blob: 17fd437623fca8e2fbf03320535e3b067a34d485 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2010 The Android Open Source Project
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000010#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
18class SkPDFCatalog;
19class SkPDFDevice;
20class 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*/
27class SkPDFPage : public SkPDFDict {
28public:
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.com1feb3302011-07-20 18:43:19 +000033 explicit SkPDFPage(SkPDFDevice* content);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000034 ~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.orga5180862010-10-26 19:48:49 +000041 * @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.com194b7cd2013-02-27 19:45:11 +000043 * @param newResourceObjects All the resource objects (recursively) used on
vandebo@chromium.org188838c2012-03-09 22:16:58 +000044 * the page are added to this array. This gives
45 * the caller a chance to deduplicate resources
46 * across pages.
edisonn@google.com194b7cd2013-02-27 19:45:11 +000047 * @param knownResourceObjects The set of resources to be ignored.
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000048 */
49 void finalizePage(SkPDFCatalog* catalog, bool firstPage,
edisonn@google.com194b7cd2013-02-27 19:45:11 +000050 const SkTSet<SkPDFObject*>& knownResourceObjects,
51 SkTSet<SkPDFObject*>* newResourceObjects);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000052
53 /** Determine the size of the page content and store to the catalog
54 * the offsets of all nonresource-indirect objects that make up the page
55 * content. This must be called before emitPage(), but after finalizePage.
56 * @param catalog The catalog to add the object offsets to.
57 * @param fileOffset The file offset where the page content will be
58 * emitted.
59 */
60 off_t getPageSize(SkPDFCatalog* catalog, off_t fileOffset);
61
62 /** Output the page content to the passed stream.
63 * @param stream The writable output stream to send the content to.
64 * @param catalog The active object catalog.
65 */
66 void emitPage(SkWStream* stream, SkPDFCatalog* catalog);
67
68 /** Generate a page tree for the passed vector of pages. New objects are
69 * added to the catalog. The pageTree vector is populated with all of
70 * the 'Pages' dictionaries as well as the 'Page' objects. Page trees
71 * have both parent and children links, creating reference cycles, so
72 * it must be torn down explicitly. The first page is not added to
73 * the pageTree dictionary array so the caller can handle it specially.
74 * @param pages The ordered vector of page objects.
75 * @param catalog The catalog to add new objects into.
76 * @param pageTree An output vector with all of the internal and leaf
77 * nodes of the pageTree.
78 * @param rootNode An output parameter set to the root node.
79 */
reed@google.comf6c3ebd2011-07-20 17:20:28 +000080 static void GeneratePageTree(const SkTDArray<SkPDFPage*>& pages,
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000081 SkPDFCatalog* catalog,
82 SkTDArray<SkPDFDict*>* pageTree,
83 SkPDFDict** rootNode);
84
vandebo@chromium.orgf0ec2662011-05-29 05:55:42 +000085 /** Get the fonts used on this page.
86 */
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000087 const SkTDArray<SkPDFFont*>& getFontResources() const;
vandebo@chromium.orgf0ec2662011-05-29 05:55:42 +000088
vandebo@chromium.org98594282011-07-25 22:34:12 +000089 /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
90 * that shows on this page.
91 */
92 const SkPDFGlyphSetMap& getFontGlyphUsage() const;
93
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000094private:
95 // Multiple pages may reference the content.
vandebo@chromium.orgd96d17b2013-01-04 19:31:24 +000096 SkAutoTUnref<SkPDFDevice> fDevice;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000097
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000098 // Once the content is finalized, put it into a stream for output.
vandebo@chromium.orgd96d17b2013-01-04 19:31:24 +000099 SkAutoTUnref<SkPDFStream> fContentStream;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +0000100};
101
102#endif