| 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 | |
| 20 | #include "SkPDFCatalog.h" |
| 21 | #include "SkPDFTypes.h" |
| 22 | #include "SkRefCnt.h" |
| 23 | #include "SkTDArray.h" |
| 24 | |
| 25 | class SkPDFDevice; |
| 26 | class SkPDFPage; |
| 27 | class SkWSteam; |
| 28 | |
| 29 | /** \class SkPDFDocument |
| 30 | |
| 31 | A SkPDFDocument assembles pages together and generates the final PDF file. |
| 32 | */ |
| 33 | class SkPDFDocument { |
| 34 | public: |
| 35 | /** Create a PDF document. |
| 36 | */ |
| ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 37 | SK_API SkPDFDocument(); |
| 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 | */ |
| 56 | SK_API bool setPage(int pageNumber, const SkRefPtr<SkPDFDevice>& pdfDevice); |
| 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 | */ |
| ctguil@chromium.org | dfc5ffe | 2011-03-30 20:14:49 +0000 | [diff] [blame] | 63 | SK_API bool appendPage(const SkRefPtr<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: |
| 70 | SkPDFCatalog fCatalog; |
| 71 | int64_t fXRefFileOffset; |
| 72 | |
| 73 | SkTDArray<SkPDFPage*> fPages; |
| 74 | SkTDArray<SkPDFDict*> fPageTree; |
| 75 | SkRefPtr<SkPDFDict> fDocCatalog; |
| 76 | SkTDArray<SkPDFObject*> fPageResources; |
| vandebo@chromium.org | a518086 | 2010-10-26 19:48:49 +0000 | [diff] [blame] | 77 | int fSecondPageFirstResourceIndex; |
| vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame] | 78 | |
| 79 | SkRefPtr<SkPDFDict> fTrailerDict; |
| 80 | |
| 81 | /** Output the PDF header to the passed stream. |
| 82 | * @param stream The writable output stream to send the header to. |
| 83 | */ |
| 84 | void emitHeader(SkWStream* stream); |
| 85 | |
| 86 | /** Get the size of the header. |
| 87 | */ |
| 88 | size_t headerSize(); |
| 89 | |
| 90 | /** Output the PDF footer to the passed stream. |
| 91 | * @param stream The writable output stream to send the footer to. |
| 92 | * @param objCount The number of objects in the PDF. |
| 93 | */ |
| 94 | void emitFooter(SkWStream* stream, int64_t objCount); |
| 95 | }; |
| 96 | |
| 97 | #endif |