blob: 443e8c23a46a7480aa256d227530cbadfac9bd1a [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 SkPDFDocument_DEFINED
11#define SkPDFDocument_DEFINED
12
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000013#include "SkAdvancedTypefaceMetrics.h"
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000014#include "SkRefCnt.h"
15#include "SkTDArray.h"
vandebo@chromium.org421d6442011-07-20 17:39:01 +000016#include "SkTScopedPtr.h"
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000017
vandebo@chromium.org421d6442011-07-20 17:39:01 +000018class SkPDFCatalog;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000019class SkPDFDevice;
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000020class SkPDFDict;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000021class SkPDFPage;
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000022class SkPDFObject;
23class SkWStream;
edisonn@google.com194b7cd2013-02-27 19:45:11 +000024template <typename T> class SK_API SkTSet;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000025
26/** \class SkPDFDocument
27
28 A SkPDFDocument assembles pages together and generates the final PDF file.
29*/
30class SkPDFDocument {
31public:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000032 enum Flags {
vandebo@chromium.org238be8c2012-07-13 20:06:02 +000033 kNoCompression_Flags = 0x01, //!< mask disable stream compression.
34 kNoLinks_Flags = 0x02, //!< do not honor link annotations.
vandebo@chromium.org421d6442011-07-20 17:39:01 +000035
vandebo@chromium.org238be8c2012-07-13 20:06:02 +000036 kDraftMode_Flags = 0x01,
vandebo@chromium.org421d6442011-07-20 17:39:01 +000037 };
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000038 /** Create a PDF document.
39 */
vandebo@chromium.org421d6442011-07-20 17:39:01 +000040 explicit SK_API SkPDFDocument(Flags flags = (Flags)0);
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000041 SK_API ~SkPDFDocument();
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000042
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000043 /** Output the PDF to the passed stream. It is an error to call this (it
44 * will return false and not modify stream) if no pages have been added
45 * or there are pages missing (i.e. page 1 and 3 have been added, but not
46 * page 2).
47 *
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000048 * @param stream The writable output stream to send the PDF to.
49 */
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000050 SK_API bool emitPDF(SkWStream* stream);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000051
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000052 /** Sets the specific page to the passed PDF device. If the specified
53 * page is already set, this overrides it. Returns true if successful.
54 * Will fail if the document has already been emitted.
55 *
56 * @param pageNumber The position to add the passed device (1 based).
57 * @param pdfDevice The page to add to this document.
58 */
reed@google.com1feb3302011-07-20 18:43:19 +000059 SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice);
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000060
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000061 /** Append the passed pdf device to the document as a new page. Returns
62 * true if successful. Will fail if the document has already been emitted.
63 *
64 * @param pdfDevice The page to add to this document.
65 */
reed@google.com1feb3302011-07-20 18:43:19 +000066 SK_API bool appendPage(SkPDFDevice* pdfDevice);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000067
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000068 /** Get the count of unique font types used in the document.
vandebo@chromium.orgd897bfb2011-05-31 18:18:21 +000069 */
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000070 SK_API void getCountOfFontTypes(
71 int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const;
vandebo@chromium.orgd897bfb2011-05-31 18:18:21 +000072
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000073private:
vandebo@chromium.org421d6442011-07-20 17:39:01 +000074 SkTScopedPtr<SkPDFCatalog> fCatalog;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000075 int64_t fXRefFileOffset;
76
77 SkTDArray<SkPDFPage*> fPages;
78 SkTDArray<SkPDFDict*> fPageTree;
reed@google.comaf777272012-09-20 18:19:26 +000079 SkPDFDict* fDocCatalog;
edisonn@google.com194b7cd2013-02-27 19:45:11 +000080 SkTSet<SkPDFObject*>* fFirstPageResources;
81 SkTSet<SkPDFObject*>* fOtherPageResources;
vandebo@chromium.org98594282011-07-25 22:34:12 +000082 SkTDArray<SkPDFObject*> fSubstitutes;
vandebo@chromium.orga5180862010-10-26 19:48:49 +000083 int fSecondPageFirstResourceIndex;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000084
reed@google.comaf777272012-09-20 18:19:26 +000085 SkPDFDict* fTrailerDict;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000086
87 /** Output the PDF header to the passed stream.
88 * @param stream The writable output stream to send the header to.
89 */
90 void emitHeader(SkWStream* stream);
91
92 /** Get the size of the header.
93 */
94 size_t headerSize();
95
96 /** Output the PDF footer to the passed stream.
97 * @param stream The writable output stream to send the footer to.
98 * @param objCount The number of objects in the PDF.
99 */
100 void emitFooter(SkWStream* stream, int64_t objCount);
101};
102
103#endif