Home | History | Annotate | Download | only in pdf
      1 
      2 /*
      3  * Copyright 2010 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkPDFPage_DEFINED
     11 #define SkPDFPage_DEFINED
     12 
     13 #include "SkPDFTypes.h"
     14 #include "SkPDFStream.h"
     15 #include "SkRefCnt.h"
     16 #include "SkTDArray.h"
     17 
     18 class SkPDFCatalog;
     19 class SkPDFDevice;
     20 class SkWStream;
     21 
     22 /** \class SkPDFPage
     23 
     24     A SkPDFPage contains meta information about a page, is used in the page
     25     tree and points to the content of the page.
     26 */
     27 class SkPDFPage : public SkPDFDict {
     28 public:
     29     /** Create a PDF page with the passed PDF device.  The device need not
     30      *  have content on it yet.
     31      *  @param content    The page content.
     32      */
     33     explicit SkPDFPage(SkPDFDevice* content);
     34     ~SkPDFPage();
     35 
     36     /** Before a page and its contents can be sized and emitted, it must
     37      *  be finalized.  No changes to the PDFDevice will be honored after
     38      *  finalizePage has been called.  This function adds the page content
     39      *  to the passed catalog, so it must be called for each document
     40      *  that the page is part of.
     41      *  @param catalog         The catalog to add page content objects to.
     42      *  @param firstPage       Indicate if this is the first page of a document.
     43      *  @param resourceObjects The resource objects used on the page are added
     44      *                         to this array.  This gives the caller a chance
     45      *                         to deduplicate resources across pages.
     46      */
     47     void finalizePage(SkPDFCatalog* catalog, bool firstPage,
     48                       SkTDArray<SkPDFObject*>* resourceObjects);
     49 
     50     /** Determine the size of the page content and store to the catalog
     51      *  the offsets of all nonresource-indirect objects that make up the page
     52      *  content.  This must be called before emitPage(), but after finalizePage.
     53      *  @param catalog    The catalog to add the object offsets to.
     54      *  @param fileOffset The file offset where the page content will be
     55      *                    emitted.
     56      */
     57     off_t getPageSize(SkPDFCatalog* catalog, off_t fileOffset);
     58 
     59     /** Output the page content to the passed stream.
     60      *  @param stream     The writable output stream to send the content to.
     61      *  @param catalog    The active object catalog.
     62      */
     63     void emitPage(SkWStream* stream, SkPDFCatalog* catalog);
     64 
     65     /** Generate a page tree for the passed vector of pages.  New objects are
     66      *  added to the catalog.  The pageTree vector is populated with all of
     67      *  the 'Pages' dictionaries as well as the 'Page' objects.  Page trees
     68      *  have both parent and children links, creating reference cycles, so
     69      *  it must be torn down explicitly.  The first page is not added to
     70      *  the pageTree dictionary array so the caller can handle it specially.
     71      *  @param pages      The ordered vector of page objects.
     72      *  @param catalog    The catalog to add new objects into.
     73      *  @param pageTree   An output vector with all of the internal and leaf
     74      *                    nodes of the pageTree.
     75      *  @param rootNode   An output parameter set to the root node.
     76      */
     77     static void GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
     78                                  SkPDFCatalog* catalog,
     79                                  SkTDArray<SkPDFDict*>* pageTree,
     80                                  SkPDFDict** rootNode);
     81 
     82     /** Get the fonts used on this page.
     83      */
     84     SK_API const SkTDArray<SkPDFFont*>& getFontResources() const;
     85 
     86     /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
     87      *  that shows on this page.
     88      */
     89     const SkPDFGlyphSetMap& getFontGlyphUsage() const;
     90 
     91 private:
     92     // Multiple pages may reference the content.
     93     SkRefPtr<SkPDFDevice> fDevice;
     94 
     95     // Once the content is finalized, put it into a stream for output.
     96     SkRefPtr<SkPDFStream> fContentStream;
     97 };
     98 
     99 #endif
    100