diff options
Diffstat (limited to 'dm')
-rw-r--r-- | dm/DM.cpp | 4 | ||||
-rw-r--r-- | dm/DMSrcSink.cpp | 15 | ||||
-rw-r--r-- | dm/DMSrcSink.h | 5 |
3 files changed, 20 insertions, 4 deletions
@@ -899,6 +899,10 @@ static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLi } } #endif + if (const SkCommandLineConfigSvg* svgConfig = config->asConfigSvg()) { + int pageIndex = svgConfig->getPageIndex(); + return new SVGSink(pageIndex); + } #define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); } diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 2229b9c26d..149138d832 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1838,14 +1838,23 @@ Error DebugSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) cons /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ -SVGSink::SVGSink() {} +SVGSink::SVGSink(int pageIndex) : fPageIndex(pageIndex) {} Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const { #if defined(SK_XML) + if (src.pageCount() > 1) { + int pageCount = src.pageCount(); + if (fPageIndex > pageCount - 1) { + return Error(SkStringPrintf("Page index %d too high for document with only %d pages.", + fPageIndex, pageCount)); + } + } std::unique_ptr<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(dst)); - return src.draw(SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()), + return src.draw(fPageIndex, + SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()), SkIntToScalar(src.size().height())), - xmlWriter.get()).get()); + xmlWriter.get()) + .get()); #else return Error("SVG sink is disabled."); #endif // SK_XML diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 6cc5df690f..227ef5341a 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -458,11 +458,14 @@ public: class SVGSink : public Sink { public: - SVGSink(); + SVGSink(int pageIndex = 0); Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; const char* fileExtension() const override { return "svg"; } SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } + +private: + int fPageIndex; }; |