epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 The Android Open Source Project |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 4 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 10 | #ifndef SkPDFDocument_DEFINED |
| 11 | #define SkPDFDocument_DEFINED |
| 12 | |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame] | 13 | #include "SkAdvancedTypefaceMetrics.h" |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 14 | #include "SkRefCnt.h" |
| 15 | #include "SkTDArray.h" |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame^] | 16 | #include "SkTemplates.h" |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 17 | |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 18 | class SkPDFCatalog; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 19 | class SkPDFDevice; |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame] | 20 | class SkPDFDict; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 21 | class SkPDFPage; |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame] | 22 | class SkPDFObject; |
| 23 | class SkWStream; |
edisonn@google.com | a20e42c | 2013-05-31 18:04:20 +0000 | [diff] [blame] | 24 | template <typename T> class SkTSet; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 25 | |
| 26 | /** \class SkPDFDocument |
| 27 | |
| 28 | A SkPDFDocument assembles pages together and generates the final PDF file. |
| 29 | */ |
| 30 | class SkPDFDocument { |
| 31 | public: |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 32 | enum Flags { |
edisonn@google.com | 8c02061 | 2013-03-12 19:53:16 +0000 | [diff] [blame] | 33 | 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.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 37 | kNoLinks_Flags = 0x02, //!< do not honor link annotations. |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 38 | |
vandebo@chromium.org | 238be8c | 2012-07-13 20:06:02 +0000 | [diff] [blame] | 39 | kDraftMode_Flags = 0x01, |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 40 | }; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 41 | /** Create a PDF document. |
| 42 | */ |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 43 | explicit SK_API SkPDFDocument(Flags flags = (Flags)0); |
ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 44 | SK_API ~SkPDFDocument(); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 45 | |
vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 46 | /** 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.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 51 | * @param stream The writable output stream to send the PDF to. |
| 52 | */ |
ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 53 | SK_API bool emitPDF(SkWStream* stream); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 54 | |
vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 55 | /** 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.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 62 | SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice); |
vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 63 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 64 | /** 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.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 69 | SK_API bool appendPage(SkPDFDevice* pdfDevice); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 70 | |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame] | 71 | /** Get the count of unique font types used in the document. |
vandebo@chromium.org | d897bfb | 2011-05-31 18:18:21 +0000 | [diff] [blame] | 72 | */ |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame] | 73 | SK_API void getCountOfFontTypes( |
| 74 | int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const; |
vandebo@chromium.org | d897bfb | 2011-05-31 18:18:21 +0000 | [diff] [blame] | 75 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 76 | private: |
commit-bot@chromium.org | e029440 | 2013-08-29 22:14:04 +0000 | [diff] [blame^] | 77 | SkAutoTDelete<SkPDFCatalog> fCatalog; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 78 | int64_t fXRefFileOffset; |
| 79 | |
| 80 | SkTDArray<SkPDFPage*> fPages; |
| 81 | SkTDArray<SkPDFDict*> fPageTree; |
reed@google.com | af77727 | 2012-09-20 18:19:26 +0000 | [diff] [blame] | 82 | SkPDFDict* fDocCatalog; |
edisonn@google.com | 6addb19 | 2013-04-02 15:33:08 +0000 | [diff] [blame] | 83 | SkTSet<SkPDFObject*>* fFirstPageResources; |
| 84 | SkTSet<SkPDFObject*>* fOtherPageResources; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 85 | SkTDArray<SkPDFObject*> fSubstitutes; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 86 | |
reed@google.com | af77727 | 2012-09-20 18:19:26 +0000 | [diff] [blame] | 87 | SkPDFDict* fTrailerDict; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 88 | |
| 89 | /** Output the PDF header to the passed stream. |
| 90 | * @param stream The writable output stream to send the header to. |
| 91 | */ |
| 92 | void emitHeader(SkWStream* stream); |
| 93 | |
| 94 | /** Get the size of the header. |
| 95 | */ |
| 96 | size_t headerSize(); |
| 97 | |
| 98 | /** Output the PDF footer to the passed stream. |
| 99 | * @param stream The writable output stream to send the footer to. |
| 100 | * @param objCount The number of objects in the PDF. |
| 101 | */ |
| 102 | void emitFooter(SkWStream* stream, int64_t objCount); |
| 103 | }; |
| 104 | |
| 105 | #endif |