Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/PdfRenderer.cpp

Issue 24811002: Update the SkDocument interface to allow for 1) abort won't emit pdf, 2) close can report success/f… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "PdfRenderer.h" 8 #include "PdfRenderer.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
11 #include "SkPDFDevice.h" 11 #include "SkPDFDevice.h"
12 #include "SkPDFDocument.h" 12 #include "SkPDFDocument.h"
13 13
14 namespace sk_tools { 14 namespace sk_tools {
15 15
16 void PdfRenderer::init(SkPicture* pict) { 16 void PdfRenderer::init(SkPicture* pict, SkWStream* stream) {
17 SkASSERT(NULL == fPicture); 17 SkASSERT(NULL == fPicture);
18 SkASSERT(NULL == fCanvas.get()); 18 SkASSERT(NULL == fCanvas.get());
19 if (fPicture != NULL || NULL != fCanvas.get()) { 19 if (fPicture != NULL || NULL != fCanvas.get()) {
20 return; 20 return;
21 } 21 }
22 22
23 SkASSERT(pict != NULL); 23 SkASSERT(pict != NULL);
24 if (NULL == pict) { 24 if (NULL == pict) {
25 return; 25 return;
26 } 26 }
27 27
28 fPicture = pict; 28 fPicture = pict;
29 fCanvas.reset(this->setupCanvas()); 29 fCanvas.reset(this->setupCanvas(stream, pict->width(), pict->height()));
30 } 30 }
31 31
32 SkCanvas* PdfRenderer::setupCanvas() { 32 SkCanvas* PdfRenderer::setupCanvas(SkWStream* stream, int width, int height) {
33 return this->setupCanvas(fPicture->width(), fPicture->height()); 33 fPdfDoc.reset(SkDocument::CreatePDF(stream, NULL, fEncoder));
34 }
35 34
36 SkCanvas* PdfRenderer::setupCanvas(int width, int height) { 35 SkSize pageSize = SkSize::Make(SkIntToScalar(width), SkIntToScalar(height));
37 SkISize pageSize = SkISize::Make(width, height); 36 SkCanvas* canvas = fPdfDoc->beginPage(pageSize);
38 fPDFDevice = SkNEW_ARGS(SkPDFDevice, (pageSize, pageSize, SkMatrix::I())); 37 canvas->ref();
39 fPDFDevice->setDCTEncoder(fEncoder); 38
40 return SkNEW_ARGS(SkCanvas, (fPDFDevice)); 39 return canvas;
41 } 40 }
42 41
43 void PdfRenderer::end() { 42 void PdfRenderer::end() {
44 fPicture = NULL; 43 fPicture = NULL;
45 fCanvas.reset(NULL); 44 fCanvas.reset(NULL);
46 if (fPDFDevice) { 45 fPdfDoc.reset(NULL);
47 SkDELETE(fPDFDevice);
48 fPDFDevice = NULL;
49 }
50 } 46 }
51 47
52 void PdfRenderer::write(SkWStream* stream) const { 48 bool SimplePdfRenderer::render() {
53 SkPDFDocument doc;
54 doc.appendPage(fPDFDevice);
55 doc.emitPDF(stream);
56 }
57
58 void SimplePdfRenderer::render() {
59 SkASSERT(fCanvas.get() != NULL); 49 SkASSERT(fCanvas.get() != NULL);
60 SkASSERT(fPicture != NULL); 50 SkASSERT(fPicture != NULL);
61 if (NULL == fCanvas.get() || NULL == fPicture) { 51 if (NULL == fCanvas.get() || NULL == fPicture) {
62 return; 52 return false;
63 } 53 }
64 54
65 fCanvas->drawPicture(*fPicture); 55 fCanvas->drawPicture(*fPicture);
66 fCanvas->flush(); 56 fCanvas->flush();
57
58 // TODO(edisonn): SkDocument should report failure somehow!
vandebo (ex-Chrome) 2013/09/27 15:50:17 Didn't you change close to return a bool, or does
edisonn 2013/10/04 19:40:37 Done.
59 fPdfDoc->close();
60 return true;
67 } 61 }
68 62
69 } 63 }
OLDNEW
« src/pdf/SkPDFShader.cpp ('K') | « tools/PdfRenderer.h ('k') | tools/render_pdfs_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698