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