Flutter Engine
The Flutter Engine
write_text_to_png.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
14#include "include/core/SkFont.h"
21
22#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
24#endif
25
26#if defined(SK_FONTMGR_CORETEXT_AVAILABLE)
28#endif
29
30#include <cstdio>
31
32int main(int argc, char** argv) {
33 if (argc != 2) {
34 printf("Usage: %s <name.png>", argv[0]);
35 return 1;
36 }
38 if (!output.isValid()) {
39 printf("Cannot open output file %s\n", argv[1]);
40 return 1;
41 }
43 SkCanvas* canvas = surface->getCanvas();
44#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
46#endif
47#if defined(SK_FONTMGR_CORETEXT_AVAILABLE)
49#endif
50
51 sk_sp<SkTypeface> face = mgr->matchFamilyStyle("Roboto", SkFontStyle());
52 if (!face) {
53 printf("Cannot open typeface\n");
54 return 1;
55 }
56 SkFont font(face, 14);
58 paint.setColor(SK_ColorGREEN);
59 canvas->clear(SK_ColorYELLOW);
60 canvas->drawString("Hello world!", 10, 25, font, paint);
61 SkPixmap pixmap;
62 if (surface->peekPixels(&pixmap)) {
63 if (!SkPngEncoder::Encode(&output, pixmap, {})) {
64 printf("Cannot write output\n");
65 return 1;
66 }
67 } else {
68 printf("Cannot readback on surface\n");
69 return 1;
70 }
71 return 0;
72}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
SK_API sk_sp< SkFontMgr > SkFontMgr_New_FontConfig(FcConfig *fc)
SK_API sk_sp< SkFontMgr > SkFontMgr_New_CoreText(CTFontCollectionRef)
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
char ** argv
Definition: library.h:9
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
font
Font Metadata and Metrics.
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
int main(int argc, char **argv)