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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 fCanvas.reset(new SkCanvas(device.get())); | 311 fCanvas.reset(new SkCanvas(device.get())); |
312 fPageDevices.push(device.detach()); | 312 fPageDevices.push(device.detach()); |
313 fCanvas->clipRect(trimBox); | 313 fCanvas->clipRect(trimBox); |
314 fCanvas->translate(trimBox.x(), trimBox.y()); | 314 fCanvas->translate(trimBox.x(), trimBox.y()); |
315 return fCanvas.get(); | 315 return fCanvas.get(); |
316 } | 316 } |
317 | 317 |
318 void onEndPage() override { | 318 void onEndPage() override { |
319 SkASSERT(fCanvas.get()); | 319 SkASSERT(fCanvas.get()); |
320 fCanvas->flush(); | 320 fCanvas->flush(); |
321 fCanvas.reset(NULL); | 321 fCanvas.reset(nullptr); |
322 } | 322 } |
323 | 323 |
324 bool onClose(SkWStream* stream) override { | 324 bool onClose(SkWStream* stream) override { |
325 SkASSERT(!fCanvas.get()); | 325 SkASSERT(!fCanvas.get()); |
326 | 326 |
327 bool success = emit_pdf_document(fPageDevices, stream); | 327 bool success = emit_pdf_document(fPageDevices, stream); |
328 fPageDevices.unrefAll(); | 328 fPageDevices.unrefAll(); |
329 fCanon.reset(); | 329 fCanon.reset(); |
330 return success; | 330 return success; |
331 } | 331 } |
332 | 332 |
333 void onAbort() override { | 333 void onAbort() override { |
334 fPageDevices.unrefAll(); | 334 fPageDevices.unrefAll(); |
335 fCanon.reset(); | 335 fCanon.reset(); |
336 } | 336 } |
337 | 337 |
338 private: | 338 private: |
339 SkPDFCanon fCanon; | 339 SkPDFCanon fCanon; |
340 SkTDArray<const SkPDFDevice*> fPageDevices; | 340 SkTDArray<const SkPDFDevice*> fPageDevices; |
341 SkAutoTUnref<SkCanvas> fCanvas; | 341 SkAutoTUnref<SkCanvas> fCanvas; |
342 SkScalar fRasterDpi; | 342 SkScalar fRasterDpi; |
343 }; | 343 }; |
344 } // namespace | 344 } // namespace |
345 /////////////////////////////////////////////////////////////////////////////// | 345 /////////////////////////////////////////////////////////////////////////////// |
346 | 346 |
347 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { | 347 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { |
348 return stream ? new SkDocument_PDF(stream, NULL, dpi) : NULL; | 348 return stream ? new SkDocument_PDF(stream, nullptr, dpi) : nullptr; |
349 } | 349 } |
350 | 350 |
351 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 351 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
352 SkFILEWStream* stream = new SkFILEWStream(path); | 352 SkFILEWStream* stream = new SkFILEWStream(path); |
353 if (!stream->isValid()) { | 353 if (!stream->isValid()) { |
354 delete stream; | 354 delete stream; |
355 return NULL; | 355 return nullptr; |
356 } | 356 } |
357 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 357 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
358 return new SkDocument_PDF(stream, delete_wstream, dpi); | 358 return new SkDocument_PDF(stream, delete_wstream, dpi); |
359 } | 359 } |
OLD | NEW |