#if defined(SK_BUILD_FOR_WIN)
#include "SkAutoCoInitialize.h"
+ #include "SkHRESULT.h"
+ #include "SkTScopedComPtr.h"
+ #include <XpsObjectModel.h>
#endif
#if defined(SK_XML)
XPSSink::XPSSink() {}
-Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
#ifdef SK_BUILD_FOR_WIN
+static SkTScopedComPtr<IXpsOMObjectFactory> make_xps_factory() {
+ IXpsOMObjectFactory* factory;
+ HRN(CoCreateInstance(CLSID_XpsOMObjectFactory,
+ nullptr,
+ CLSCTX_INPROC_SERVER,
+ IID_PPV_ARGS(&factory)));
+ return SkTScopedComPtr<IXpsOMObjectFactory>(factory);
+}
+
+Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
SkAutoCoInitialize com;
if (!com.succeeded()) {
return "Could not initialize COM.";
}
-#endif
- sk_sp<SkDocument> doc(SkDocument::MakeXPS(dst));
+ SkTScopedComPtr<IXpsOMObjectFactory> factory = make_xps_factory();
+ if (!factory) {
+ return "Failed to create XPS Factory.";
+ }
+ sk_sp<SkDocument> doc(SkDocument::MakeXPS(dst, factory.get()));
if (!doc) {
return "SkDocument::MakeXPS() returned nullptr";
}
return draw_skdocument(src, doc.get(), dst);
}
+#else
+Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
+ return "XPS not supported on this platform.";
+}
+#endif
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
"$_src/xps/SkXPSDocument.h",
"$_src/xps/SkXPSDevice.cpp",
"$_src/xps/SkXPSDevice.h",
- "$_src/xps/SkDocument_XPS_None.cpp",
]
class SkCanvas;
class SkWStream;
+#ifdef SK_BUILD_FOR_WIN
+struct IXpsOMObjectFactory;
+#endif
+
/** SK_ScalarDefaultDPI is 72 DPI.
*/
#define SK_ScalarDefaultRasterDPI 72.0f
static sk_sp<SkDocument> MakePDF(const char outputFilePath[],
SkScalar dpi = SK_ScalarDefaultRasterDPI);
+#ifdef SK_BUILD_FOR_WIN
/**
* Create a XPS-backed document, writing the results into the stream.
- * Returns NULL if XPS is not supported.
+ *
+ * @param stream A XPS document will be written to this stream. The
+ * document may write to the stream at anytime during its
+ * lifetime, until either close() or abort() are called or
+ * the document is deleted.
+ * @param xpsFactory A pointer to a COM XPS factory. Must be non-null.
+ * The document will take a ref to the factory. See
+ * dm/DMSrcSink.cpp for an example.
+ * @param dpi The DPI (pixels-per-inch) at which features without
+ * native XPS support will be rasterized (e.g. draw image
+ * with perspective, draw text with perspective, ...) A
+ * larger DPI would create a XPS that reflects the
+ * original intent with better fidelity, but it can make
+ * for larger XPS files too, which would use more memory
+ * while rendering, and it would be slower to be processed
+ * or sent online or to printer.
+ *
+ * @returns nullptr if XPS is not supported.
*/
static sk_sp<SkDocument> MakeXPS(SkWStream* stream,
+ IXpsOMObjectFactory* xpsFactory,
SkScalar dpi = SK_ScalarDefaultRasterDPI);
-
- /**
- * Create a XPS-backed document, writing the results into a file.
- * Returns NULL if XPS is not supported.
- */
- static sk_sp<SkDocument> MakeXPS(const char path[],
- SkScalar dpi = SK_ScalarDefaultRasterDPI);
+#endif
+ // DEPRECATED; TODO(halcanary): remove this function after Chromium switches to new API.
+ static sk_sp<SkDocument> MakeXPS(SkWStream*) { return nullptr; }
/**
* Begin a new page for the document, returning the canvas that will draw
+++ /dev/null
-/*
- * 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 "SkTypes.h"
-#if !defined(SK_BUILD_FOR_WIN32)
-
-#include "SkDocument.h"
-sk_sp<SkDocument> SkDocument::MakeXPS(SkWStream*, SkScalar) { return nullptr; }
-sk_sp<SkDocument> SkDocument::MakeXPS(const char path[], SkScalar) {
- return nullptr;
-}
-
-#endif//!defined(SK_BUILD_FOR_WIN32)
#include "SkHRESULT.h"
SkXPSDocument::SkXPSDocument(SkWStream* stream,
- void (*doneProc)(SkWStream*, bool),
SkScalar dpi,
SkTScopedComPtr<IXpsOMObjectFactory> xpsFactory)
- : SkDocument(stream, doneProc)
+ : SkDocument(stream, nullptr)
, fXpsFactory(std::move(xpsFactory))
, fDevice(SkISize{10000, 10000})
{
void SkXPSDocument::onAbort() {}
-
-static SkTScopedComPtr<IXpsOMObjectFactory> make_xps_factory() {
- IXpsOMObjectFactory* factory;
- HRN(CoCreateInstance(CLSID_XpsOMObjectFactory,
- nullptr,
- CLSCTX_INPROC_SERVER,
- IID_PPV_ARGS(&factory)));
- return SkTScopedComPtr<IXpsOMObjectFactory>(factory);
-}
-
-
///////////////////////////////////////////////////////////////////////////////
-// TODO(halcanary, reed): modify the SkDocument API to take a IXpsOMObjectFactory* pointer.
-/*
sk_sp<SkDocument> SkDocument::MakeXPS(SkWStream* stream,
IXpsOMObjectFactory* factoryPtr,
SkScalar dpi) {
SkTScopedComPtr<IXpsOMObjectFactory> factory(SkSafeRefComPtr(factoryPtr));
return stream && factory
- ? sk_make_sp<SkXPSDocument>(stream, nullptr, dpi, std::move(factory))
- : nullptr;
-}
-*/
-
-sk_sp<SkDocument> SkDocument::MakeXPS(SkWStream* stream, SkScalar dpi) {
- auto factory = make_xps_factory();
- return stream && factory
- ? sk_make_sp<SkXPSDocument>(stream, nullptr, dpi, std::move(factory))
- : nullptr;
-}
-
-sk_sp<SkDocument> SkDocument::MakeXPS(const char path[], SkScalar dpi) {
- std::unique_ptr<SkFILEWStream> stream(new SkFILEWStream(path));
- auto factory = make_xps_factory();
- return stream->isValid() && factory
- ? sk_make_sp<SkXPSDocument>(stream.release(),
- [](SkWStream* s, bool) { delete s; },
- dpi, std::move(factory))
+ ? sk_make_sp<SkXPSDocument>(stream, dpi, std::move(factory))
: nullptr;
}
class SkXPSDocument final : public SkDocument {
public:
- SkXPSDocument(SkWStream*, void (*doneProc)(SkWStream*, bool abort),
- SkScalar dpi, SkTScopedComPtr<IXpsOMObjectFactory>);
+ SkXPSDocument(SkWStream*, SkScalar dpi, SkTScopedComPtr<IXpsOMObjectFactory>);
virtual ~SkXPSDocument();
protected: