2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #if defined(SK_BUILD_FOR_WIN32)
12 #include "SkXPSDocument.h"
14 #include "SkHRESULT.h"
16 SkXPSDocument::SkXPSDocument(SkWStream* stream,
18 SkTScopedComPtr<IXpsOMObjectFactory> xpsFactory)
19 : SkDocument(stream, nullptr)
20 , fXpsFactory(std::move(xpsFactory))
21 , fDevice(SkISize{10000, 10000})
23 const SkScalar kPointsPerMeter = SkDoubleToScalar(360000.0 / 127.0);
24 fUnitsPerMeter.set(kPointsPerMeter, kPointsPerMeter);
25 SkScalar pixelsPerMeterScale = SkDoubleToScalar(dpi * 5000.0 / 127.0);
26 fPixelsPerMeter.set(pixelsPerMeterScale, pixelsPerMeterScale);
27 SkASSERT(fXpsFactory);
28 fDevice.beginPortfolio(stream, fXpsFactory.get());
31 SkXPSDocument::~SkXPSDocument() {
32 // subclasses must call close() in their destructors
36 SkCanvas* SkXPSDocument::onBeginPage(SkScalar width,
38 const SkRect& trimBox) {
39 fDevice.beginSheet(fUnitsPerMeter, fPixelsPerMeter,
40 SkSize::Make(width, height));
41 fCanvas.reset(new SkCanvas(&fDevice));
42 fCanvas->clipRect(trimBox);
43 fCanvas->translate(trimBox.x(), trimBox.y());
47 void SkXPSDocument::onEndPage() {
48 SkASSERT(fCanvas.get());
50 fCanvas.reset(nullptr);
54 void SkXPSDocument::onClose(SkWStream*) {
55 SkASSERT(!fCanvas.get());
56 (void)fDevice.endPortfolio();
59 void SkXPSDocument::onAbort() {}
61 ///////////////////////////////////////////////////////////////////////////////
63 sk_sp<SkDocument> SkDocument::MakeXPS(SkWStream* stream,
65 SkTScopedComPtr<IXpsOMObjectFactory> factory;
66 auto hr = CoCreateInstance(
67 CLSID_XpsOMObjectFactory,
70 IID_PPV_ARGS(&factory));
74 return SkDocument::MakeXPS (stream, factory, dpi);
77 sk_sp<SkDocument> SkDocument::MakeXPS(SkWStream* stream,
78 IXpsOMObjectFactory* factoryPtr,
80 SkTScopedComPtr<IXpsOMObjectFactory> factory(SkSafeRefComPtr(factoryPtr));
81 return stream && factory
82 ? sk_make_sp<SkXPSDocument>(stream, dpi, std::move(factory))
86 #endif//defined(SK_BUILD_FOR_WIN32)