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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 #endif | 315 #endif |
316 | 316 |
317 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } | 317 template <typename T> static T* clone(const T* o) { return o ? new T(*o) : nullp
tr; } |
318 //////////////////////////////////////////////////////////////////////////////// | 318 //////////////////////////////////////////////////////////////////////////////// |
319 | 319 |
320 namespace { | 320 namespace { |
321 class SkDocument_PDF : public SkDocument { | 321 class SkDocument_PDF : public SkDocument { |
322 public: | 322 public: |
323 SkDocument_PDF(SkWStream* stream, | 323 SkDocument_PDF(SkWStream* stream, |
324 void (*doneProc)(SkWStream*, bool), | 324 void (*doneProc)(SkWStream*, bool), |
325 SkScalar rasterDpi) | 325 SkScalar rasterDpi, |
| 326 SkPixelSerializer* jpegEncoder) |
326 : SkDocument(stream, doneProc) | 327 : SkDocument(stream, doneProc) |
327 , fRasterDpi(rasterDpi) {} | 328 , fRasterDpi(rasterDpi) { |
| 329 fCanon.fPixelSerializer.reset(SkSafeRef(jpegEncoder)); |
| 330 } |
328 | 331 |
329 virtual ~SkDocument_PDF() { | 332 virtual ~SkDocument_PDF() { |
330 // subclasses must call close() in their destructors | 333 // subclasses must call close() in their destructors |
331 this->close(); | 334 this->close(); |
332 } | 335 } |
333 | 336 |
334 protected: | 337 protected: |
335 SkCanvas* onBeginPage(SkScalar width, SkScalar height, | 338 SkCanvas* onBeginPage(SkScalar width, SkScalar height, |
336 const SkRect& trimBox) override { | 339 const SkRect& trimBox) override { |
337 SkASSERT(!fCanvas.get()); | 340 SkASSERT(!fCanvas.get()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 SkPDFCanon fCanon; | 382 SkPDFCanon fCanon; |
380 SkTDArray<const SkPDFDevice*> fPageDevices; | 383 SkTDArray<const SkPDFDevice*> fPageDevices; |
381 SkAutoTUnref<SkCanvas> fCanvas; | 384 SkAutoTUnref<SkCanvas> fCanvas; |
382 SkScalar fRasterDpi; | 385 SkScalar fRasterDpi; |
383 SkPDFMetadata fMetadata; | 386 SkPDFMetadata fMetadata; |
384 }; | 387 }; |
385 } // namespace | 388 } // namespace |
386 /////////////////////////////////////////////////////////////////////////////// | 389 /////////////////////////////////////////////////////////////////////////////// |
387 | 390 |
388 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { | 391 SkDocument* SkDocument::CreatePDF(SkWStream* stream, SkScalar dpi) { |
389 return stream ? new SkDocument_PDF(stream, nullptr, dpi) : nullptr; | 392 return stream ? new SkDocument_PDF(stream, nullptr, dpi, nullptr) : nullptr; |
| 393 } |
| 394 |
| 395 SkDocument* SkDocument::CreatePDF(SkWStream* stream, |
| 396 SkScalar dpi, |
| 397 SkPixelSerializer* jpegEncoder) { |
| 398 return stream |
| 399 ? new SkDocument_PDF(stream, nullptr, dpi, jpegEncoder) |
| 400 : nullptr; |
390 } | 401 } |
391 | 402 |
392 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { | 403 SkDocument* SkDocument::CreatePDF(const char path[], SkScalar dpi) { |
393 SkFILEWStream* stream = new SkFILEWStream(path); | 404 SkFILEWStream* stream = new SkFILEWStream(path); |
394 if (!stream->isValid()) { | 405 if (!stream->isValid()) { |
395 delete stream; | 406 delete stream; |
396 return nullptr; | 407 return nullptr; |
397 } | 408 } |
398 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; | 409 auto delete_wstream = [](SkWStream* stream, bool) { delete stream; }; |
399 return new SkDocument_PDF(stream, delete_wstream, dpi); | 410 return new SkDocument_PDF(stream, delete_wstream, dpi, nullptr); |
400 } | 411 } |
OLD | NEW |