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

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

Issue 963953002: XPS, DM: add SkDocument::CreateXPS (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix conics Created 5 years, 9 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
« include/core/SkDocument.h ('K') | « src/device/xps/SkXPSDevice.cpp ('k') | no next file » | 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 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 "SkXPSDevice.h"
10 #include "SkStream.h"
11
12 #ifdef SK_SUPPORT_XPS
13
14 class SkDocument_XPS : public SkDocument {
15 public:
16 SkDocument_XPS(SkWStream* stream,
17 void (*doneProc)(SkWStream*, bool),
18 SkScalar dpi)
19 : SkDocument(stream, doneProc) {
20 const SkScalar kPointsPerMeter = SkDoubleToScalar(360000.0 / 127.0);
21 fUnitsPerMeter.set(kPointsPerMeter, kPointsPerMeter);
22 SkScalar pixelsPerMeterScale = SkDoubleToScalar(dpi * 5000.0 / 127.0);
23 fPixelsPerMeter.set(pixelsPerMeterScale, pixelsPerMeterScale);
24 fDevice.beginPortfolio(stream);
25 }
26
27 virtual ~SkDocument_XPS() {
28 // subclasses must call close() in their destructors
29 this->close();
30 }
31
32 protected:
33 virtual SkCanvas* onBeginPage(SkScalar width,
34 SkScalar height,
35 const SkRect& trimBox) SK_OVERRIDE {
36 fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter,
37 SkSize::Make(width, height));
38 fCanvas.reset(SkNEW_ARGS(SkCanvas, (&fDevice)));
39 fCanvas->clipRect(trimBox);
40 fCanvas->translate(trimBox.x(), trimBox.y());
41 return fCanvas.get();
42 }
43
44 void onEndPage() SK_OVERRIDE {
45 SkASSERT(fCanvas.get());
46 fCanvas->flush();
47 fCanvas.reset(NULL);
48 fDevice.endSheet();
49 }
50
51 bool onClose(SkWStream*) SK_OVERRIDE {
52 SkASSERT(!fCanvas.get());
53 return fDevice.endPortfolio();
54 }
55
56 void onAbort() SK_OVERRIDE {}
57
58 private:
59 SkXPSDevice fDevice;
60 SkAutoTUnref<SkCanvas> fCanvas;
61 SkVector fUnitsPerMeter;
62 SkVector fPixelsPerMeter;
63 };
64
65 ///////////////////////////////////////////////////////////////////////////////
66
67 SkDocument* SkDocument::CreateXPS(SkWStream* stream, SkScalar dpi) {
68 return stream ? SkNEW_ARGS(SkDocument_XPS, (stream, NULL, dpi)) : NULL;
69 }
70
71 static void delete_wstream(SkWStream* stream, bool aborted) {
72 SkDELETE(stream);
73 }
74
75 SkDocument* SkDocument::CreateXPS(const char path[], SkScalar dpi) {
76 SkAutoTDelete<SkFILEWStream> stream(SkNEW_ARGS(SkFILEWStream, (path)));
77 if (!stream->isValid()) {
78 return NULL;
79 }
80 return SkNEW_ARGS(SkDocument_XPS, (stream.detach(), delete_wstream, dpi));
81 }
82
83 #endif // SK_SUPPORT_XPS
OLDNEW
« include/core/SkDocument.h ('K') | « src/device/xps/SkXPSDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698