180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/* 380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2010 The Android Open Source Project 480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * 580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be 680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file. 780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef SkPDFPage_DEFINED 1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define SkPDFPage_DEFINED 1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPDFTypes.h" 1480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkPDFStream.h" 1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkRefCnt.h" 1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkTDArray.h" 1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkPDFCatalog; 1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkPDFDevice; 2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkWStream; 2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/** \class SkPDFPage 2380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru A SkPDFPage contains meta information about a page, is used in the page 2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru tree and points to the content of the page. 2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru*/ 2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass SkPDFPage : public SkPDFDict { 28910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger SK_DECLARE_INST_COUNT(SkPDFPage) 2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic: 3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Create a PDF page with the passed PDF device. The device need not 3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * have content on it yet. 3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param content The page content. 3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru explicit SkPDFPage(SkPDFDevice* content); 3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru ~SkPDFPage(); 3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Before a page and its contents can be sized and emitted, it must 3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * be finalized. No changes to the PDFDevice will be honored after 3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * finalizePage has been called. This function adds the page content 4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * to the passed catalog, so it must be called for each document 4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * that the page is part of. 4280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param catalog The catalog to add page content objects to. 4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param firstPage Indicate if this is the first page of a document. 447839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger * @param newResourceObjects All the resource objects (recursively) used on 4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * the page are added to this array. This gives 4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * the caller a chance to deduplicate resources 4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * across pages. 487839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger * @param knownResourceObjects The set of resources to be ignored. 4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void finalizePage(SkPDFCatalog* catalog, bool firstPage, 517839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger const SkTSet<SkPDFObject*>& knownResourceObjects, 527839ce1af63bf12fe7b3caa866970bbbb3afb13dDerek Sollenberger SkTSet<SkPDFObject*>* newResourceObjects); 5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 54096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger /** Add destinations for this page to the supplied dictionary. 55096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger * @param dict Dictionary to add destinations to. 56096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger */ 57096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger void appendDestinations(SkPDFDict* dict); 58096defe64d408e54474fe19f418c95bf1a554fc7Derek Sollenberger 5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Determine the size of the page content and store to the catalog 6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * the offsets of all nonresource-indirect objects that make up the page 6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * content. This must be called before emitPage(), but after finalizePage. 6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param catalog The catalog to add the object offsets to. 6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param fileOffset The file offset where the page content will be 6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * emitted. 6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru off_t getPageSize(SkPDFCatalog* catalog, off_t fileOffset); 6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Output the page content to the passed stream. 6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param stream The writable output stream to send the content to. 7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param catalog The active object catalog. 7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru void emitPage(SkWStream* stream, SkPDFCatalog* catalog); 7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Generate a page tree for the passed vector of pages. New objects are 7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * added to the catalog. The pageTree vector is populated with all of 7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * the 'Pages' dictionaries as well as the 'Page' objects. Page trees 7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * have both parent and children links, creating reference cycles, so 7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * it must be torn down explicitly. The first page is not added to 7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * the pageTree dictionary array so the caller can handle it specially. 8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param pages The ordered vector of page objects. 8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param catalog The catalog to add new objects into. 8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param pageTree An output vector with all of the internal and leaf 8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * nodes of the pageTree. 8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * @param rootNode An output parameter set to the root node. 8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru static void GeneratePageTree(const SkTDArray<SkPDFPage*>& pages, 8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPDFCatalog* catalog, 8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkTDArray<SkPDFDict*>* pageTree, 8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru SkPDFDict** rootNode); 9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Get the fonts used on this page. 9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkTDArray<SkPDFFont*>& getFontResources() const; 9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font 9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * that shows on this page. 9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */ 9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru const SkPDFGlyphSetMap& getFontGlyphUsage() const; 9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate: 10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // Multiple pages may reference the content. 102d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger SkAutoTUnref<SkPDFDevice> fDevice; 10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru // Once the content is finalized, put it into a stream for output. 105d686ac77c2c485c4a3302eda9c1de597a6f8c568Derek Sollenberger SkAutoTUnref<SkPDFStream> fContentStream; 106910f694aefb0b671dd8522a9afe9b6be645701c1Derek Sollenberger typedef SkPDFDict INHERITED; 10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru}; 10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru 10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif 110