| OLD | NEW |
| 1 Using Skia's PDF Backend | 1 Using Skia's PDF Backend |
| 2 ======================== | 2 ======================== |
| 3 | 3 |
| 4 Here is an example of using Skia's PDF backend in the recommended way: | 4 Here is an example of using Skia's PDF backend in the recommended way: |
| 5 via the SkDocument and SkCanvas APIs. | 5 via the SkDocument and SkCanvas APIs. |
| 6 | 6 |
| 7 <!--?prettify?--> | 7 <!--?prettify?--> |
| 8 | 8 |
| 9 #include "SkDocument.h" | 9 #include "SkDocument.h" |
| 10 | 10 |
| 11 bool WritePDF() { | 11 bool WritePDF() { |
| 12 SkWStream* output = ....; | 12 SkWStream* outputStream = ....; |
| 13 | 13 |
| 14 SkAutoTUnref<SkDocument> pdfDocument( | 14 SkAutoTUnref<SkDocument> pdfDocument( |
| 15 SkDocument::CreatePDF(outputStream)); | 15 SkDocument::CreatePDF(outputStream)); |
| 16 | 16 |
| 17 int numberOfPages = ....; | 17 int numberOfPages = ....; |
| 18 for (int page = 0; page < numberOfPages; ++page) { | 18 for (int page = 0; page < numberOfPages; ++page) { |
| 19 SkScalar pageWidth = ....; | 19 SkScalar pageWidth = ....; |
| 20 SkScalar pageHeight = ....; | 20 SkScalar pageHeight = ....; |
| 21 SkCanvas* pageCanvas = | 21 SkCanvas* pageCanvas = |
| 22 pdfDocument->beginPage(pageWidth, pageHeight); | 22 pdfDocument->beginPage(pageWidth, pageHeight); |
| 23 | 23 |
| 24 // ....insert canvas draw commands here.... | 24 // ....insert canvas draw commands here.... |
| 25 | 25 |
| 26 pdfDocument->endPage(); | 26 pdfDocument->endPage(); |
| 27 } | 27 } |
| 28 |
| 29 SkTArray<SkDocument::Attribute> info; |
| 30 info.emplace_back(SkString("Title"), SkString("....")); |
| 31 info.emplace_back(SkString("Author"), SkString("....")); |
| 32 info.emplace_back(SkString("Subject"), SkString("....")); |
| 33 info.emplace_back(SkString("Keywords"), SkString("....")); |
| 34 info.emplace_back(SkString("Creator"), SkString("....")); |
| 35 SkTime::DateTime now; |
| 36 SkTime::GetDateTime(&now); |
| 37 pdfDocument->setMetadata(info, &now, &now); |
| 38 |
| 28 return pdfDocument->close(); | 39 return pdfDocument->close(); |
| 29 } | 40 } |
| OLD | NEW |