Flutter Engine
The Flutter Engine
Functions
PDF.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (PDF, 256, 256, true, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( PDF  ,
256  ,
256  ,
true  ,
 
)

Definition at line 4 of file PDF.cpp.

4 {
5
6// Here is an example of using Skia’s PDF backend (SkPDF) via the SkDocument
7// and SkCanvas APIs.
8void WritePDF(SkWStream* outputStream,
9 const char* documentTitle,
10 void (*writePage)(SkCanvas*, int page),
11 int numberOfPages,
12 SkSize pageSize) {
13 SkPDF::Metadata metadata;
14 metadata.fTitle = documentTitle;
15 metadata.fCreator = "Example WritePDF() Function";
16 metadata.fCreation = {0, 2019, 1, 4, 31, 12, 34, 56};
17 metadata.fModified = {0, 2019, 1, 4, 31, 12, 34, 56};
18 auto pdfDocument = SkPDF::MakeDocument(outputStream, metadata);
19 SkASSERT(pdfDocument);
20 for (int page = 0; page < numberOfPages; ++page) {
21 SkCanvas* pageCanvas = pdfDocument->beginPage(pageSize.width(),
22 pageSize.height());
23 writePage(pageCanvas, page);
24 pdfDocument->endPage();
25 }
26 pdfDocument->close();
27}
28
29// Print binary data to stdout as hex.
30void print_data(const SkData* data, const char* name) {
31 if (data) {
32 SkDebugf("\nxxd -r -p > %s << EOF", name);
33 size_t s = data->size();
34 const uint8_t* d = data->bytes();
35 for (size_t i = 0; i < s; ++i) {
36 if (i % 40 == 0) { SkDebugf("\n"); }
37 SkDebugf("%02x", d[i]);
38 }
39 SkDebugf("\nEOF\n\n");
40 }
41}
42
43// example function that draws on a SkCanvas.
44void write_page(SkCanvas* canvas, int) {
45 const SkScalar R = 115.2f, C = 128.0f;
47 path.moveTo(C + R, C);
48 for (int i = 1; i < 8; ++i) {
49 SkScalar a = 2.6927937f * i;
50 path.lineTo(C + R * cos(a), C + R * sin(a));
51 }
54 canvas->drawPath(path, paint);
55}
56
57void draw(SkCanvas*) {
58 constexpr SkSize ansiLetterSize{8.5f * 72, 11.0f * 72};
60 WritePDF(&buffer, "SkPDF Example", &write_page, 1, ansiLetterSize);
61 sk_sp<SkData> pdfData = buffer.detachAsData();
62 print_data(pdfData.get(), "skpdf_example.pdf");
63}
64} // END FIDDLE
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
Definition: SkData.h:25
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
float SkScalar
Definition: extension.cpp:12
struct MyStruct s
struct MyStruct a[10]
#define R(r)
SK_API sk_sp< SkDocument > MakeDocument(SkWStream *stream, const Metadata &metadata)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
DateTime fCreation
DateTime fModified
Definition: SkSize.h:52
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63