Flutter Engine
The Flutter Engine
write_to_pdf.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
15#include "include/core/SkFont.h"
22
23#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
25#endif
26
27#if defined(SK_FONTMGR_CORETEXT_AVAILABLE)
29#endif
30
31#include <cstdio>
32
33int main(int argc, char** argv) {
34 if (argc != 2) {
35 printf("Usage: %s <name.pdf>", argv[0]);
36 return 1;
37 }
39 if (!output.isValid()) {
40 printf("Cannot open output file %s\n", argv[1]);
41 return 1;
42 }
43
44 SkPDF::Metadata metadata;
45 metadata.fTitle = "Test PDF";
46 metadata.fAuthor = "Skia Demo Writer";
47 metadata.fLang = "eng";
48 metadata.fEncodingQuality = 90;
49
51 SkCanvas* canvas = pdf->beginPage(100, 50);
52
53#if defined(SK_FONTMGR_FONTCONFIG_AVAILABLE)
55#endif
56#if defined(SK_FONTMGR_CORETEXT_AVAILABLE)
58#endif
59
60 sk_sp<SkTypeface> face = mgr->matchFamilyStyle("Roboto", SkFontStyle());
61 if (!face) {
62 printf("Cannot open typeface\n");
63 return 1;
64 }
65 SkFont font(face, 14);
67 paint.setColor(SK_ColorGREEN);
68 canvas->clear(SK_ColorYELLOW);
69 canvas->drawString("Hello world!", 10, 25, font, paint);
70
71 pdf->endPage();
72 pdf->close();
73 return 0;
74}
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
char ** argv
Definition: library.h:9
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
font
Font Metadata and Metrics.
SkString fAuthor
Definition: SkPDFDocument.h:92
int main(int argc, char **argv)