Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
58
// Here is an example of using Skia’s PDF backend (SkPDF) via the SkDocument
// and SkCanvas APIs.
void WritePDF(SkWStream* outputStream,
const char* documentTitle,
void (*writePage)(SkCanvas*, int page),
int numberOfPages,
SkSize pageSize) {
SkPDF::Metadata metadata;
metadata.fTitle = documentTitle;
metadata.fCreator = "Example WritePDF() Function";
auto pdfDocument = SkPDF::MakeDocument(outputStream, metadata);
SkASSERT(pdfDocument);
for (int page = 0; page < numberOfPages; ++page) {
SkCanvas* pageCanvas = pdfDocument->beginPage(pageSize.width(),
pageSize.height());
writePage(pageCanvas, page);
pdfDocument->endPage();
}
pdfDocument->close();
}
// Print binary data to stdout as hex.
void print_data(const SkData* data, const char* name) {
if (data) {
SkDebugf("\nxxd -r -p > %s << EOF", name);
size_t s = data->size();
const uint8_t* d = data->bytes();
for (size_t i = 0; i < s; ++i) {
if (i % 40 == 0) { SkDebugf("\n"); }
SkDebugf("%02x", d[i]);
}
SkDebugf("\nEOF\n\n");
}
}
// example function that draws on a SkCanvas.
void write_page(SkCanvas* canvas, int) {
const SkScalar R = 115.2f, C = 128.0f;
SkPath path;
path.moveTo(C + R, C);
for (int i = 1; i < 8; ++i) {
SkScalar a = 2.6927937f * i;
path.lineTo(C + R * cos(a), C + R * sin(a));
}
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
canvas->drawPath(path, paint);
}
void draw(SkCanvas*) {
constexpr SkSize ansiLetterSize{8.5f * 72, 11.0f * 72};
SkDynamicMemoryWStream buffer;
WritePDF(&buffer, "SkPDF Example", &write_page, 1, ansiLetterSize);
sk_sp<SkData> pdfData = buffer.detachAsData();
print_data(pdfData.get(), "skpdf_example.pdf");
}