aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/doc
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-03-03 09:13:09 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-03 09:13:09 -0800
commit47ef4d5d934bba86848aa238efab21f54a160c1a (patch)
tree8e0fd1776a766fc9b4bcddba37d520763d50ab58 /src/doc
parentf24f2247c25b842327e12c70e44efe4cc1b28dfa (diff)
XPS, DM: add SkDocument::CreateXPS
- SkDocument::CreateXPS() function added, returns NULL on non-Windows OS. - DM: (Windows only) an XPSSink is added, fails on non-Windows OS - DM: Common code for PDFSink::draw and XPSSink::draw are factored into draw_skdocument static function. - SkDocument_XPS (Windows only) implementation of SkDocument via SkXPSDevice. - SkDocument_XPS_None (non-Windows) returns NULL for SkDocument::CreateXPS(). - gyp/xps.gyp refactored. - SkXPSDevice::drawTextOnPath removed (see http://crrev.com/925343003 ) - SkXPSDevice::drawPath supports conics via SkAutoConicToQuads. Review URL: https://codereview.chromium.org/963953002
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/SkDocument_XPS.cpp79
-rw-r--r--src/doc/SkDocument_XPS_None.cpp3
2 files changed, 82 insertions, 0 deletions
diff --git a/src/doc/SkDocument_XPS.cpp b/src/doc/SkDocument_XPS.cpp
new file mode 100644
index 0000000000..db14a708bd
--- /dev/null
+++ b/src/doc/SkDocument_XPS.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkDocument.h"
+#include "SkXPSDevice.h"
+#include "SkStream.h"
+
+class SkDocument_XPS : public SkDocument {
+public:
+ SkDocument_XPS(SkWStream* stream,
+ void (*doneProc)(SkWStream*, bool),
+ SkScalar dpi)
+ : SkDocument(stream, doneProc) {
+ const SkScalar kPointsPerMeter = SkDoubleToScalar(360000.0 / 127.0);
+ fUnitsPerMeter.set(kPointsPerMeter, kPointsPerMeter);
+ SkScalar pixelsPerMeterScale = SkDoubleToScalar(dpi * 5000.0 / 127.0);
+ fPixelsPerMeter.set(pixelsPerMeterScale, pixelsPerMeterScale);
+ fDevice.beginPortfolio(stream);
+ }
+
+ virtual ~SkDocument_XPS() {
+ // subclasses must call close() in their destructors
+ this->close();
+ }
+
+protected:
+ virtual SkCanvas* onBeginPage(SkScalar width,
+ SkScalar height,
+ const SkRect& trimBox) SK_OVERRIDE {
+ fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter,
+ SkSize::Make(width, height));
+ fCanvas.reset(SkNEW_ARGS(SkCanvas, (&fDevice)));
+ fCanvas->clipRect(trimBox);
+ fCanvas->translate(trimBox.x(), trimBox.y());
+ return fCanvas.get();
+ }
+
+ void onEndPage() SK_OVERRIDE {
+ SkASSERT(fCanvas.get());
+ fCanvas->flush();
+ fCanvas.reset(NULL);
+ fDevice.endSheet();
+ }
+
+ bool onClose(SkWStream*) SK_OVERRIDE {
+ SkASSERT(!fCanvas.get());
+ return fDevice.endPortfolio();
+ }
+
+ void onAbort() SK_OVERRIDE {}
+
+private:
+ SkXPSDevice fDevice;
+ SkAutoTUnref<SkCanvas> fCanvas;
+ SkVector fUnitsPerMeter;
+ SkVector fPixelsPerMeter;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+SkDocument* SkDocument::CreateXPS(SkWStream* stream, SkScalar dpi) {
+ return stream ? SkNEW_ARGS(SkDocument_XPS, (stream, NULL, dpi)) : NULL;
+}
+
+static void delete_wstream(SkWStream* stream, bool aborted) {
+ SkDELETE(stream);
+}
+
+SkDocument* SkDocument::CreateXPS(const char path[], SkScalar dpi) {
+ SkAutoTDelete<SkFILEWStream> stream(SkNEW_ARGS(SkFILEWStream, (path)));
+ if (!stream->isValid()) {
+ return NULL;
+ }
+ return SkNEW_ARGS(SkDocument_XPS, (stream.detach(), delete_wstream, dpi));
+}
diff --git a/src/doc/SkDocument_XPS_None.cpp b/src/doc/SkDocument_XPS_None.cpp
new file mode 100644
index 0000000000..01055e5cf0
--- /dev/null
+++ b/src/doc/SkDocument_XPS_None.cpp
@@ -0,0 +1,3 @@
+#include "SkDocument.h"
+SkDocument* SkDocument::CreateXPS(SkWStream*, SkScalar) { return NULL; }
+SkDocument* SkDocument::CreateXPS(const char path[], SkScalar) { return NULL; }