• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      */
37     SK_API SkPDFDocument();
38     SK_API ~SkPDFDocument();
39 
40     /** Output the PDF to the passed stream.
41      *  @param stream    The writable output stream to send the PDF to.
42      */
43     SK_API bool emitPDF(SkWStream* stream);
44 
45     /** Append the passed pdf device to the document as a new page.  Returns
46      *  true if successful.  Will fail if the document has already been emitted.
47      *
48      *  @param pdfDevice The page to add to this document.
49      */
50     SK_API bool appendPage(const SkRefPtr<SkPDFDevice>& pdfDevice);
51 
52     /** Get the list of pages in this document.
53      */
54     SK_API const SkTDArray<SkPDFPage*>& getPages();
55 
56 private:
57     SkPDFCatalog fCatalog;
58     int64_t fXRefFileOffset;
59 
60     SkTDArray<SkPDFPage*> fPages;
61     SkTDArray<SkPDFDict*> fPageTree;
62     SkRefPtr<SkPDFDict> fDocCatalog;
63     SkTDArray<SkPDFObject*> fPageResources;
64     int fSecondPageFirstResourceIndex;
65 
66     SkRefPtr<SkPDFDict> fTrailerDict;
67 
68     /** Output the PDF header to the passed stream.
69      *  @param stream    The writable output stream to send the header to.
70      */
71     void emitHeader(SkWStream* stream);
72 
73     /** Get the size of the header.
74      */
75     size_t headerSize();
76 
77     /** Output the PDF footer to the passed stream.
78      *  @param stream    The writable output stream to send the footer to.
79      *  @param objCount  The number of objects in the PDF.
80      */
81     void emitFooter(SkWStream* stream, int64_t objCount);
82 };
83 
84 #endif
85