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

Side by Side Diff: tools/PdfRenderer.cpp

Issue 463603002: clean up render_pdfs: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 4 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
« no previous file with comments | « tools/PdfRenderer.h ('k') | tools/render_pdfs_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "PdfRenderer.h"
9 #include "SkCanvas.h"
10 #include "SkDevice.h"
11 #include "SkPDFDevice.h"
12 #include "SkPDFDocument.h"
13
14 namespace sk_tools {
15
16 void PdfRenderer::init(SkPicture* pict, SkWStream* stream) {
17 SkASSERT(NULL == fPicture);
18 SkASSERT(NULL == fCanvas.get());
19 if (fPicture != NULL || NULL != fCanvas.get()) {
20 return;
21 }
22
23 SkASSERT(pict != NULL);
24 if (NULL == pict) {
25 return;
26 }
27
28 fPicture = pict;
29 fCanvas.reset(this->setupCanvas(stream, pict->width(), pict->height()));
30 }
31
32 SkCanvas* PdfRenderer::setupCanvas(SkWStream* stream, int width, int height) {
33 fPdfDoc.reset(SkDocument::CreatePDF(stream, NULL, fEncoder));
34
35 SkCanvas* canvas = fPdfDoc->beginPage(SkIntToScalar(width), SkIntToScalar(he ight));
36 canvas->ref();
37
38 return canvas;
39 }
40
41 void PdfRenderer::end() {
42 fPicture = NULL;
43 fCanvas.reset(NULL);
44 fPdfDoc.reset(NULL);
45 }
46
47 bool SimplePdfRenderer::render() {
48 SkASSERT(fCanvas.get() != NULL);
49 SkASSERT(fPicture != NULL);
50 if (NULL == fCanvas.get() || NULL == fPicture) {
51 return false;
52 }
53
54 fCanvas->drawPicture(fPicture);
55 fCanvas->flush();
56
57 return fPdfDoc->close();
58 }
59
60 }
OLDNEW
« no previous file with comments | « tools/PdfRenderer.h ('k') | tools/render_pdfs_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698