blob: 0a76ea26aa10efc213fa81e5afc39beb5f4c2187 [file] [log] [blame]
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +00001/*
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
25class SkPDFDevice;
26class SkPDFPage;
27class SkWSteam;
28
29/** \class SkPDFDocument
30
31 A SkPDFDocument assembles pages together and generates the final PDF file.
32*/
33class SkPDFDocument {
34public:
35 /** Create a PDF document.
36 */
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000037 SK_API SkPDFDocument();
38 SK_API ~SkPDFDocument();
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000039
40 /** Output the PDF to the passed stream.
41 * @param stream The writable output stream to send the PDF to.
42 */
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000043 SK_API bool emitPDF(SkWStream* stream);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000044
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 */
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000050 SK_API bool appendPage(const SkRefPtr<SkPDFDevice>& pdfDevice);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000051
vandebo@chromium.orgd897bfb2011-05-31 18:18:21 +000052 /** Get the list of pages in this document.
53 */
54 SK_API const SkTDArray<SkPDFPage*>& getPages();
55
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000056private:
57 SkPDFCatalog fCatalog;
58 int64_t fXRefFileOffset;
59
60 SkTDArray<SkPDFPage*> fPages;
61 SkTDArray<SkPDFDict*> fPageTree;
62 SkRefPtr<SkPDFDict> fDocCatalog;
63 SkTDArray<SkPDFObject*> fPageResources;
vandebo@chromium.orga5180862010-10-26 19:48:49 +000064 int fSecondPageFirstResourceIndex;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000065
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