OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDocument.h" | 8 #include "SkDocument.h" |
9 #include "SkPDFCanon.h" | 9 #include "SkPDFCanon.h" |
10 #include "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) { | 64 static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) { |
65 SkAutoTDelete<SkStreamAsset> content(pageDevice->content()); | 65 SkAutoTDelete<SkStreamAsset> content(pageDevice->content()); |
66 return new SkPDFStream(content.get()); | 66 return new SkPDFStream(content.get()); |
67 } | 67 } |
68 | 68 |
69 static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) { | 69 static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) { |
70 SkAutoTUnref<SkPDFDict> page(new SkPDFDict("Page")); | 70 SkAutoTUnref<SkPDFDict> page(new SkPDFDict("Page")); |
71 page->insertObject("Resources", pageDevice->createResourceDict()); | 71 page->insertObject("Resources", pageDevice->createResourceDict()); |
72 page->insertObject("MediaBox", pageDevice->copyMediaBox()); | 72 page->insertObject("MediaBox", pageDevice->copyMediaBox()); |
73 if (SkPDFArray* annots = pageDevice->getAnnotations()) { | 73 SkAutoTUnref<SkPDFArray> annotations(new SkPDFArray); |
74 SkASSERT(annots->size() > 0); | 74 pageDevice->appendAnnotations(annotations); |
75 page->insertObject("Annots", SkRef(annots)); | 75 if (annotations->size() > 0) { |
| 76 page->insertObject("Annots", annotations.detach()); |
76 } | 77 } |
77 page->insertObjRef("Contents", create_pdf_page_content(pageDevice)); | 78 page->insertObjRef("Contents", create_pdf_page_content(pageDevice)); |
78 return page.detach(); | 79 return page.detach(); |
79 } | 80 } |
80 | 81 |
81 static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages, | 82 static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages, |
82 SkTDArray<SkPDFDict*>* pageTree, | 83 SkTDArray<SkPDFDict*>* pageTree, |
83 SkPDFDict** rootNode) { | 84 SkPDFDict** rootNode) { |
84 // PDF wants a tree describing all the pages in the document. We arbitrary | 85 // PDF wants a tree describing all the pages in the document. We arbitrary |
85 // choose 8 (kNodeSize) as the number of allowed children. The internal | 86 // choose 8 (kNodeSize) as the number of allowed children. The internal |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 351 |
351 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 352 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
352 SkFILEWStream* stream = new SkFILEWStream(path); | 353 SkFILEWStream* stream = new SkFILEWStream(path); |
353 if (!stream->isValid()) { | 354 if (!stream->isValid()) { |
354 delete stream; | 355 delete stream; |
355 return nullptr; | 356 return nullptr; |
356 } | 357 } |
357 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 358 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
358 return new SkDocument_PDF(stream, delete_wstream, dpi); | 359 return new SkDocument_PDF(stream, delete_wstream, dpi); |
359 } | 360 } |
OLD | NEW |