| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SkPDFPage_DEFINED |
| 18 | #define SkPDFPage_DEFINED |
| 19 | |
| 20 | #include "SkPDFTypes.h" |
| 21 | #include "SkPDFStream.h" |
| 22 | #include "SkRefCnt.h" |
| 23 | #include "SkTDArray.h" |
| 24 | |
| 25 | class SkPDFCatalog; |
| 26 | class SkPDFDevice; |
| 27 | class SkWStream; |
| 28 | |
| 29 | /** \class SkPDFPage |
| 30 | |
| 31 | A SkPDFPage contains meta information about a page, is used in the page |
| 32 | tree and points to the content of the page. |
| 33 | */ |
| 34 | class SkPDFPage : public SkPDFDict { |
| 35 | public: |
| 36 | /** Create a PDF page with the passed PDF device. The device need not |
| 37 | * have content on it yet. |
| 38 | * @param content The page content. |
| 39 | */ |
| reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 40 | explicit SkPDFPage(SkPDFDevice* content); |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 41 | ~SkPDFPage(); |
| 42 | |
| 43 | /** Before a page and its contents can be sized and emitted, it must |
| 44 | * be finalized. No changes to the PDFDevice will be honored after |
| 45 | * finalizePage has been called. This function adds the page content |
| 46 | * to the passed catalog, so it must be called for each document |
| 47 | * that the page is part of. |
| vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 48 | * @param catalog The catalog to add page content objects to. |
| 49 | * @param firstPage Indicate if this is the first page of a document. |
| 50 | * @param resourceObjects The resource objects used on the page are added |
| 51 | * to this array. This gives the caller a chance |
| 52 | * to deduplicate resources across pages. |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 53 | */ |
| 54 | void finalizePage(SkPDFCatalog* catalog, bool firstPage, |
| 55 | SkTDArray<SkPDFObject*>* resourceObjects); |
| 56 | |
| 57 | /** Determine the size of the page content and store to the catalog |
| 58 | * the offsets of all nonresource-indirect objects that make up the page |
| 59 | * content. This must be called before emitPage(), but after finalizePage. |
| 60 | * @param catalog The catalog to add the object offsets to. |
| 61 | * @param fileOffset The file offset where the page content will be |
| 62 | * emitted. |
| 63 | */ |
| 64 | off_t getPageSize(SkPDFCatalog* catalog, off_t fileOffset); |
| 65 | |
| 66 | /** Output the page content to the passed stream. |
| 67 | * @param stream The writable output stream to send the content to. |
| 68 | * @param catalog The active object catalog. |
| 69 | */ |
| 70 | void emitPage(SkWStream* stream, SkPDFCatalog* catalog); |
| 71 | |
| 72 | /** Generate a page tree for the passed vector of pages. New objects are |
| 73 | * added to the catalog. The pageTree vector is populated with all of |
| 74 | * the 'Pages' dictionaries as well as the 'Page' objects. Page trees |
| 75 | * have both parent and children links, creating reference cycles, so |
| 76 | * it must be torn down explicitly. The first page is not added to |
| 77 | * the pageTree dictionary array so the caller can handle it specially. |
| 78 | * @param pages The ordered vector of page objects. |
| 79 | * @param catalog The catalog to add new objects into. |
| 80 | * @param pageTree An output vector with all of the internal and leaf |
| 81 | * nodes of the pageTree. |
| 82 | * @param rootNode An output parameter set to the root node. |
| 83 | */ |
| reed@google.com | f6c3ebd | 2011-07-20 17:20:28 +0000 | [diff] [blame] | 84 | static void GeneratePageTree(const SkTDArray<SkPDFPage*>& pages, |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 85 | SkPDFCatalog* catalog, |
| 86 | SkTDArray<SkPDFDict*>* pageTree, |
| 87 | SkPDFDict** rootNode); |
| 88 | |
| vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 89 | /** Get the fonts used on this page. |
| 90 | */ |
| vandebo@chromium.org | d897bfb | 2011-05-31 18:18:21 +0000 | [diff] [blame] | 91 | SK_API const SkTDArray<SkPDFFont*>& getFontResources() const; |
| vandebo@chromium.org | f0ec266 | 2011-05-29 05:55:42 +0000 | [diff] [blame] | 92 | |
| vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 93 | /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font |
| 94 | * that shows on this page. |
| 95 | */ |
| 96 | const SkPDFGlyphSetMap& getFontGlyphUsage() const; |
| 97 | |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 98 | private: |
| 99 | // Multiple pages may reference the content. |
| 100 | SkRefPtr<SkPDFDevice> fDevice; |
| 101 | |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 102 | // Once the content is finalized, put it into a stream for output. |
| 103 | SkRefPtr<SkPDFStream> fContentStream; |
| 104 | }; |
| 105 | |
| 106 | #endif |