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 "SkMakeUnique.h" |
8 #include "SkPDFCanon.h" | 9 #include "SkPDFCanon.h" |
9 #include "SkPDFCanvas.h" | 10 #include "SkPDFCanvas.h" |
10 #include "SkPDFDevice.h" | 11 #include "SkPDFDevice.h" |
11 #include "SkPDFDocument.h" | 12 #include "SkPDFDocument.h" |
12 #include "SkPDFUtils.h" | 13 #include "SkPDFUtils.h" |
13 #include "SkStream.h" | 14 #include "SkStream.h" |
14 | 15 |
15 SkPDFObjectSerializer::SkPDFObjectSerializer() : fBaseOffset(0), fNextToBeSerial
ized(0) {} | 16 SkPDFObjectSerializer::SkPDFObjectSerializer() : fBaseOffset(0), fNextToBeSerial
ized(0) {} |
16 | 17 |
17 template <class T> static void renew(T* t) { t->~T(); new (t) T; } | 18 template <class T> static void renew(T* t) { t->~T(); new (t) T; } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 161 } |
161 SkDEBUGCODE( for (const auto& n : curNodes) { SkASSERT(!n); } ); | 162 SkDEBUGCODE( for (const auto& n : curNodes) { SkASSERT(!n); } ); |
162 | 163 |
163 curNodes.swap(&nextRoundNodes); | 164 curNodes.swap(&nextRoundNodes); |
164 nextRoundNodes.reset(); | 165 nextRoundNodes.reset(); |
165 treeCapacity *= kNodeSize; | 166 treeCapacity *= kNodeSize; |
166 } while (curNodes.count() > 1); | 167 } while (curNodes.count() > 1); |
167 return std::move(curNodes[0]); | 168 return std::move(curNodes[0]); |
168 } | 169 } |
169 | 170 |
170 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } | |
171 //////////////////////////////////////////////////////////////////////////////// | 171 //////////////////////////////////////////////////////////////////////////////// |
172 | 172 |
173 SkPDFDocument::SkPDFDocument(SkWStream* stream, | 173 SkPDFDocument::SkPDFDocument(SkWStream* stream, |
174 void (*doneProc)(SkWStream*, bool), | 174 void (*doneProc)(SkWStream*, bool), |
175 SkScalar rasterDpi, | 175 SkScalar rasterDpi, |
176 const SkDocument::PDFMetadata& metadata, | 176 const SkDocument::PDFMetadata& metadata, |
177 sk_sp<SkPixelSerializer> jpegEncoder, | 177 sk_sp<SkPixelSerializer> jpegEncoder, |
178 bool pdfa) | 178 bool pdfa) |
179 : SkDocument(stream, doneProc) | 179 : SkDocument(stream, doneProc) |
180 , fRasterDpi(rasterDpi) | 180 , fRasterDpi(rasterDpi) |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 const SkDocument::PDFMetadata& metadata, | 459 const SkDocument::PDFMetadata& metadata, |
460 sk_sp<SkPixelSerializer> jpeg, | 460 sk_sp<SkPixelSerializer> jpeg, |
461 bool pdfa) { | 461 bool pdfa) { |
462 return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, metadata, | 462 return stream ? sk_make_sp<SkPDFDocument>(stream, proc, dpi, metadata, |
463 std::move(jpeg), pdfa) | 463 std::move(jpeg), pdfa) |
464 : nullptr; | 464 : nullptr; |
465 } | 465 } |
466 | 466 |
467 sk_sp<SkDocument> SkDocument::MakePDF(const char path[], SkScalar dpi) { | 467 sk_sp<SkDocument> SkDocument::MakePDF(const char path[], SkScalar dpi) { |
468 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 468 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
469 std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path)); | 469 auto stream = skstd::make_unique<SkFILEWStream>(path); |
470 return stream->isValid() | 470 return stream->isValid() |
471 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, | 471 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, |
472 SkDocument::PDFMetadata(), nullptr, | 472 SkDocument::PDFMetadata(), nullptr, |
473 false) | 473 false) |
474 : nullptr; | 474 : nullptr; |
475 } | 475 } |
476 | 476 |
477 sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, | 477 sk_sp<SkDocument> SkDocument::MakePDF(SkWStream* stream, |
478 SkScalar dpi, | 478 SkScalar dpi, |
479 const SkDocument::PDFMetadata& metadata, | 479 const SkDocument::PDFMetadata& metadata, |
480 sk_sp<SkPixelSerializer> jpegEncoder, | 480 sk_sp<SkPixelSerializer> jpegEncoder, |
481 bool pdfa) { | 481 bool pdfa) { |
482 return SkPDFMakeDocument(stream, nullptr, dpi, metadata, | 482 return SkPDFMakeDocument(stream, nullptr, dpi, metadata, |
483 std::move(jpegEncoder), pdfa); | 483 std::move(jpegEncoder), pdfa); |
484 } | 484 } |
OLD | NEW |