diff options
author | halcanary <halcanary@google.com> | 2015-03-03 08:26:00 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-03 08:26:00 -0800 |
commit | 00d39bcbfc8394a9b48b86b04ab06ec19091fa43 (patch) | |
tree | 2287b3641efeb3175c2eb4af1437c2d0343fecdf /src/doc | |
parent | 60ff4582ae76aa131aeb20a3e16c89fa3a40a41c (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.
NOPRESUBMIT=true
Review URL: https://codereview.chromium.org/963953002
Diffstat (limited to 'src/doc')
-rw-r--r-- | src/doc/SkDocument_XPS.cpp | 79 | ||||
-rw-r--r-- | src/doc/SkDocument_XPS_None.cpp | 3 |
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; } |