Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Side by Side Diff: src/doc/SkDocument_PDF.cpp

Issue 1771073002: SkPDF: s/SkAutoTUnref/sk_sp/g (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pdf/SkPDFBitmap.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 SkPDFSubstituteMap* substituteMap) { 55 SkPDFSubstituteMap* substituteMap) {
56 SkASSERT(substituteMap); 56 SkASSERT(substituteMap);
57 57
58 SkPDFGlyphSetMap usage; 58 SkPDFGlyphSetMap usage;
59 for (int i = 0; i < pageDevices.count(); ++i) { 59 for (int i = 0; i < pageDevices.count(); ++i) {
60 usage.merge(pageDevices[i]->getFontGlyphUsage()); 60 usage.merge(pageDevices[i]->getFontGlyphUsage());
61 } 61 }
62 SkPDFGlyphSetMap::F2BIter iterator(usage); 62 SkPDFGlyphSetMap::F2BIter iterator(usage);
63 const SkPDFGlyphSetMap::FontGlyphSetPair* entry = iterator.next(); 63 const SkPDFGlyphSetMap::FontGlyphSetPair* entry = iterator.next();
64 while (entry) { 64 while (entry) {
65 SkAutoTUnref<SkPDFFont> subsetFont( 65 sk_sp<SkPDFFont> subsetFont(
66 entry->fFont->getFontSubset(entry->fGlyphSet)); 66 entry->fFont->getFontSubset(entry->fGlyphSet));
67 if (subsetFont) { 67 if (subsetFont) {
68 substituteMap->setSubstitute(entry->fFont, subsetFont.get()); 68 substituteMap->setSubstitute(entry->fFont, subsetFont.get());
69 } 69 }
70 entry = iterator.next(); 70 entry = iterator.next();
71 } 71 }
72 } 72 }
73 73
74 static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) { 74 static SkPDFObject* create_pdf_page_content(const SkPDFDevice* pageDevice) {
75 SkAutoTDelete<SkStreamAsset> content(pageDevice->content()); 75 SkAutoTDelete<SkStreamAsset> content(pageDevice->content());
76 return new SkPDFStream(content.get()); 76 return new SkPDFStream(content.get());
77 } 77 }
78 78
79 static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) { 79 static SkPDFDict* create_pdf_page(const SkPDFDevice* pageDevice) {
80 SkAutoTUnref<SkPDFDict> page(new SkPDFDict("Page")); 80 sk_sp<SkPDFDict> page(new SkPDFDict("Page"));
81 page->insertObject("Resources", pageDevice->createResourceDict()); 81 page->insertObject("Resources", pageDevice->createResourceDict());
82 page->insertObject("MediaBox", pageDevice->copyMediaBox()); 82 page->insertObject("MediaBox", pageDevice->copyMediaBox());
83 SkAutoTUnref<SkPDFArray> annotations(new SkPDFArray); 83 sk_sp<SkPDFArray> annotations(new SkPDFArray);
84 pageDevice->appendAnnotations(annotations.get()); 84 pageDevice->appendAnnotations(annotations.get());
85 if (annotations->size() > 0) { 85 if (annotations->size() > 0) {
86 page->insertObject("Annots", annotations.release()); 86 page->insertObject("Annots", annotations.release());
87 } 87 }
88 page->insertObjRef("Contents", create_pdf_page_content(pageDevice)); 88 page->insertObjRef("Contents", create_pdf_page_content(pageDevice));
89 return page.release(); 89 return page.release();
90 } 90 }
91 91
92 static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages, 92 static void generate_page_tree(const SkTDArray<SkPDFDict*>& pages,
93 SkTDArray<SkPDFDict*>* pageTree, 93 SkTDArray<SkPDFDict*>* pageTree,
(...skipping 20 matching lines...) Expand all
114 nextRoundNodes.setReserve((pages.count() + kNodeSize - 1)/kNodeSize); 114 nextRoundNodes.setReserve((pages.count() + kNodeSize - 1)/kNodeSize);
115 115
116 int treeCapacity = kNodeSize; 116 int treeCapacity = kNodeSize;
117 do { 117 do {
118 for (int i = 0; i < curNodes.count(); ) { 118 for (int i = 0; i < curNodes.count(); ) {
119 if (i > 0 && i + 1 == curNodes.count()) { 119 if (i > 0 && i + 1 == curNodes.count()) {
120 nextRoundNodes.push(curNodes[i]); 120 nextRoundNodes.push(curNodes[i]);
121 break; 121 break;
122 } 122 }
123 123
124 SkAutoTUnref<SkPDFDict> newNode(new SkPDFDict("Pages")); 124 sk_sp<SkPDFDict> newNode(new SkPDFDict("Pages"));
125 SkAutoTUnref<SkPDFArray> kids(new SkPDFArray); 125 sk_sp<SkPDFArray> kids(new SkPDFArray);
126 kids->reserve(kNodeSize); 126 kids->reserve(kNodeSize);
127 127
128 int count = 0; 128 int count = 0;
129 for (; i < curNodes.count() && count < kNodeSize; i++, count++) { 129 for (; i < curNodes.count() && count < kNodeSize; i++, count++) {
130 curNodes[i]->insertObjRef("Parent", SkRef(newNode.get())); 130 curNodes[i]->insertObjRef("Parent", SkRef(newNode.get()));
131 kids->appendObjRef(SkRef(curNodes[i])); 131 kids->appendObjRef(SkRef(curNodes[i]));
132 132
133 // TODO(vandebo): put the objects in strict access order. 133 // TODO(vandebo): put the objects in strict access order.
134 // Probably doesn't matter because they are so small. 134 // Probably doesn't matter because they are so small.
135 if (curNodes[i] != pages[0]) { 135 if (curNodes[i] != pages[0]) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 168
169 static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices, 169 static bool emit_pdf_document(const SkTDArray<const SkPDFDevice*>& pageDevices,
170 const SkPDFMetadata& metadata, 170 const SkPDFMetadata& metadata,
171 SkWStream* stream) { 171 SkWStream* stream) {
172 if (pageDevices.isEmpty()) { 172 if (pageDevices.isEmpty()) {
173 return false; 173 return false;
174 } 174 }
175 175
176 SkTDArray<SkPDFDict*> pages; 176 SkTDArray<SkPDFDict*> pages;
177 SkAutoTUnref<SkPDFDict> dests(new SkPDFDict); 177 sk_sp<SkPDFDict> dests(new SkPDFDict);
178 178
179 for (int i = 0; i < pageDevices.count(); i++) { 179 for (int i = 0; i < pageDevices.count(); i++) {
180 SkASSERT(pageDevices[i]); 180 SkASSERT(pageDevices[i]);
181 SkASSERT(i == 0 || 181 SkASSERT(i == 0 ||
182 pageDevices[i - 1]->getCanon() == pageDevices[i]->getCanon()); 182 pageDevices[i - 1]->getCanon() == pageDevices[i]->getCanon());
183 SkAutoTUnref<SkPDFDict> page(create_pdf_page(pageDevices[i])); 183 sk_sp<SkPDFDict> page(create_pdf_page(pageDevices[i]));
184 pageDevices[i]->appendDestinations(dests.get(), page.get()); 184 pageDevices[i]->appendDestinations(dests.get(), page.get());
185 pages.push(page.release()); 185 pages.push(page.release());
186 } 186 }
187 187
188 SkAutoTUnref<SkPDFDict> docCatalog(new SkPDFDict("Catalog")); 188 sk_sp<SkPDFDict> docCatalog(new SkPDFDict("Catalog"));
189 189
190 SkAutoTUnref<SkPDFObject> infoDict( 190 sk_sp<SkPDFObject> infoDict(
191 metadata.createDocumentInformationDict()); 191 metadata.createDocumentInformationDict());
192 192
193 SkAutoTUnref<SkPDFObject> id, xmp; 193 sk_sp<SkPDFObject> id, xmp;
194 #ifdef SK_PDF_GENERATE_PDFA 194 #ifdef SK_PDF_GENERATE_PDFA
195 SkPDFMetadata::UUID uuid = metadata.uuid(); 195 SkPDFMetadata::UUID uuid = metadata.uuid();
196 // We use the same UUID for Document ID and Instance ID since this 196 // We use the same UUID for Document ID and Instance ID since this
197 // is the first revision of this document (and Skia does not 197 // is the first revision of this document (and Skia does not
198 // support revising existing PDF documents). 198 // support revising existing PDF documents).
199 // If we are not in PDF/A mode, don't use a UUID since testing 199 // If we are not in PDF/A mode, don't use a UUID since testing
200 // works best with reproducible outputs. 200 // works best with reproducible outputs.
201 id.reset(SkPDFMetadata::CreatePdfId(uuid, uuid)); 201 id.reset(SkPDFMetadata::CreatePdfId(uuid, uuid));
202 xmp.reset(metadata.createXMPObject(uuid, uuid)); 202 xmp.reset(metadata.createXMPObject(uuid, uuid));
203 docCatalog->insertObjRef("Metadata", xmp.release()); 203 docCatalog->insertObjRef("Metadata", xmp.release());
204 204
205 // sRGB is specified by HTML, CSS, and SVG. 205 // sRGB is specified by HTML, CSS, and SVG.
206 SkAutoTUnref<SkPDFDict> outputIntent(new SkPDFDict("OutputIntent")); 206 sk_sp<SkPDFDict> outputIntent(new SkPDFDict("OutputIntent"));
207 outputIntent->insertName("S", "GTS_PDFA1"); 207 outputIntent->insertName("S", "GTS_PDFA1");
208 outputIntent->insertString("RegistryName", "http://www.color.org"); 208 outputIntent->insertString("RegistryName", "http://www.color.org");
209 outputIntent->insertString("OutputConditionIdentifier", 209 outputIntent->insertString("OutputConditionIdentifier",
210 "sRGB IEC61966-2.1"); 210 "sRGB IEC61966-2.1");
211 SkAutoTUnref<SkPDFArray> intentArray(new SkPDFArray); 211 sk_sp<SkPDFArray> intentArray(new SkPDFArray);
212 intentArray->appendObject(outputIntent.release()); 212 intentArray->appendObject(outputIntent.release());
213 // Don't specify OutputIntents if we are not in PDF/A mode since 213 // Don't specify OutputIntents if we are not in PDF/A mode since
214 // no one has ever asked for this feature. 214 // no one has ever asked for this feature.
215 docCatalog->insertObject("OutputIntents", intentArray.release()); 215 docCatalog->insertObject("OutputIntents", intentArray.release());
216 #endif 216 #endif
217 217
218 SkTDArray<SkPDFDict*> pageTree; 218 SkTDArray<SkPDFDict*> pageTree;
219 SkPDFDict* pageTreeRoot; 219 SkPDFDict* pageTreeRoot;
220 generate_page_tree(pages, &pageTree, &pageTreeRoot); 220 generate_page_tree(pages, &pageTree, &pageTreeRoot);
221 docCatalog->insertObjRef("Pages", SkRef(pageTreeRoot)); 221 docCatalog->insertObjRef("Pages", SkRef(pageTreeRoot));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 this->close(); 334 this->close();
335 } 335 }
336 336
337 protected: 337 protected:
338 SkCanvas* onBeginPage(SkScalar width, SkScalar height, 338 SkCanvas* onBeginPage(SkScalar width, SkScalar height,
339 const SkRect& trimBox) override { 339 const SkRect& trimBox) override {
340 SkASSERT(!fCanvas.get()); 340 SkASSERT(!fCanvas.get());
341 341
342 SkISize pageSize = SkISize::Make( 342 SkISize pageSize = SkISize::Make(
343 SkScalarRoundToInt(width), SkScalarRoundToInt(height)); 343 SkScalarRoundToInt(width), SkScalarRoundToInt(height));
344 SkAutoTUnref<SkPDFDevice> device( 344 sk_sp<SkPDFDevice> device(
345 SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon)); 345 SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon));
346 fCanvas.reset(new SkCanvas(device.get())); 346 fCanvas.reset(new SkCanvas(device.get()));
347 fPageDevices.push(device.release()); 347 fPageDevices.push(device.release());
348 fCanvas->clipRect(trimBox); 348 fCanvas->clipRect(trimBox);
349 fCanvas->translate(trimBox.x(), trimBox.y()); 349 fCanvas->translate(trimBox.x(), trimBox.y());
350 return fCanvas.get(); 350 return fCanvas.get();
351 } 351 }
352 352
353 void onEndPage() override { 353 void onEndPage() override {
354 SkASSERT(fCanvas.get()); 354 SkASSERT(fCanvas.get());
(...skipping 20 matching lines...) Expand all
375 const SkTime::DateTime* creationDate, 375 const SkTime::DateTime* creationDate,
376 const SkTime::DateTime* modifiedDate) override { 376 const SkTime::DateTime* modifiedDate) override {
377 fMetadata.fInfo.reset(info, infoCount); 377 fMetadata.fInfo.reset(info, infoCount);
378 fMetadata.fCreation.reset(clone(creationDate)); 378 fMetadata.fCreation.reset(clone(creationDate));
379 fMetadata.fModified.reset(clone(modifiedDate)); 379 fMetadata.fModified.reset(clone(modifiedDate));
380 } 380 }
381 381
382 private: 382 private:
383 SkPDFCanon fCanon; 383 SkPDFCanon fCanon;
384 SkTDArray<const SkPDFDevice*> fPageDevices; 384 SkTDArray<const SkPDFDevice*> fPageDevices;
385 SkAutoTUnref<SkCanvas> fCanvas; 385 sk_sp<SkCanvas> fCanvas;
386 SkScalar fRasterDpi; 386 SkScalar fRasterDpi;
387 SkPDFMetadata fMetadata; 387 SkPDFMetadata fMetadata;
388 }; 388 };
389 } // namespace 389 } // namespace
390 /////////////////////////////////////////////////////////////////////////////// 390 ///////////////////////////////////////////////////////////////////////////////
391 391
392 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { 392 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) {
393 return stream ? new SkDocument_PDF(stream, nullptr, dpi, nullptr) : nullptr; 393 return stream ? new SkDocument_PDF(stream, nullptr, dpi, nullptr) : nullptr;
394 } 394 }
395 395
396 SkDocument* SkDocument::CreatePDF(SkWStream* stream, 396 SkDocument* SkDocument::CreatePDF(SkWStream* stream,
397 SkScalar dpi, 397 SkScalar dpi,
398 SkPixelSerializer* jpegEncoder) { 398 SkPixelSerializer* jpegEncoder) {
399 return stream 399 return stream
400 ? new SkDocument_PDF(stream, nullptr, dpi, jpegEncoder) 400 ? new SkDocument_PDF(stream, nullptr, dpi, jpegEncoder)
401 : nullptr; 401 : nullptr;
402 } 402 }
403 403
404 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { 404 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) {
405 SkFILEWStream* stream = new SkFILEWStream(path); 405 SkFILEWStream* stream = new SkFILEWStream(path);
406 if (!stream->isValid()) { 406 if (!stream->isValid()) {
407 delete stream; 407 delete stream;
408 return nullptr; 408 return nullptr;
409 } 409 }
410 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; 410 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; };
411 return new SkDocument_PDF(stream, delete_wstream, dpi, nullptr); 411 return new SkDocument_PDF(stream, delete_wstream, dpi, nullptr);
412 } 412 }
OLDNEW
« no previous file with comments | « no previous file | src/pdf/SkPDFBitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698