epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 33 | explicit SkPDFPage(SkPDFDevice* content); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 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. |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 41 | * @param catalog The catalog to add page content objects to. |
| 42 | * @param firstPage Indicate if this is the first page of a document. |
edisonn@google.com | 6addb19 | 2013-04-02 15:33:08 +0000 | [diff] [blame] | 43 | * @param newResourceObjects All the resource objects (recursively) used on |
vandebo@chromium.org | 188838c | 2012-03-09 22:16:58 +0000 | [diff] [blame] | 44 | * the page are added to this array. This gives |
| 45 | * the caller a chance to deduplicate resources |
| 46 | * across pages. |
edisonn@google.com | 6addb19 | 2013-04-02 15:33:08 +0000 | [diff] [blame] | 47 | * @param knownResourceObjects The set of resources to be ignored. |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 48 | */ |
| 49 | void finalizePage(SkPDFCatalog* catalog, bool firstPage, |
edisonn@google.com | 6addb19 | 2013-04-02 15:33:08 +0000 | [diff] [blame] | 50 | const SkTSet<SkPDFObject*>& knownResourceObjects, |
| 51 | SkTSet<SkPDFObject*>* newResourceObjects); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 52 | |
epoger@google.com | b58772f | 2013-03-08 09:09:10 +0000 | [diff] [blame] | 53 | /** Add destinations for this page to the supplied dictionary. |
| 54 | * @param dict Dictionary to add destinations to. |
| 55 | */ |
| 56 | void appendDestinations(SkPDFDict* dict); |
| 57 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 58 | /** Determine the size of the page content and store to the catalog |
| 59 | * the offsets of all nonresource-indirect objects that make up the page |
| 60 | * content. This must be called before emitPage(), but after finalizePage. |
| 61 | * @param catalog The catalog to add the object offsets to. |
| 62 | * @param fileOffset The file offset where the page content will be |
| 63 | * emitted. |
| 64 | */ |
| 65 | off_t getPageSize(SkPDFCatalog* catalog, off_t fileOffset); |
| 66 | |
| 67 | /** Output the page content to the passed stream. |
| 68 | * @param stream The writable output stream to send the content to. |
| 69 | * @param catalog The active object catalog. |
| 70 | */ |
| 71 | void emitPage(SkWStream* stream, SkPDFCatalog* catalog); |
| 72 | |
| 73 | /** Generate a page tree for the passed vector of pages. New objects are |
| 74 | * added to the catalog. The pageTree vector is populated with all of |
| 75 | * the 'Pages' dictionaries as well as the 'Page' objects. Page trees |
| 76 | * have both parent and children links, creating reference cycles, so |
| 77 | * it must be torn down explicitly. The first page is not added to |
| 78 | * the pageTree dictionary array so the caller can handle it specially. |
| 79 | * @param pages The ordered vector of page objects. |
| 80 | * @param catalog The catalog to add new objects into. |
| 81 | * @param pageTree An output vector with all of the internal and leaf |
| 82 | * nodes of the pageTree. |
| 83 | * @param rootNode An output parameter set to the root node. |
| 84 | */ |
reed@google.com | f6c3ebd | 2011-07-20 17:20:28 +0000 | [diff] [blame] | 85 | static void GeneratePageTree(const SkTDArray<SkPDFPage*>& pages, |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 86 | SkPDFCatalog* catalog, |
| 87 | SkTDArray<SkPDFDict*>* pageTree, |
| 88 | SkPDFDict** rootNode); |
| 89 | |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 90 | /** Get the fonts used on this page. |
| 91 | */ |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame] | 92 | const SkTDArray<SkPDFFont*>& getFontResources() const; |
vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 93 | |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 94 | /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
| 95 | * that shows on this page. |
| 96 | */ |
| 97 | const SkPDFGlyphSetMap& getFontGlyphUsage() const; |
| 98 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 99 | private: |
| 100 | // Multiple pages may reference the content. |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 101 | SkAutoTUnref<SkPDFDevice> fDevice; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 102 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 103 | // Once the content is finalized, put it into a stream for output. |
vandebo@chromium.org | d96d17b | 2013-01-04 19:31:24 +0000 | [diff] [blame] | 104 | SkAutoTUnref<SkPDFStream> fContentStream; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | #endif |