OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 The Android Open Source Project | 3 * Copyright 2010 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkData.h" | 10 #include "SkData.h" |
11 #include "SkPDFCatalog.h" | 11 #include "SkPDFCatalog.h" |
12 #include "SkPDFDevice.h" | 12 #include "SkPDFDevice.h" |
13 #include "SkPDFPage.h" | 13 #include "SkPDFPage.h" |
14 #include "SkPDFResourceDict.h" | 14 #include "SkPDFResourceDict.h" |
15 | 15 |
16 SkPDFPage::SkPDFPage(SkPDFDevice* content) | 16 SkPDFPage::SkPDFPage(SkPDFDevice* content) |
17 : SkPDFDict("Page"), | 17 : SkPDFDict("Page"), |
18 fDevice(content) { | 18 fDevice(content) { |
19 SkSafeRef(content); | 19 SkSafeRef(content); |
20 } | 20 } |
21 | 21 |
22 SkPDFPage::~SkPDFPage() {} | 22 SkPDFPage::~SkPDFPage() {} |
23 | 23 |
24 void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage, | 24 void SkPDFPage::finalizePage(SkPDFCatalog* catalog, bool firstPage, |
25 const SkTSet<SkPDFObject*>& knownResourceObjects, | 25 const SkTSet<SkPDFObject*>& knownResourceObjects, |
26 SkTSet<SkPDFObject*>* newResourceObjects) { | 26 SkTSet<SkPDFObject*>* newResourceObjects) { |
27 SkPDFResourceDict* resourceDict = fDevice->getResourceDict(); | |
28 if (fContentStream.get() == NULL) { | 27 if (fContentStream.get() == NULL) { |
29 insert("Resources", resourceDict); | 28 this->insert("Resources", fDevice->getResourceDict()); |
30 SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox())); | 29 SkSafeUnref(this->insert("MediaBox", fDevice->copyMediaBox())); |
31 if (!SkToBool(catalog->getDocumentFlags() & | 30 if (!SkToBool(catalog->getDocumentFlags() & |
32 SkPDFDocument::kNoLinks_Flags)) { | 31 SkPDFDocument::kNoLinks_Flags)) { |
33 SkPDFArray* annots = fDevice->getAnnotations(); | 32 SkPDFArray* annots = fDevice->getAnnotations(); |
34 if (annots && annots->size() > 0) { | 33 if (annots && annots->size() > 0) { |
35 insert("Annots", annots); | 34 insert("Annots", annots); |
36 } | 35 } |
37 } | 36 } |
38 | 37 |
39 SkAutoTUnref<SkData> content(fDevice->copyContentToData()); | 38 SkAutoTUnref<SkData> content(fDevice->copyContentToData()); |
40 fContentStream.reset(new SkPDFStream(content.get())); | 39 fContentStream.reset(new SkPDFStream(content.get())); |
41 insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref(); | 40 insert("Contents", new SkPDFObjRef(fContentStream.get()))->unref(); |
42 } | 41 } |
43 catalog->addObject(fContentStream.get(), firstPage); | 42 catalog->addObject(fContentStream.get(), firstPage); |
44 resourceDict->getReferencedResources(knownResourceObjects, | |
45 newResourceObjects, | |
46 true); | |
47 } | 43 } |
48 | 44 |
49 // static | 45 // static |
50 void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages, | 46 void SkPDFPage::GeneratePageTree(const SkTDArray<SkPDFPage*>& pages, |
51 SkPDFCatalog* catalog, | 47 SkPDFCatalog* catalog, |
52 SkTDArray<SkPDFDict*>* pageTree, | 48 SkTDArray<SkPDFDict*>* pageTree, |
53 SkPDFDict** rootNode) { | 49 SkPDFDict** rootNode) { |
54 // PDF wants a tree describing all the pages in the document. We arbitrary | 50 // PDF wants a tree describing all the pages in the document. We arbitrary |
55 // choose 8 (kNodeSize) as the number of allowed children. The internal | 51 // choose 8 (kNodeSize) as the number of allowed children. The internal |
56 // nodes have type "Pages" with an array of children, a parent pointer, and | 52 // nodes have type "Pages" with an array of children, a parent pointer, and |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return fDevice->getFontGlyphUsage(); | 138 return fDevice->getFontGlyphUsage(); |
143 } | 139 } |
144 | 140 |
145 void SkPDFPage::appendDestinations(SkPDFDict* dict) { | 141 void SkPDFPage::appendDestinations(SkPDFDict* dict) { |
146 fDevice->appendDestinations(dict, this); | 142 fDevice->appendDestinations(dict, this); |
147 } | 143 } |
148 | 144 |
149 SkPDFObject* SkPDFPage::getContentStream() const { | 145 SkPDFObject* SkPDFPage::getContentStream() const { |
150 return fContentStream.get(); | 146 return fContentStream.get(); |
151 } | 147 } |
OLD | NEW |