Home | History | Annotate | Download | only in design
      1 PDF Theory of Operation
      2 =======================
      3 
      4 <!--
      5 PRE-GIT DOCUMENT VERSION HISTORY
      6     2012-06-25 Steve VanDeBogart
      7                * Original version
      8     2015-01-14 Hal Canary.
      9                * Add section "Using the PDF backend"
     10                * Markdown formatting
     11 -->
     12 
     13 
     14 To make use of Skia's PDF backend, see
     15 [Using Skia's PDF Backend](../../user/sample/pdf).
     16 
     17 Internally, Skia uses SkPDFDocument and SkPDFDevice to represent PDF
     18 documents and pages.  This document describes how the backend
     19 operates, but **these interfaces are not part of the public API and
     20 are subject to perpetual change.**
     21 
     22 * * *
     23 
     24 ### Contents ###
     25 
     26 *   [Typical usage of the PDF backend](#Typical_usage_of_the_PDF_backend)
     27 *   [PDF Objects and Document Structure](#PDF_Objects_and_Document_Structure)
     28 *   [PDF drawing](#PDF_drawing)
     29 *   [Interned objects](#Interned_objects)
     30 *   [Graphic States](#Graphic_States)
     31 *   [Clip and Transform](#Clip_and_Transform)
     32 *   [Generating a content stream](#Generating_a_content_stream)
     33 *   [Margins and content area](#Margins_and_content_area)
     34 *   [Drawing details](#Drawing_details)
     35     +   [Layers](#Layers)
     36     +   [Fonts](#Fonts)
     37     +   [Shaders](#Shaders)
     38     +   [Xfer modes](#Xfer_modes)
     39 *   [Known issues](#Known_issues)
     40 
     41 <a name="Typical_usage_of_the_PDF_backend"></a>
     42 Typical usage of the PDF backend
     43 --------------------------------
     44 
     45 SkPDFDevice is the main interface to the PDF backend. This child of
     46 SkDevice can be set on an SkCanvas and drawn to. It requires no more
     47 care and feeding than SkDevice. Once drawing is complete, the device
     48 should be added to an SkPDFDocument as a page of the desired PDF. A
     49 new SkPDFDevice should be created for each page desired in the
     50 document. After all the pages have been added to the document,
     51 `SkPDFDocument::emitPDF()` can be called to get a PDF file. One of the
     52 special features of the PDF backend is that the same device can be
     53 added to multiple documents. This for example, would let you generate
     54 a PDF with the single page you just drew as well as adding it to a
     55 longer document with a bunch of other pages.
     56 
     57 <!--?prettify lang=cc?-->
     58 
     59     SkPDFCanon canon;
     60     SkAutoUnref<SkPDFDevice> pdfDevice(
     61         SkPDFDevice::Create(SkISize::Make(width, height), 72.0f, &canon));
     62 
     63     SkCanvas canvas(pdfDevice);
     64     draw_content(&canvas);
     65 
     66     SkPDFDocument doc;
     67     doc.appendPage(dev);
     68     doc.emitPDF(&pdf_stream);
     69 
     70 <a name="PDF_Objects_and_Document_Structure"></a>
     71 PDF Objects and Document Structure
     72 ----------------------------------
     73 
     74 **Background**: The PDF file format has a header, a set of objects and
     75 then a footer that contains a table of contents for all of the objects
     76 in the document (the cross-reference table). The table of contents
     77 lists the specific byte position for each object. The objects may have
     78 references to other objects and the ASCII size of those references is
     79 dependent on the object number assigned to the referenced object;
     80 therefore we cant calculate the table of contents until the size of
     81 objects is known, which requires assignment of object
     82 numbers.
     83 
     84 Furthermore, PDF files can support a *linearized* mode, where objects
     85 are in a specific order so that pdf-viewers can more easily retrieve
     86 just the objects they need to display a specific page, i.e. by
     87 byte-range requests over the web. Linearization also requires that all
     88 objects used or referenced on the first page of the PDF have object
     89 numbers before the rest of the objects. Consequently, before
     90 generating a linearized PDF, all objects, their sizes, and object
     91 references must be known.  Skia has no plans to implement linearized
     92 PDFs.
     93 
     94 <!-- <del>At this point, linearized PDFs are not generated. The
     95 framework to generate them is in place, but the final bits of code
     96 have not been written.</del> -->
     97 
     98     %PDF-1.4
     99     objects...
    100     xref
    101     0 31  % Total number of entries in the table of contents.
    102     0000000000 65535 f
    103     0000210343 00000 n
    104     
    105     0000117055 00000 n
    106     trailer
    107     <</Size 31 /Root 1 0 R>>
    108     startxref
    109     210399  % Byte offset to the start of the table of contents.
    110     %%EOF
    111 
    112 The class SkPDFCatalog and the virtual class SkPDFObject are used to
    113 manage the needs of the file format. Any object that will represent a
    114 PDF object must inherit from SkPDFObject and implement the methods to
    115 generate the binary representation and report any other SkPDFObjects
    116 used as resources. SkPDFTypes.h defines most of the basic PDF objects
    117 types: bool, int, scalar, string, name, array, dictionary, and object
    118 reference. The stream type is defined in SkPDFStream.h. A stream is a
    119 dictionary containing at least a Length entry followed by the data of
    120 the stream. All of these types except the stream type can be used in
    121 both a direct and an indirect fashion, i.e. an array can have an int
    122 or a dictionary as an inline entry, which does not require an object
    123 number. The stream type, cannot be inlined and must be referred to
    124 with an object reference. Most of the time, other objects types can be
    125 referred to with an object reference, but there are specific rules in
    126 the PDF specification that requires an inline reference in some place
    127 or an indirect reference in other places. All indirect objects must
    128 have an object number assigned.
    129 
    130 *   **bools**: `true` `false`
    131 *   **ints**: `42` `0` `-1`
    132 *   **scalars**: `0.001`
    133 *   **strings**: `(strings are in parentheses or byte encoded)` `<74657374>`
    134 *   **name**: `/Name` `/Name#20with#20spaces`
    135 *   **array**: `[/Foo 42 (arrays can contain multiple types)]`
    136 *   **dictionary**: `<</Key1 (value1) /key2 42>>`
    137 *   **indirect object**:  
    138     `5 0 obj  
    139     (An indirect string. Indirect objects have an object number and a
    140     generation number, Skia always uses generation 0 objects)  
    141     endobj`  
    142 *   **object reference**: `5 0 R`
    143 *   **stream**: `<</Length 56>>  
    144     stream  
    145     ...stream contents can be arbitrary, including binary...  
    146     endstream`
    147 
    148 The PDF backend requires all indirect objects used in a PDF to be
    149 added to the SkPDFCatalog of the SkPDFDocument. The catalog is
    150 responsible for assigning object numbers and generating the table of
    151 contents required at the end of PDF files. In some sense, generating a
    152 PDF is a three step process. In the first step all the objects and
    153 references among them are created (mostly done by SkPDFDevice). In the
    154 second step, object numbers are assigned and SkPDFCatalog is informed
    155 of the file offset of each indirect object. Finally, in the third
    156 step, the header is printed, each object is printed, and then the
    157 table of contents and trailer are printed. SkPDFDocument takes care of
    158 collecting all the objects from the various SkPDFDevice instances,
    159 adding them to an SkPDFCatalog, iterating through the objects once to
    160 set their file positions, and iterating again to generate the final
    161 PDF.
    162 
    163     %PDF-1.4
    164     2 0 obj <<
    165       /Type /Catalog
    166       /Pages 1 0 R
    167     >>
    168     endobj
    169     3 0 obj <<
    170       /Type /Page
    171       /Parent 1 0 R
    172       /Resources <>
    173       /MediaBox [0 0 612 792]
    174       /Contents 4 0 R
    175     >>
    176     endobj
    177     4 0 obj <> stream
    178     endstream
    179     endobj
    180     1 0 obj <<
    181       /Type /Pages
    182       /Kids [3 0 R]
    183       /Count 1
    184     >>
    185     endobj
    186     xref
    187     0 5
    188     0000000000 65535 f
    189     0000000236 00000 n
    190     0000000009 00000 n
    191     0000000062 00000 n
    192     0000000190 00000 n
    193     trailer
    194     <</Size 5 /Root 2 0 R>>
    195     startxref
    196     299
    197     %%EOF
    198 
    199 <a name="PDF_drawing"></a>
    200 PDF drawing
    201 -----------
    202 
    203 Most drawing in PDF is specified by the text of a stream, referred to
    204 as a content stream. The syntax of the content stream is different
    205 than the syntax of the file format described above and is much closer
    206 to PostScript in nature. The commands in the content stream tell the
    207 PDF interpreter to draw things, like a rectangle (`x y w h re`), an
    208 image, or text, or to do meta operations like set the drawing color,
    209 apply a transform to the drawing coordinates, or clip future drawing
    210 operations. The page object that references a content stream has a
    211 list of resources that can be used in the content stream using the
    212 dictionary name to reference the resources. Resources are things like
    213 font objects, images objects, graphic state objects (a set of meta
    214 operations like miter limit, line width, etc). Because of a mismatch
    215 between Skia and PDFs support for transparency (which will be
    216 explained later), SkPDFDevice records each drawing operation into an
    217 internal structure (ContentEntry) and only when the content stream is
    218 needed does it flatten that list of structures into the final content
    219 stream.
    220 
    221     4 0 obj <<
    222       /Type /Page
    223       /Resources <<
    224         /Font <</F1 9 0 R>>
    225         /XObject <</Image1 22 0 R /Image2 73 0 R>>
    226       >>
    227       /Content 5 0 R
    228     >> endobj
    229 
    230     5 0 obj <</Length 227>> stream
    231     % In the font specified in object 9 and a height
    232     % of 12 points, at (72, 96) draw Hello World.
    233     BT
    234       /F1 12 Tf
    235       72 96 Td
    236       (Hello World) Tj
    237     ET
    238     % Draw a filled rectange.
    239     200 96 72 72 re B
    240     ...
    241     endstream
    242     endobj
    243 
    244 <a name="Interned_objects"></a>
    245 Interned objects
    246 ----------------
    247 
    248 There are a number of high level PDF objects (like fonts, graphic
    249 states, etc) that are likely to be referenced multiple times in a
    250 single PDF. To ensure that there is only one copy of each object
    251 instance these objects an implemented with an
    252 [interning pattern](http://en.wikipedia.org/wiki/String_interning).
    253 As such, the classes representing these objects (like
    254 SkPDFGraphicState) have private constructors and static methods to
    255 retrieve an instance of the class. Internally, the class has a list of
    256 unique instances that it consults before returning a new instance of
    257 the class. If the requested instance already exists, the existing one
    258 is returned. For obvious reasons, the returned instance should not be
    259 modified. A mechanism to ensure that interned classes are immutable is
    260 needed.  See [issue 2683](https://bug.skia.org/2683).
    261 
    262 <a name="Graphic_States"></a>
    263 Graphic States
    264 --------------
    265 
    266 PDF has a number of parameters that affect how things are drawn. The
    267 ones that correspond to drawing options in Skia are: color, alpha,
    268 line cap, line join type, line width, miter limit, and xfer/blend mode
    269 (see later section for xfer modes). With the exception of color, these
    270 can all be specified in a single pdf object, represented by the
    271 SkPDFGraphicState class. A simple command in the content stream can
    272 then set the drawing parameters to the values specified in that
    273 graphic state object. PDF does not allow specifying color in the
    274 graphic state object, instead it must be specified directly in the
    275 content stream. Similarly the current font and font size are set
    276 directly in the content stream.
    277 
    278     6 0 obj <<
    279       /Type /ExtGState
    280       /CA 1  % Opaque - alpha = 1
    281       /LC 0  % Butt linecap
    282       /LJ 0  % Miter line-join
    283       /LW 2  % Line width of 2
    284       /ML 6  % Miter limit of 6
    285       /BM /Normal  % Blend mode is normal i.e. source over
    286     >>
    287     endobj
    288 
    289 <a name="Clip_and_Transform"></a>
    290 Clip and Transform
    291 ------------------
    292 
    293 Similar to Skia, PDF allows drawing to be clipped or
    294 transformed. However, there are a few caveats that affect the design
    295 of the PDF backend. PDF does not support perspective transforms
    296 (perspective transform are treated as identity transforms). Clips,
    297 however, have more issues to cotend with. PDF clips cannot be directly
    298 unapplied or expanded. i.e. once an area has been clipped off, there
    299 is no way to draw to it. However, PDF provides a limited depth stack
    300 for the PDF graphic state (which includes the drawing parameters
    301 mentioned above in the Graphic States section as well as the clip and
    302 transform). Therefore to undo a clip, the PDF graphic state must be
    303 pushed before the clip is applied, then popped to revert to the state
    304 of the graphic state before the clip was applied.
    305 
    306 As the canvas makes drawing calls into SkPDFDevice, the active
    307 transform, clip region, and clip stack are stored in a ContentEntry
    308 structure. Later, when the ContentEntry structures are flattened into
    309 a valid PDF content stream, the transforms and clips are compared to
    310 decide on an efficient set of operations to transition between the
    311 states needed. Currently, a local optimization is used, to figure out
    312 the best transition from one state to the next. A global optimization
    313 could improve things by more effectively using the graphics state
    314 stack provided in the PDF format.
    315 
    316 <a name="Generating_a_content_stream"></a>
    317 Generating a content stream
    318 ---------------------------
    319 
    320 For each draw call on an SkPDFDevice, a new ContentEntry is created,
    321 which stores the matrix, clip region, and clip stack as well as the
    322 paint parameters. Most of the paint parameters are bundled into an
    323 SkPDFGraphicState (interned) with the rest (color, font size, etc)
    324 explicitly stored in the ContentEntry. After populating the
    325 ContentEntry with all the relevant context, it is compared to the the
    326 most recently used ContentEntry. If the context matches, then the
    327 previous one is appended to instead of using the new one. In either
    328 case, with the context populated into the ContentEntry, the
    329 appropriate draw call is allowed to append to the content stream
    330 snippet in the ContentEntry to affect the core of the drawing call,
    331 i.e. drawing a shape, an image, text, etc.
    332 
    333 When all drawing is complete, SkPDFDocument::emitPDF() will call
    334 SkPDFDevice::content() to request the complete content stream for the
    335 page. The first thing done is to apply the initial transform specified
    336 in part in the constructor, this transform takes care of changing the
    337 coordinate space from an origin in the lower left (PDF default) to the
    338 upper left (Skia default) as well as any translation or scaling
    339 requested by the user (i.e. to achieve a margin or scale the
    340 canvas). Next (well almost next, see the next section), a clip is
    341 applied to restrict drawing to the content area (the part of the page
    342 inside the margins) of the page. Then, each ContentEntry is applied to
    343 the content stream with the help of a helper class, GraphicStackState,
    344 which tracks the state of the PDF graphics stack and optimizes the
    345 output. For each ContentEntry, commands are emitted to the final
    346 content entry to update the clip from its current state to the state
    347 specified in the ContentEntry, similarly the Matrix and drawing state
    348 (color, line joins, etc) are updated, then the content entry fragment
    349 (the actual drawing operation) is appended.
    350 
    351 <a name="Margins_and_content_area"></a>
    352 Margins and content area
    353 ------------------------
    354 
    355 The above procedure does not permit drawing in the margins. This is
    356 done in order to contain any rendering problems in WebKit. In order to
    357 support headers and footers, which are drawn in the margin, a second
    358 set of ContentEntrys are maintained. The
    359 methodSkPDFDevice::setDrawingArea() selects which set of
    360 ContentEntrys are drawn into. Then, in the SkPDFDevice::content()
    361 method, just before the clip to the content area is applied the margin
    362 ContentEntry's are played back.
    363 
    364 <!-- TODO(halcanary): update this documentation. -->
    365 
    366 <a name="Drawing_details"></a>
    367 Drawing details
    368 ---------------
    369 
    370 Certain objects have specific properties that need to be dealt
    371 with. Images, layers (see below), and fonts assume the standard PDF
    372 coordinate system, so we have to undo any flip to the Skia coordinate
    373 system before drawing these entities. We dont currently support
    374 inverted paths, so filling an inverted path will give the wrong result
    375 ([issue 241](https://bug.skia.org/241)). PDF doesnt draw zero length
    376 lines that have butt of square caps, so that is emulated.
    377 
    378 <a name="Layers"></a>
    379 ### Layers ###
    380 
    381 PDF has a higher level object called a form x-object (form external
    382 object) that is basically a PDF page, with resources and a content
    383 stream, but can be transformed and drawn on an existing page. This is
    384 used to implement layers. SkDevice has a method,
    385 createFormXObjectFromDevice, which uses the SkPDFDevice::content()
    386 method to construct a form x-object from the the
    387 device. SkPDFDevice::drawDevice() works by creating a form x-object of
    388 the passed device and then drawing that form x-object in the root
    389 device. There are a couple things to be aware of in this process. As
    390 noted previously, we have to be aware of any flip to the coordinate
    391 system - flipping it an even number of times will lead to the wrong
    392 result unless it is corrected for. The SkClipStack passed to drawing
    393 commands includes the entire clip stack, including the clipping
    394 operations done on the base layer. Since the form x-object will be
    395 drawn as a single operation onto the base layer, we can assume that
    396 all of those clips are in effect and need not apply them within the
    397 layer.
    398 
    399 <a name="Fonts"></a>
    400 ### Fonts ###
    401 
    402 There are many details for dealing with fonts, so this document will
    403 only talk about some of the more important ones. A couple short
    404 details:
    405 
    406 *   We cant assume that an arbitrary font will be available at PDF view
    407     time, so we embed all fonts in accordance with modern PDF
    408     guidelines.
    409 *   Most fonts these days are TrueType fonts, so this is where most of
    410     the effort has been concentrated.
    411 *   Because Skia may only be given a glyph-id encoding of the text to
    412     render and there is no perfect way to reverse the encoding, the
    413     PDF backend always uses the glyph-id encoding of the text.
    414 
    415 #### *Type1/Type3 fonts* ####
    416 
    417 Linux supports Type1 fonts, but Windows and Mac seem to lack the
    418 functionality required to extract the required information from the
    419 font without parsing the font file. When a non TrueType font is used
    420 any any platform (except for Type1 on Linux), it is encoded as a Type3
    421 font. In this context, a Type3 font is an array of form x-objects
    422 (content streams) that draw each glyph of the font. No hinting or
    423 kerning information is included in a Type3 font, just the shape of
    424 each glyph. Any font that has the do-not embed copy protection bit set
    425 will also get embedded as a Type3 font. From what I understand, shapes
    426 are not copyrightable, but programs are, so by stripping all the
    427 programmatic information and only embedding the shape of the glyphs we
    428 are honoring the do-not embed bit as much as required by law.
    429 
    430 PDF only supports an 8-bit encoding for Type1 or Type3 fonts. However,
    431 they can contain more than 256 glyphs. The PDF backend handles this by
    432 segmenting the glyphs into groups of 255 (glyph id 0 is always the
    433 unknown glyph) and presenting the font as multiple fonts, each with up
    434 to 255 glyphs.
    435 
    436 #### *Font subsetting* ####
    437 
    438 Many fonts, especially fonts with CJK support are fairly large, so it
    439 is desirable to subset them. Chrome uses the SFNTLY package to provide
    440 subsetting support to Skia for TrueType fonts. However, there is a
    441 conflict between font subsetting and interned objects. If the object
    442 is immutable, how can it be subsetted? This conflict is resolved by
    443 using a substitution mechanism in SkPDFCatalog. Font objects are still
    444 interned, but the interned objects arent internally
    445 populated. Subsetting starts while drawing text to an SkPDFDevice; a
    446 bit set indicating which glyphs have been used is maintained. Later,
    447 when SkPDFDocument::emitPDF() is rendering the PDF, it queries each
    448 device (each page) for the set of fonts used and the glyphs used from
    449 each font and combines the information. It then asks the interned
    450 (unpopulated) font objects to create a populated instance with the
    451 calculated subset of the font - this instance is not interned. The
    452 subsetted instance is then set as a substitute for the interned font
    453 object in the SkPDFCatalog. All future references to those fonts
    454 within that document will refer to the subsetted instances, resulting
    455 in a final PDF with exactly one instance of each used font that
    456 includes only the glyphs used.
    457 
    458 The substitution mechanism is a little complicated, but is needed to
    459 support the use case of an SkPDFDevice being added to multiple
    460 documents. If fonts were subsetted in-situ, concurrent PDF generation
    461 would have to be explicitly handled. Instead, by giving each document
    462 its own subsetted instance, there is no need to worry about concurrent
    463 PDF generation. The substitution method is also used to support
    464 optional stream compression. A stream can used by different documents
    465 in both a compressed and uncompressed form, leading to the same
    466 potential difficulties faced by the concurrent font use case.
    467 
    468 <a name="Shaders"></a>
    469 ### Shaders ###
    470 
    471 Skia has two types of predefined shaders, image shaders and gradient
    472 shaders. In both cases, shaders are effectively positioned absolutely,
    473 so the initial position and bounds of where they are visible is part
    474 of the immutable state of the shader object. Each of the Skias tile
    475 modes needs to be considered and handled explicitly. The image shader
    476 we generate will be tiled, so tiling is handled by default. To support
    477 mirroring, we draw the image, reversed, on the appropriate axis, or on
    478 both axes plus a fourth in the vacant quadrant. For clamp mode, we
    479 extract the pixels along the appropriate edge and stretch the single
    480 pixel wide/long image to fill the bounds. For both x and y in clamp
    481 mode, we fill the corners with a rectangle of the appropriate
    482 color. The composed shader is then rotated or scaled as appropriate
    483 for the request.
    484 
    485 Gradient shaders are handled purely mathematically. First, the matrix
    486 is transformed so that specific points in the requested gradient are
    487 at pre-defined locations, for example, the linear distance of the
    488 gradient is always normalized to one. Then, a type 4 PDF function is
    489 created that achieves the desired gradient. A type 4 function is a
    490 function defined by a resticted postscript language. The generated
    491 functions clamp at the edges so if the desired tiling mode is tile or
    492 mirror, we hav to add a bit more postscript code to map any input
    493 parameter into the 0-1 range appropriately. The code to generate the
    494 postscript code is somewhat obtuse, since it is trying to generate
    495 optimized (for space) postscript code, but there is a significant
    496 number of comments to explain the intent.
    497 
    498 <a name="Xfer_modes"></a>
    499 ### Xfer modes ###
    500 
    501 PDF supports some of the xfer modes used in Skia directly. For those,
    502 it is simply a matter of setting the blend mode in the graphic state
    503 to the appropriate value (Normal/SrcOver, Multiply, Screen, Overlay,
    504 Darken, Lighten, !ColorDOdge, ColorBurn, HardLight, SoftLight,
    505 Difference, Exclusion). Aside from the standard SrcOver mode, PDF does
    506 not directly support the porter-duff xfer modes though. Most of them
    507 (Clear, SrcMode, DstMode, DstOver, SrcIn, DstIn, SrcOut, DstOut) can
    508 be emulated by various means, mostly by creating form x-objects out of
    509 part of the content and drawing it with a another form x-object as a
    510 mask. I have not figured out how to emulate the following modes:
    511 SrcATop, DstATop, Xor, Plus.
    512 
    513 At the time of writing [2012-06-25], I have a [CL outstanding to fix a
    514 misunderstanding I had about the meaning of some of the emulated
    515 modes](https://codereview.appspot.com/4631078/).
    516 I will describe the system with this change applied.
    517 
    518 First, a bit of terminology and definition. When drawing something
    519 with an emulated xfer mode, whats already drawn to the device is
    520 called the destination or Dst, and whats about to be drawn is the
    521 source or Src. Src (and Dst) can have regions where it is transparent
    522 (alpha equals zero), but it also has an inherent shape. For most kinds
    523 of drawn objects, the shape is the same as where alpha is not
    524 zero. However, for things like images and layers, the shape is the
    525 bounds of the item, not where the alpha is non-zero. For example, a
    526 10x10 image, that is transparent except for a 1x1 dot in the center
    527 has a shape that is 10x10. The xfermodes gm test demonstrates the
    528 interaction between shape and alpha in combination with the port-duff
    529 xfer modes.
    530 
    531 The clear xfer mode removes any part of Dst that is within Srcs
    532 shape. This is accomplished by bundling the current content of the
    533 device (Dst) into a single entity and then drawing that with the
    534 inverse of Srcs shape used as a mask (we want Dst where Src
    535 isnt). The implementation of that takes a couple more steps. You may
    536 have to refer back to [the content stream section](#Generating_a_content_stream). For any draw call, a
    537 ContentEntry is created through a method called
    538 SkPDFDevice::setUpContentEntry(). This method examines the xfer modes
    539 in effect for that drawing operation and if it is an xfer mode that
    540 needs emulation, it creates a form x-object from the device,
    541 i.e. creates Dst, and stores it away for later use. This also clears
    542 all of that existing ContentEntry's on that device. The drawing
    543 operation is then allowed to proceed as normal (in most cases, see
    544 note about shape below), but into the now empty device. Then, when the
    545 drawing operation in done, a complementary method is
    546 called,SkPDFDevice::finishContentEntry(), which takes action if the
    547 current xfer mode is emulated. In the case of Clear, it packages what
    548 was just drawn into another form x-object, and then uses the Src form
    549 x-object, an invert function, and the Dst form x-object to draw Dst
    550 with the inverse shape of Src as a mask. This works well when the
    551 shape of Src is the same as the opaque part of the drawing, since PDF
    552 uses the alpha channel of the mask form x-object to do masking. When
    553 shape doesnt match the alpha channel, additional action is
    554 required. The drawing routines where shape and alpha dont match, set
    555 state to indicate the shape (always rectangular), which
    556 finishContentEntry uses. The clear xfer mode is a special case; if
    557 shape is needed, then Src isnt used, so there is code to not bother
    558 drawing Src if shape is required and the xfer mode is clear.
    559 
    560 SrcMode is clear plus Src being drawn afterward. DstMode simply omits
    561 drawing Src. DstOver is the same as SrcOver with Src and Dst swapped -
    562 this is accomplished by inserting the new ContentEntry at the
    563 beginning of the list of ContentEntrys in setUpContentEntry instead
    564 of at the end. SrcIn, SrcOut, DstIn, DstOut are similar to each, the
    565 difference being an inverted or non-inverted mask and swapping Src and
    566 Dst (or not). SrcIn is SrcMode with Src drawn with Dst as a
    567 mask. SrcOut is like SrcMode, but with Src drawn with an inverted Dst
    568 as a mask. DstIn is SrcMode with Dst drawn with Src as a
    569 mask. Finally, DstOut is SrcMode with Dst draw with an inverted Src as
    570 a mask.
    571 
    572 <a name="Known_issues"></a>
    573 Known issues
    574 ------------
    575 
    576 *   [issue 241](https://bug.skia.org/241)
    577     As previously noted, a boolean geometry library
    578     would improve clip fidelity in some places, add supported for
    579     inverted fill types, as well as simplify code.
    580     This is fixed, but behind a flag until path ops is production ready.
    581 *   [issue 237](https://bug.skia.org/237)
    582     SkMaskFilter is not supported.
    583 *   [issue 238](https://bug.skia.org/238)
    584     SkColorFilter is not supported.
    585 *   [issue 249](https://bug.skia.org/249)
    586     SrcAtop Xor, and Plus xfer modes are not supported.
    587 *   [issue 240](https://bug.skia.org/240)
    588     drawVerticies is not implemented.
    589 *   [issue 244](https://bug.skia.org/244)
    590     Mostly, only TTF fonts are directly supported.  (User metrics 
    591     show that almost all fonts are truetype.
    592 *   [issue 260](https://bug.skia.org/260)
    593     Page rotation is accomplished by specifying a different
    594     size page instead of including the appropriate rotation
    595     annotation.
    596 
    597 * * *
    598 
    599