|
1 |
|
2 /* |
|
3 * Copyright 2010 The Android Open Source Project |
|
4 * |
|
5 * Use of this source code is governed by a BSD-style license that can be |
|
6 * found in the LICENSE file. |
|
7 */ |
|
8 |
|
9 |
|
10 #ifndef SkPDFDocument_DEFINED |
|
11 #define SkPDFDocument_DEFINED |
|
12 |
|
13 #include "SkAdvancedTypefaceMetrics.h" |
|
14 #include "SkRefCnt.h" |
|
15 #include "SkTDArray.h" |
|
16 #include "SkTemplates.h" |
|
17 |
|
18 class SkPDFCatalog; |
|
19 class SkPDFDevice; |
|
20 class SkPDFDict; |
|
21 class SkPDFPage; |
|
22 class SkPDFObject; |
|
23 class SkWStream; |
|
24 template <typename T> class SkTSet; |
|
25 |
|
26 /** \class SkPDFDocument |
|
27 |
|
28 A SkPDFDocument assembles pages together and generates the final PDF file. |
|
29 */ |
|
30 class SkPDFDocument { |
|
31 public: |
|
32 enum Flags { |
|
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. |
|
37 kNoLinks_Flags = 0x02, //!< do not honor link annotations. |
|
38 |
|
39 kDraftMode_Flags = 0x01, |
|
40 }; |
|
41 /** Create a PDF document. |
|
42 */ |
|
43 explicit SK_API SkPDFDocument(Flags flags = (Flags)0); |
|
44 SK_API ~SkPDFDocument(); |
|
45 |
|
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 * |
|
51 * @param stream The writable output stream to send the PDF to. |
|
52 */ |
|
53 SK_API bool emitPDF(SkWStream* stream); |
|
54 |
|
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 */ |
|
62 SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice); |
|
63 |
|
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 */ |
|
69 SK_API bool appendPage(SkPDFDevice* pdfDevice); |
|
70 |
|
71 /** Get the count of unique font types used in the document. |
|
72 */ |
|
73 SK_API void getCountOfFontTypes( |
|
74 int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const; |
|
75 |
|
76 private: |
|
77 SkAutoTDelete<SkPDFCatalog> fCatalog; |
|
78 int64_t fXRefFileOffset; |
|
79 |
|
80 SkTDArray<SkPDFPage*> fPages; |
|
81 SkTDArray<SkPDFDict*> fPageTree; |
|
82 SkPDFDict* fDocCatalog; |
|
83 SkTSet<SkPDFObject*>* fFirstPageResources; |
|
84 SkTSet<SkPDFObject*>* fOtherPageResources; |
|
85 SkTDArray<SkPDFObject*> fSubstitutes; |
|
86 |
|
87 SkPDFDict* fTrailerDict; |
|
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 |