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 "SkPDFCanon.h" | 8 #include "SkPDFCanon.h" |
9 #include "SkPDFCanvas.h" | 9 #include "SkPDFCanvas.h" |
10 #include "SkPDFDevice.h" | 10 #include "SkPDFDevice.h" |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height, | 269 SkCanvas* SkPDFDocument::onBeginPage(SkScalar width, SkScalar height, |
270 const SkRect& trimBox) { | 270 const SkRect& trimBox) { |
271 SkASSERT(!fCanvas.get()); // endPage() was called before this. | 271 SkASSERT(!fCanvas.get()); // endPage() was called before this. |
272 if (fPageDevices.empty()) { | 272 if (fPageDevices.empty()) { |
273 // if this is the first page if the document. | 273 // if this is the first page if the document. |
274 fObjectSerializer.serializeHeader(this->getStream(), fMetadata); | 274 fObjectSerializer.serializeHeader(this->getStream(), fMetadata); |
275 } | 275 } |
276 SkISize pageSize = SkISize::Make( | 276 SkISize pageSize = SkISize::Make( |
277 SkScalarRoundToInt(width), SkScalarRoundToInt(height)); | 277 SkScalarRoundToInt(width), SkScalarRoundToInt(height)); |
278 sk_sp<SkPDFDevice> device( | 278 sk_sp<SkPDFDevice> device( |
279 SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon)); | 279 SkPDFDevice::Create(pageSize, fRasterDpi, this)); |
280 fCanvas = sk_make_sp<SkPDFCanvas>(device); | 280 fCanvas = sk_make_sp<SkPDFCanvas>(device); |
281 fPageDevices.push_back(std::move(device)); | 281 fPageDevices.push_back(std::move(device)); |
282 fCanvas->clipRect(trimBox); | 282 fCanvas->clipRect(trimBox); |
283 fCanvas->translate(trimBox.x(), trimBox.y()); | 283 fCanvas->translate(trimBox.x(), trimBox.y()); |
284 return fCanvas.get(); | 284 return fCanvas.get(); |
285 } | 285 } |
286 | 286 |
287 void SkPDFDocument::onEndPage() { | 287 void SkPDFDocument::onEndPage() { |
288 SkASSERT(fCanvas.get()); | 288 SkASSERT(fCanvas.get()); |
289 fCanvas->flush(); | 289 fCanvas->flush(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 return SkPDFMakeDocument(stream, nullptr, dpi, jpegEncoder).release(); | 394 return SkPDFMakeDocument(stream, nullptr, dpi, jpegEncoder).release(); |
395 } | 395 } |
396 | 396 |
397 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 397 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
398 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 398 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
399 SkAutoTDelete<SkFILEWStream> stream(new SkFILEWStream(path)); | 399 SkAutoTDelete<SkFILEWStream> stream(new SkFILEWStream(path)); |
400 return stream->isValid() | 400 return stream->isValid() |
401 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, nullptr).rele
ase() | 401 ? SkPDFMakeDocument(stream.release(), delete_wstream, dpi, nullptr).rele
ase() |
402 : nullptr; | 402 : nullptr; |
403 } | 403 } |
OLD | NEW |