gfx/skia/trunk/src/pdf/SkPDFPage.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/pdf/SkPDFPage.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2010 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#ifndef SkPDFPage_DEFINED
    1.14 +#define SkPDFPage_DEFINED
    1.15 +
    1.16 +#include "SkPDFTypes.h"
    1.17 +#include "SkPDFStream.h"
    1.18 +#include "SkRefCnt.h"
    1.19 +#include "SkTDArray.h"
    1.20 +
    1.21 +class SkPDFCatalog;
    1.22 +class SkPDFDevice;
    1.23 +class SkWStream;
    1.24 +
    1.25 +/** \class SkPDFPage
    1.26 +
    1.27 +    A SkPDFPage contains meta information about a page, is used in the page
    1.28 +    tree and points to the content of the page.
    1.29 +*/
    1.30 +class SkPDFPage : public SkPDFDict {
    1.31 +    SK_DECLARE_INST_COUNT(SkPDFPage)
    1.32 +public:
    1.33 +    /** Create a PDF page with the passed PDF device.  The device need not
    1.34 +     *  have content on it yet.
    1.35 +     *  @param content    The page content.
    1.36 +     */
    1.37 +    explicit SkPDFPage(SkPDFDevice* content);
    1.38 +    ~SkPDFPage();
    1.39 +
    1.40 +    /** Before a page and its contents can be sized and emitted, it must
    1.41 +     *  be finalized.  No changes to the PDFDevice will be honored after
    1.42 +     *  finalizePage has been called.  This function adds the page content
    1.43 +     *  to the passed catalog, so it must be called for each document
    1.44 +     *  that the page is part of.
    1.45 +     *  @param catalog         The catalog to add page content objects to.
    1.46 +     *  @param firstPage       Indicate if this is the first page of a document.
    1.47 +     *  @param newResourceObjects All the resource objects (recursively) used on
    1.48 +     *                         the page are added to this array.  This gives
    1.49 +     *                         the caller a chance to deduplicate resources
    1.50 +     *                         across pages.
    1.51 +     *  @param knownResourceObjects  The set of resources to be ignored.
    1.52 +     */
    1.53 +    void finalizePage(SkPDFCatalog* catalog, bool firstPage,
    1.54 +                      const SkTSet<SkPDFObject*>& knownResourceObjects,
    1.55 +                      SkTSet<SkPDFObject*>* newResourceObjects);
    1.56 +
    1.57 +    /** Add destinations for this page to the supplied dictionary.
    1.58 +     *  @param dict       Dictionary to add destinations to.
    1.59 +     */
    1.60 +    void appendDestinations(SkPDFDict* dict);
    1.61 +
    1.62 +    /** Determine the size of the page content and store to the catalog
    1.63 +     *  the offsets of all nonresource-indirect objects that make up the page
    1.64 +     *  content.  This must be called before emitPage(), but after finalizePage.
    1.65 +     *  @param catalog    The catalog to add the object offsets to.
    1.66 +     *  @param fileOffset The file offset where the page content will be
    1.67 +     *                    emitted.
    1.68 +     */
    1.69 +    off_t getPageSize(SkPDFCatalog* catalog, off_t fileOffset);
    1.70 +
    1.71 +    /** Output the page content to the passed stream.
    1.72 +     *  @param stream     The writable output stream to send the content to.
    1.73 +     *  @param catalog    The active object catalog.
    1.74 +     */
    1.75 +    void emitPage(SkWStream* stream, SkPDFCatalog* catalog);
    1.76 +
    1.77 +    /** Generate a page tree for the passed vector of pages.  New objects are
    1.78 +     *  added to the catalog.  The pageTree vector is populated with all of
    1.79 +     *  the 'Pages' dictionaries as well as the 'Page' objects.  Page trees
    1.80 +     *  have both parent and children links, creating reference cycles, so
    1.81 +     *  it must be torn down explicitly.  The first page is not added to
    1.82 +     *  the pageTree dictionary array so the caller can handle it specially.
    1.83 +     *  @param pages      The ordered vector of page objects.
    1.84 +     *  @param catalog    The catalog to add new objects into.
    1.85 +     *  @param pageTree   An output vector with all of the internal and leaf
    1.86 +     *                    nodes of the pageTree.
    1.87 +     *  @param rootNode   An output parameter set to the root node.
    1.88 +     */
    1.89 +    static void GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
    1.90 +                                 SkPDFCatalog* catalog,
    1.91 +                                 SkTDArray<SkPDFDict*>* pageTree,
    1.92 +                                 SkPDFDict** rootNode);
    1.93 +
    1.94 +    /** Get the fonts used on this page.
    1.95 +     */
    1.96 +    const SkTDArray<SkPDFFont*>& getFontResources() const;
    1.97 +
    1.98 +    /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
    1.99 +     *  that shows on this page.
   1.100 +     */
   1.101 +    const SkPDFGlyphSetMap& getFontGlyphUsage() const;
   1.102 +
   1.103 +private:
   1.104 +    // Multiple pages may reference the content.
   1.105 +    SkAutoTUnref<SkPDFDevice> fDevice;
   1.106 +
   1.107 +    // Once the content is finalized, put it into a stream for output.
   1.108 +    SkAutoTUnref<SkPDFStream> fContentStream;
   1.109 +    typedef SkPDFDict INHERITED;
   1.110 +};
   1.111 +
   1.112 +#endif

mercurial