michael@0: michael@0: /* michael@0: * Copyright 2010 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkPDFPage_DEFINED michael@0: #define SkPDFPage_DEFINED michael@0: michael@0: #include "SkPDFTypes.h" michael@0: #include "SkPDFStream.h" michael@0: #include "SkRefCnt.h" michael@0: #include "SkTDArray.h" michael@0: michael@0: class SkPDFCatalog; michael@0: class SkPDFDevice; michael@0: class SkWStream; michael@0: michael@0: /** \class SkPDFPage michael@0: michael@0: A SkPDFPage contains meta information about a page, is used in the page michael@0: tree and points to the content of the page. michael@0: */ michael@0: class SkPDFPage : public SkPDFDict { michael@0: SK_DECLARE_INST_COUNT(SkPDFPage) michael@0: public: michael@0: /** Create a PDF page with the passed PDF device. The device need not michael@0: * have content on it yet. michael@0: * @param content The page content. michael@0: */ michael@0: explicit SkPDFPage(SkPDFDevice* content); michael@0: ~SkPDFPage(); michael@0: michael@0: /** Before a page and its contents can be sized and emitted, it must michael@0: * be finalized. No changes to the PDFDevice will be honored after michael@0: * finalizePage has been called. This function adds the page content michael@0: * to the passed catalog, so it must be called for each document michael@0: * that the page is part of. michael@0: * @param catalog The catalog to add page content objects to. michael@0: * @param firstPage Indicate if this is the first page of a document. michael@0: * @param newResourceObjects All the resource objects (recursively) used on michael@0: * the page are added to this array. This gives michael@0: * the caller a chance to deduplicate resources michael@0: * across pages. michael@0: * @param knownResourceObjects The set of resources to be ignored. michael@0: */ michael@0: void finalizePage(SkPDFCatalog* catalog, bool firstPage, michael@0: const SkTSet& knownResourceObjects, michael@0: SkTSet* newResourceObjects); michael@0: michael@0: /** Add destinations for this page to the supplied dictionary. michael@0: * @param dict Dictionary to add destinations to. michael@0: */ michael@0: void appendDestinations(SkPDFDict* dict); michael@0: michael@0: /** Determine the size of the page content and store to the catalog michael@0: * the offsets of all nonresource-indirect objects that make up the page michael@0: * content. This must be called before emitPage(), but after finalizePage. michael@0: * @param catalog The catalog to add the object offsets to. michael@0: * @param fileOffset The file offset where the page content will be michael@0: * emitted. michael@0: */ michael@0: off_t getPageSize(SkPDFCatalog* catalog, off_t fileOffset); michael@0: michael@0: /** Output the page content to the passed stream. michael@0: * @param stream The writable output stream to send the content to. michael@0: * @param catalog The active object catalog. michael@0: */ michael@0: void emitPage(SkWStream* stream, SkPDFCatalog* catalog); michael@0: michael@0: /** Generate a page tree for the passed vector of pages. New objects are michael@0: * added to the catalog. The pageTree vector is populated with all of michael@0: * the 'Pages' dictionaries as well as the 'Page' objects. Page trees michael@0: * have both parent and children links, creating reference cycles, so michael@0: * it must be torn down explicitly. The first page is not added to michael@0: * the pageTree dictionary array so the caller can handle it specially. michael@0: * @param pages The ordered vector of page objects. michael@0: * @param catalog The catalog to add new objects into. michael@0: * @param pageTree An output vector with all of the internal and leaf michael@0: * nodes of the pageTree. michael@0: * @param rootNode An output parameter set to the root node. michael@0: */ michael@0: static void GeneratePageTree(const SkTDArray& pages, michael@0: SkPDFCatalog* catalog, michael@0: SkTDArray* pageTree, michael@0: SkPDFDict** rootNode); michael@0: michael@0: /** Get the fonts used on this page. michael@0: */ michael@0: const SkTDArray& getFontResources() const; michael@0: michael@0: /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font michael@0: * that shows on this page. michael@0: */ michael@0: const SkPDFGlyphSetMap& getFontGlyphUsage() const; michael@0: michael@0: private: michael@0: // Multiple pages may reference the content. michael@0: SkAutoTUnref fDevice; michael@0: michael@0: // Once the content is finalized, put it into a stream for output. michael@0: SkAutoTUnref fContentStream; michael@0: typedef SkPDFDict INHERITED; michael@0: }; michael@0: michael@0: #endif