blob: 7a9505bbed55716ed3f7af7590e5f6d143e95c18 [file] [log] [blame]
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +00001/*
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
25class SkPDFCatalog;
26class SkPDFDevice;
27class 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*/
34class SkPDFPage : public SkPDFDict {
35public:
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.com1feb3302011-07-20 18:43:19 +000040 explicit SkPDFPage(SkPDFDevice* content);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000041 ~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.orga5180862010-10-26 19:48:49 +000048 * @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.orgd877fdb2010-10-12 23:08:13 +000053 */
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.comf6c3ebd2011-07-20 17:20:28 +000084 static void GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000085 SkPDFCatalog* catalog,
86 SkTDArray<SkPDFDict*>* pageTree,
87 SkPDFDict** rootNode);
88
vandebo@chromium.orgf0ec2662011-05-29 05:55:42 +000089 /** Get the fonts used on this page.
90 */
vandebo@chromium.orgd897bfb2011-05-31 18:18:21 +000091 SK_API const SkTDArray<SkPDFFont*>& getFontResources() const;
vandebo@chromium.orgf0ec2662011-05-29 05:55:42 +000092
vandebo@chromium.org98594282011-07-25 22:34:12 +000093 /** 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.orgd877fdb2010-10-12 23:08:13 +000098private:
99 // Multiple pages may reference the content.
100 SkRefPtr<SkPDFDevice> fDevice;
101
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +0000102 // Once the content is finalized, put it into a stream for output.
103 SkRefPtr<SkPDFStream> fContentStream;
104};
105
106#endif