| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SkPDFDocument_DEFINED |
| 18 | #define SkPDFDocument_DEFINED |
| 19 | |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 20 | #include "SkPDFTypes.h" |
| 21 | #include "SkRefCnt.h" |
| 22 | #include "SkTDArray.h" |
| vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame^] | 23 | #include "SkTScopedPtr.h" |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 24 | |
| vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame^] | 25 | class SkPDFCatalog; |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 26 | class SkPDFDevice; |
| 27 | class SkPDFPage; |
| 28 | class SkWSteam; |
| 29 | |
| 30 | /** \class SkPDFDocument |
| 31 | |
| 32 | A SkPDFDocument assembles pages together and generates the final PDF file. |
| 33 | */ |
| 34 | class SkPDFDocument { |
| 35 | public: |
| vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame^] | 36 | enum Flags { |
| 37 | kNoCompression_Flag = 0x01, //!< mask disable stream compression. |
| 38 | kNoEmbedding_Flag = 0x02, //!< mask do not embed fonts. |
| 39 | |
| 40 | kDraftMode_Flags = 0x03, |
| 41 | }; |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 42 | /** Create a PDF document. |
| 43 | */ |
| vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame^] | 44 | explicit SK_API SkPDFDocument(Flags flags = (Flags)0); |
| ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 45 | SK_API ~SkPDFDocument(); |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 46 | |
| vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 47 | /** Output the PDF to the passed stream. It is an error to call this (it |
| 48 | * will return false and not modify stream) if no pages have been added |
| 49 | * or there are pages missing (i.e. page 1 and 3 have been added, but not |
| 50 | * page 2). |
| 51 | * |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 52 | * @param stream The writable output stream to send the PDF to. |
| 53 | */ |
| ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 54 | SK_API bool emitPDF(SkWStream* stream); |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 55 | |
| vandebo@chromium.org | fb6a53a | 2011-07-18 23:13:19 +0000 | [diff] [blame] | 56 | /** Sets the specific page to the passed PDF device. If the specified |
| 57 | * page is already set, this overrides it. Returns true if successful. |
| 58 | * Will fail if the document has already been emitted. |
| 59 | * |
| 60 | * @param pageNumber The position to add the passed device (1 based). |
| 61 | * @param pdfDevice The page to add to this document. |
| 62 | */ |
| 63 | SK_API bool setPage(int pageNumber, const SkRefPtr<SkPDFDevice>& pdfDevice); |
| 64 | |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 65 | /** Append the passed pdf device to the document as a new page. Returns |
| 66 | * true if successful. Will fail if the document has already been emitted. |
| 67 | * |
| 68 | * @param pdfDevice The page to add to this document. |
| 69 | */ |
| ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 70 | SK_API bool appendPage(const SkRefPtr<SkPDFDevice>& pdfDevice); |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 71 | |
| vandebo@chromium.org | d897bfb | 2011-05-31 18:18:21 +0000 | [diff] [blame] | 72 | /** Get the list of pages in this document. |
| 73 | */ |
| 74 | SK_API const SkTDArray<SkPDFPage*>& getPages(); |
| 75 | |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 76 | private: |
| vandebo@chromium.org | 421d644 | 2011-07-20 17:39:01 +0000 | [diff] [blame^] | 77 | SkTScopedPtr<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; |
| 82 | SkRefPtr<SkPDFDict> fDocCatalog; |
| 83 | SkTDArray<SkPDFObject*> fPageResources; |
| vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 84 | int fSecondPageFirstResourceIndex; |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 85 | |
| 86 | SkRefPtr<SkPDFDict> fTrailerDict; |
| 87 | |
| 88 | /** Output the PDF header to the passed stream. |
| 89 | * @param stream The writable output stream to send the header to. |
| 90 | */ |
| 91 | void emitHeader(SkWStream* stream); |
| 92 | |
| 93 | /** Get the size of the header. |
| 94 | */ |
| 95 | size_t headerSize(); |
| 96 | |
| 97 | /** Output the PDF footer to the passed stream. |
| 98 | * @param stream The writable output stream to send the footer to. |
| 99 | * @param objCount The number of objects in the PDF. |
| 100 | */ |
| 101 | void emitFooter(SkWStream* stream, int64_t objCount); |
| 102 | }; |
| 103 | |
| 104 | #endif |