• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkTScopedPtr.h"
17 
18 class SkPDFCatalog;
19 class SkPDFDevice;
20 class SkPDFDict;
21 class SkPDFPage;
22 class SkPDFObject;
23 class SkWStream;
24 
25 /** \class SkPDFDocument
26 
27     A SkPDFDocument assembles pages together and generates the final PDF file.
28 */
29 class SkPDFDocument {
30 public:
31     enum Flags {
32         kNoCompression_Flags = 0x01,  //!< mask disable stream compression.
33         kNoLinks_Flags       = 0x02,  //!< do not honor link annotations.
34 
35         kDraftMode_Flags     = 0x01,
36     };
37     /** Create a PDF document.
38      */
39     explicit SK_API SkPDFDocument(Flags flags = (Flags)0);
40     SK_API ~SkPDFDocument();
41 
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      *
47      *  @param stream    The writable output stream to send the PDF to.
48      */
49     SK_API bool emitPDF(SkWStream* stream);
50 
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      */
58     SK_API bool setPage(int pageNumber, SkPDFDevice* pdfDevice);
59 
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      */
65     SK_API bool appendPage(SkPDFDevice* pdfDevice);
66 
67     /** Get the count of unique font types used in the document.
68      */
69     SK_API void getCountOfFontTypes(
70         int counts[SkAdvancedTypefaceMetrics::kNotEmbeddable_Font + 1]) const;
71 
72 private:
73     SkTScopedPtr<SkPDFCatalog> fCatalog;
74     int64_t fXRefFileOffset;
75 
76     SkTDArray<SkPDFPage*> fPages;
77     SkTDArray<SkPDFDict*> fPageTree;
78     SkPDFDict* fDocCatalog;
79     SkTDArray<SkPDFObject*> fPageResources;
80     SkTDArray<SkPDFObject*> fSubstitutes;
81     int fSecondPageFirstResourceIndex;
82 
83     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
102