blob: 5fb7c954059ce3181a1b6b49a32c1c3653c0b432 [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
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000040 /** 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.orgd877fdb2010-10-12 23:08:13 +000045 * @param stream The writable output stream to send the PDF to.
46 */
ctguil@chromium.orgdfc5ffe2011-03-30 20:14:49 +000047 SK_API bool emitPDF(SkWStream* stream);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000048
vandebo@chromium.orgfb6a53a2011-07-18 23:13:19 +000049 /** 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.orgd877fdb2010-10-12 23:08:13 +000058 /** 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.orgdfc5ffe2011-03-30 20:14:49 +000063 SK_API bool appendPage(const SkRefPtr<SkPDFDevice>& pdfDevice);
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000064
vandebo@chromium.orgd897bfb2011-05-31 18:18:21 +000065 /** Get the list of pages in this document.
66 */
67 SK_API const SkTDArray<SkPDFPage*>& getPages();
68
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000069private:
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.orga5180862010-10-26 19:48:49 +000077 int fSecondPageFirstResourceIndex;
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000078
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