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" |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 16 | #include "SkTScopedPtr.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; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 24 | |
| 25 | /** \class SkPDFDocument |
| 26 | |
| 27 | A SkPDFDocument assembles pages together and generates the final PDF file. |
| 28 | */ |
| 29 | class SkPDFDocument { |
| 30 | public: |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 31 | enum Flags { |
| 32 | kNoCompression_Flag = 0x01, //!< mask disable stream compression. |
| 33 | kNoEmbedding_Flag = 0x02, //!< mask do not embed fonts. |
| 34 | |
| 35 | kDraftMode_Flags = 0x03, |
| 36 | }; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 37 | /** Create a PDF document. |
| 38 | */ |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 39 | explicit SK_API SkPDFDocument(Flags flags = (Flags)0); |
ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 40 | SK_API ~SkPDFDocument(); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 41 | |
vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 42 | /** Output the PDF to the passed stream. It is an error to call this (it |
| 43 | * will return false and not modify stream) if no pages have been added |
| 44 | * or there are pages missing (i.e. page 1 and 3 have been added, but not |
| 45 | * page 2). |
| 46 | * |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 47 | * @param stream The writable output stream to send the PDF to. |
| 48 | */ |
ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 49 | SK_API bool emitPDF(SkWStream* stream); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 50 | |
vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 51 | /** Sets the specific page to the passed PDF device. If the specified |
| 52 | * page is already set, this overrides it. Returns true if successful. |
| 53 | * Will fail if the document has already been emitted. |
| 54 | * |
| 55 | * @param pageNumber The position to add the passed device (1 based). |
| 56 | * @param pdfDevice The page to add to this document. |
| 57 | */ |
reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 58 | SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice); |
vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 59 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 60 | /** Append the passed pdf device to the document as a new page. Returns |
| 61 | * true if successful. Will fail if the document has already been emitted. |
| 62 | * |
| 63 | * @param pdfDevice The page to add to this document. |
| 64 | */ |
reed@google.com | 1feb330 | 2011-07-20 18:43:19 +0000 | [diff] [blame] | 65 | SK_API bool appendPage(SkPDFDevice* pdfDevice); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 66 | |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame^] | 67 | /** Get the count of unique font types used in the document. |
vandebo@chromium.org | d897bfb | 2011-05-31 18:18:21 +0000 | [diff] [blame] | 68 | */ |
vandebo@chromium.org | 7d6c8f9 | 2012-03-22 20:45:15 +0000 | [diff] [blame^] | 69 | SK_API void getCountOfFontTypes( |
| 70 | int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const; |
vandebo@chromium.org | d897bfb | 2011-05-31 18:18:21 +0000 | [diff] [blame] | 71 | |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 72 | private: |
vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame] | 73 | SkTScopedPtr<SkPDFCatalog> fCatalog; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 74 | int64_t fXRefFileOffset; |
| 75 | |
| 76 | SkTDArray<SkPDFPage*> fPages; |
| 77 | SkTDArray<SkPDFDict*> fPageTree; |
| 78 | SkRefPtr<SkPDFDict> fDocCatalog; |
| 79 | SkTDArray<SkPDFObject*> fPageResources; |
vandebo@chromium.org | 9859428 | 2011-07-25 22:34:12 +0000 | [diff] [blame] | 80 | SkTDArray<SkPDFObject*> fSubstitutes; |
vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 81 | int fSecondPageFirstResourceIndex; |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 82 | |
| 83 | SkRefPtr<SkPDFDict> fTrailerDict; |
| 84 | |
| 85 | /** Output the PDF header to the passed stream. |
| 86 | * @param stream The writable output stream to send the header to. |
| 87 | */ |
| 88 | void emitHeader(SkWStream* stream); |
| 89 | |
| 90 | /** Get the size of the header. |
| 91 | */ |
| 92 | size_t headerSize(); |
| 93 | |
| 94 | /** Output the PDF footer to the passed stream. |
| 95 | * @param stream The writable output stream to send the footer to. |
| 96 | * @param objCount The number of objects in the PDF. |
| 97 | */ |
| 98 | void emitFooter(SkWStream* stream, int64_t objCount); |
| 99 | }; |
| 100 | |
| 101 | #endif |