| 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 "SkPDFCatalog.h" | 10 #include "SkPDFCatalog.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 : SkDocument(stream, doneProc) | 302 : SkDocument(stream, doneProc) |
| 303 , fRasterDpi(rasterDpi) {} | 303 , fRasterDpi(rasterDpi) {} |
| 304 | 304 |
| 305 virtual ~SkDocument_PDF() { | 305 virtual ~SkDocument_PDF() { |
| 306 // subclasses must call close() in their destructors | 306 // subclasses must call close() in their destructors |
| 307 this->close(); | 307 this->close(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 protected: | 310 protected: |
| 311 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, | 311 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height, |
| 312 const SkRect& trimBox) SK_OVERRIDE { | 312 const SkRect& trimBox) override { |
| 313 SkASSERT(!fCanvas.get()); | 313 SkASSERT(!fCanvas.get()); |
| 314 | 314 |
| 315 SkISize pageSize = SkISize::Make( | 315 SkISize pageSize = SkISize::Make( |
| 316 SkScalarRoundToInt(width), SkScalarRoundToInt(height)); | 316 SkScalarRoundToInt(width), SkScalarRoundToInt(height)); |
| 317 SkAutoTUnref<SkPDFDevice> device( | 317 SkAutoTUnref<SkPDFDevice> device( |
| 318 SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon)); | 318 SkPDFDevice::Create(pageSize, fRasterDpi, &fCanon)); |
| 319 fCanvas.reset(SkNEW_ARGS(SkCanvas, (device.get()))); | 319 fCanvas.reset(SkNEW_ARGS(SkCanvas, (device.get()))); |
| 320 fPageDevices.push(device.detach()); | 320 fPageDevices.push(device.detach()); |
| 321 fCanvas->clipRect(trimBox); | 321 fCanvas->clipRect(trimBox); |
| 322 fCanvas->translate(trimBox.x(), trimBox.y()); | 322 fCanvas->translate(trimBox.x(), trimBox.y()); |
| 323 return fCanvas.get(); | 323 return fCanvas.get(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void onEndPage() SK_OVERRIDE { | 326 void onEndPage() override { |
| 327 SkASSERT(fCanvas.get()); | 327 SkASSERT(fCanvas.get()); |
| 328 fCanvas->flush(); | 328 fCanvas->flush(); |
| 329 fCanvas.reset(NULL); | 329 fCanvas.reset(NULL); |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool onClose(SkWStream* stream) SK_OVERRIDE { | 332 bool onClose(SkWStream* stream) override { |
| 333 SkASSERT(!fCanvas.get()); | 333 SkASSERT(!fCanvas.get()); |
| 334 | 334 |
| 335 bool success = emit_pdf_document(fPageDevices, stream); | 335 bool success = emit_pdf_document(fPageDevices, stream); |
| 336 fPageDevices.unrefAll(); | 336 fPageDevices.unrefAll(); |
| 337 fCanon.reset(); | 337 fCanon.reset(); |
| 338 return success; | 338 return success; |
| 339 } | 339 } |
| 340 | 340 |
| 341 void onAbort() SK_OVERRIDE { | 341 void onAbort() override { |
| 342 fPageDevices.unrefAll(); | 342 fPageDevices.unrefAll(); |
| 343 fCanon.reset(); | 343 fCanon.reset(); |
| 344 } | 344 } |
| 345 | 345 |
| 346 private: | 346 private: |
| 347 SkPDFCanon fCanon; | 347 SkPDFCanon fCanon; |
| 348 SkTDArray<const SkPDFDevice*> fPageDevices; | 348 SkTDArray<const SkPDFDevice*> fPageDevices; |
| 349 SkAutoTUnref<SkCanvas> fCanvas; | 349 SkAutoTUnref<SkCanvas> fCanvas; |
| 350 SkScalar fRasterDpi; | 350 SkScalar fRasterDpi; |
| 351 }; | 351 }; |
| 352 } // namespace | 352 } // namespace |
| 353 /////////////////////////////////////////////////////////////////////////////// | 353 /////////////////////////////////////////////////////////////////////////////// |
| 354 | 354 |
| 355 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { | 355 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { |
| 356 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, NULL, dpi)) : NULL; | 356 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream, NULL, dpi)) : NULL; |
| 357 } | 357 } |
| 358 | 358 |
| 359 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 359 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
| 360 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); | 360 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path)); |
| 361 if (!stream->isValid()) { | 361 if (!stream->isValid()) { |
| 362 SkDELETE(stream); | 362 SkDELETE(stream); |
| 363 return NULL; | 363 return NULL; |
| 364 } | 364 } |
| 365 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; | 365 auto delete_wstream = [](SkWStream* stream, bool) { SkDELETE(stream); }; |
| 366 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); | 366 return SkNEW_ARGS(SkDocument_PDF, (stream, delete_wstream, dpi)); |
| 367 } | 367 } |
| OLD | NEW |