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

Side by Side Diff: src/doc/SkDocument_PDF.cpp

Issue 16660002: SkDocument base for pdf, xps, etc. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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
(Empty)
1 /*
2 * Copyright 2013 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 "SkDocument.h"
9 #include "SkPDFDocument.h"
10 #include "SkPDFDevice.h"
11
12 class SkDocument_PDF : public SkDocument {
13 public:
14 SkDocument_PDF(SkWStream* stream) : SkDocument(stream) {
15 fDoc = new SkPDFDocument;
16 fCanvas = NULL;
17 fDevice = NULL;
18 }
19
20 virtual ~SkDocument_PDF() {
21 this->close();
22 delete fDoc;
23 }
24
25 protected:
26 virtual SkCanvas* onBeginPage(SkScalar width, SkScalar height,
27 const SkRect& content) SK_OVERRIDE {
28 SkISize pageS, contentS;
29 SkMatrix matrix;
30
31 pageS.set(SkScalarRoundToInt(width), SkScalarRoundToInt(height));
32 contentS.set(SkScalarRoundToInt(content.width()),
33 SkScalarRoundToInt(content.height()));
34 matrix.setTranslate(content.fLeft, content.fTop);
35
36 fDevice = new SkPDFDevice(pageS, contentS, matrix);
37 fCanvas = new SkCanvas(fDevice);
38 return fCanvas;
39 }
40
41 virtual void onEndPage() SK_OVERRIDE {
42 if (fCanvas) {
43 fCanvas->flush();
44 fDoc->appendPage(fDevice);
45
46 fCanvas->unref();
47 fDevice->unref();
48
49 fCanvas = NULL;
50 fDevice = NULL;
51 }
52 }
53
54 virtual void onClose(SkWStream* stream) SK_OVERRIDE {
55 fDoc->emitPDF(stream);
56
57 delete fDoc;
58 SkSafeUnref(fCanvas);
59 SkSafeUnref(fDevice);
60
61 fDoc = NULL;
62 fCanvas = NULL;
63 fDevice = NULL;
64 }
65
66 private:
67 SkPDFDocument* fDoc;
68 SkPDFDevice* fDevice;
69 SkCanvas* fCanvas;
70 };
71
72 ///////////////////////////////////////////////////////////////////////////////
73
74 SkDocument* SkDocument::CreatePDF(SkWStream* stream) {
75 return stream ? SkNEW_ARGS(SkDocument_PDF, (stream)) : NULL;
76 }
77
78 SkDocument* SkDocument::CreatePDF(const char path[]) {
79 SkFILEWStream* stream = SkNEW_ARGS(SkFILEWStream, (path));
80 if (!stream->isValid()) {
81 SkDELETE(stream);
82 return NULL;
83 }
84 return SkNEW_ARGS(SkDocument_PDF, (stream));
85 }
86
OLDNEW
« include/core/SkDocument.h ('K') | « src/doc/SkDocument.cpp ('k') | tools/skhello.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698