Chromium Code Reviews| 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 (SkPDF) via the |
| 5 via the SkDocument and SkCanvas APIs. | 5 SkDocument and SkCanvas APIs. |
| 6 | 6 |
| 7 <!--?prettify lang=cc?--> | 7 <!--?prettify lang=cc?--> |
| 8 | 8 |
| 9 #include "SkDocument.h" | 9 #include "SkDocument.h" |
| 10 | 10 |
| 11 bool WritePDF(SkWStream* outputStream) { | 11 bool WritePDF(SkWStream* outputStream) { |
| 12 SkDocument::PDFMetadata metadata; | 12 SkDocument::PDFMetadata metadata; |
| 13 metadata.fCreator = "creator...."; | 13 metadata.fCreator = "creator...."; |
| 14 metadata.fTitle = "title..."; | 14 metadata.fTitle = "title..."; |
| 15 metadata.fAuthor = "author..."; | 15 metadata.fAuthor = "author..."; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 32 SkScalar pageHeight = ....; | 32 SkScalar pageHeight = ....; |
| 33 SkCanvas* pageCanvas = | 33 SkCanvas* pageCanvas = |
| 34 pdfDocument->beginPage(pageWidth, pageHeight); | 34 pdfDocument->beginPage(pageWidth, pageHeight); |
| 35 | 35 |
| 36 // ....insert canvas draw commands here.... | 36 // ....insert canvas draw commands here.... |
| 37 | 37 |
| 38 pdfDocument->endPage(); | 38 pdfDocument->endPage(); |
| 39 } | 39 } |
| 40 return pdfDocument->close(); | 40 return pdfDocument->close(); |
| 41 } | 41 } |
| 42 | |
| 43 * * * | |
| 44 | |
| 45 <span id="limits">SkPDF Limitations</span> | |
| 46 ------------------------------------------ | |
| 47 | |
| 48 There are several corners of Skia's public API that SkPDF does not | |
|
djsollen
2016/09/29 13:12:39
SkPDF currently does not
hal.canary
2016/09/29 15:31:13
Done.
| |
| 49 handle because either no one has asked for it or there is no simple | |
|
djsollen
2016/09/29 13:12:40
replace "no one has asked for it" with "no known c
hal.canary
2016/09/29 15:31:13
Done.
| |
| 50 PDF-ish way to handle it. | |
| 51 | |
| 52 **drop** means to draw nothing. | |
|
djsollen
2016/09/29 13:12:40
put a heading above these 3 terms indicating they
hal.canary
2016/09/29 15:31:13
Done.
| |
| 53 | |
| 54 **ignore** mean to draw without the effect | |
| 55 | |
| 56 **expand** means to implement something in a non-PDF-ish way. | |
|
djsollen
2016/09/29 13:12:40
does non-PDF-ish mean rasterized content instead o
hal.canary
2016/09/29 15:31:13
Done.
+ **expand** means to implement something
| |
| 57 | |
| 58 - *SkMaskFilter* — Mask filters are either dropped (drawText calls) | |
|
djsollen
2016/09/29 13:12:39
these first 3 bullets (and the last one) say the
hal.canary
2016/09/29 15:31:13
Done.
| |
| 59 or ignored (other draw calls). | |
| 60 | |
| 61 - *SkPathEffect* — Path effects are either ignored (drawText calls) | |
| 62 or expanded (other draw calls). | |
| 63 | |
| 64 - *SkColorFilter* — Color filters are either expanded (drawImage / | |
| 65 drawBitmap calls) or ignored (everything else); | |
| 66 | |
| 67 - *SkImageFilter* — ImageFilter is always expanded. (Text-as-text is lost). | |
| 68 | |
| 69 - *SkXferMode* — Transfer modes that are not natively supported by | |
| 70 PDF are ignored: DstOver, SrcIn, DstIn, SrcOut, DstOut, SrcATop, | |
| 71 DstATop, and Modulate. | |
| 72 | |
| 73 - *SkShader* — Non-gradient shaders are expanded. | |
| 74 | |
| 75 <style scoped><!-- | |
| 76 #pdftable {border-collapse:collapse;} | |
| 77 #pdftable tr th, #pdftable tr td {border:#888888 2px solid;padding: 5px;} | |
| 78 --></style> | |
| 79 <table id="pdftable"> | |
| 80 <tr> | |
| 81 <th>Effect</th> | |
| 82 <th>text</th> | |
| 83 <th>images</th> | |
| 84 <th>everything else</th> | |
| 85 </tr> | |
| 86 <tr> | |
| 87 <th>SkMaskFilter</th> | |
| 88 <td>drop</td> | |
| 89 <td>ignore</td> | |
| 90 <td>ignore</td> | |
| 91 </tr> | |
| 92 <tr> | |
| 93 <th>SkPathEffect</th> | |
| 94 <td>ignore</td> | |
| 95 <td>n/a</td> | |
| 96 <td>expand</td> | |
| 97 </tr> | |
| 98 <tr> | |
| 99 <th>SkColorFilter</th> | |
| 100 <td>ignore</td> | |
| 101 <td>expand</td> | |
| 102 <td>ignore</td> | |
| 103 </tr> | |
| 104 <tr> | |
| 105 <th>SkImageFilter</th> | |
| 106 <td>expand</td> | |
| 107 <td>expand</td> | |
| 108 <td>expand</td> | |
| 109 </tr> | |
| 110 <tr> | |
| 111 <th>unsupported SkXferModes</th> | |
| 112 <td>ignore</td> | |
| 113 <td>ignore</td> | |
| 114 <td>ignore</td> | |
| 115 </tr> | |
| 116 <tr> | |
| 117 <th>non-gradient SkShader</th> | |
| 118 <td>expand</td> | |
| 119 <td>n/a</td> | |
| 120 <td>expand</td> | |
| 121 </tr> | |
| 122 </table> | |
| 123 | |
| 124 Other limitations: | |
| 125 | |
| 126 - *VerticalText* — drop. (No clients seem to make use of VerticalText.) | |
| 127 | |
| 128 - *drawTextOnPath* — expand. (Text-as-text is lost.) | |
| 129 | |
| 130 - *drawVertices* — drop. | |
| 131 | |
| 132 - *drawPatch* — drop. | |
| 133 | |
| 134 * * * | |
| OLD | NEW |