blob: 07738a210bfae59d1230f221842f1412949b8ee9 [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"
commit-bot@chromium.orge0294402013-08-29 22:14:04 +000016#include "SkTemplates.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.coma20e42c2013-05-31 18:04:20 +000024template <typename T> class 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 {
edisonn@google.com8c020612013-03-12 19:53:16 +000033 kNoCompression_Flags = 0x01, //!< DEPRECATED.
34 kFavorSpeedOverSize_Flags = 0x01, //!< Don't compress the stream, but
35 // if it is already compressed return
36 // the compressed stream.
vandebo@chromium.org238be8c2012-07-13 20:06:02 +000037 kNoLinks_Flags = 0x02, //!< do not honor link annotations.
vandebo@chromium.org421d6442011-07-20 17:39:01 +000038
vandebo@chromium.org238be8c2012-07-13 20:06:02 +000039 kDraftMode_Flags = 0x01,
vandebo@chromium.org421d6442011-07-20 17:39:01 +000040 };
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000041 /** Create a PDF document.
42 */
vandebo@chromium.org421d6442011-07-20 17:39:01 +000043 explicit SK_API SkPDFDocument(Flags flags = (Flags)0);
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000044 SK_API ~SkPDFDocument();
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000045
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000046 /** Output the PDF to the passed stream. It is an error to call this (it
47 * will return false and not modify stream) if no pages have been added
48 * or there are pages missing (i.e. page 1 and 3 have been added, but not
49 * page 2).
50 *
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000051 * @param stream The writable output stream to send the PDF to.
52 */
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000053 SK_API bool emitPDF(SkWStream* stream);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000054
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000055 /** Sets the specific page to the passed PDF device. If the specified
56 * page is already set, this overrides it. Returns true if successful.
57 * Will fail if the document has already been emitted.
58 *
59 * @param pageNumber The position to add the passed device (1 based).
60 * @param pdfDevice The page to add to this document.
61 */
reed@google.com1feb3302011-07-20 18:43:19 +000062 SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice);
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000063
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000064 /** Append the passed pdf device to the document as a new page. Returns
65 * true if successful. Will fail if the document has already been emitted.
66 *
67 * @param pdfDevice The page to add to this document.
68 */
reed@google.com1feb3302011-07-20 18:43:19 +000069 SK_API bool appendPage(SkPDFDevice* pdfDevice);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000070
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000071 /** Get the count of unique font types used in the document.
vandebo0f9bad02014-06-19 11:05:39 -070072 * DEPRECATED.
vandebo@chromium.orgd897bfb2011-05-31 18:18:21 +000073 */
vandebo@chromium.org7d6c8f92012-03-22 20:45:15 +000074 SK_API void getCountOfFontTypes(
vandebo0f9bad02014-06-19 11:05:39 -070075 int counts[SkAdvancedTypefaceMetrics::kOther_Font + 2]) const;
76
77 /** Get the count of unique font types used in the document.
78 */
79 SK_API void getCountOfFontTypes(
80 int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1],
81 int* notSubsettableCount,
82 int* notEmbedddableCount) const;
vandebo@chromium.orgd897bfb2011-05-31 18:18:21 +000083
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000084private:
commit-bot@chromium.orge0294402013-08-29 22:14:04 +000085 SkAutoTDelete<SkPDFCatalog> fCatalog;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000086 int64_t fXRefFileOffset;
87
88 SkTDArray<SkPDFPage*> fPages;
89 SkTDArray<SkPDFDict*> fPageTree;
reed@google.comaf777272012-09-20 18:19:26 +000090 SkPDFDict* fDocCatalog;
edisonn@google.com6addb192013-04-02 15:33:08 +000091 SkTSet<SkPDFObject*>* fFirstPageResources;
92 SkTSet<SkPDFObject*>* fOtherPageResources;
vandebo@chromium.org98594282011-07-25 22:34:12 +000093 SkTDArray<SkPDFObject*> fSubstitutes;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000094
reed@google.comaf777272012-09-20 18:19:26 +000095 SkPDFDict* fTrailerDict;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000096
97 /** Output the PDF header to the passed stream.
98 * @param stream The writable output stream to send the header to.
99 */
100 void emitHeader(SkWStream* stream);
101
102 /** Get the size of the header.
103 */
104 size_t headerSize();
105
106 /** Output the PDF footer to the passed stream.
107 * @param stream The writable output stream to send the footer to.
108 * @param objCount The number of objects in the PDF.
109 */
110 void emitFooter(SkWStream* stream, int64_t objCount);
111};
112
113#endif