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