Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Unified Diff: dm/DMSrcSink.cpp

Issue 2209593004: Add an SVG DM source (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: GN fix Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dm/DMSrcSink.h ('k') | gyp/dm.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index b6f061677c04ea806d0bd9c33fa99f224640e4a8..26d88b3817391a341abee1df17a961a1ce8c6580 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -34,6 +34,7 @@
#include "SkSVGCanvas.h"
#include "SkStream.h"
#include "SkTLogic.h"
+#include "SkSVGDOM.h"
#include "SkSwizzler.h"
#include <functional>
@@ -1010,6 +1011,36 @@ SkISize SKPSrc::size() const {
Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+#if defined(SK_XML)
+// Should we try to use the SVG intrinsic size instead?
+static const SkSize kSVGSize = SkSize::Make(1000, 1000);
+
+SVGSrc::SVGSrc(Path path) : fPath(path) {}
+
+Error SVGSrc::draw(SkCanvas* canvas) const {
+ SkFILEStream stream(fPath.c_str());
+ if (!stream.isValid()) {
+ return SkStringPrintf("Unable to open file: %s", fPath.c_str());
+ }
+
+ sk_sp<SkSVGDOM> dom = SkSVGDOM::MakeFromStream(stream, kSVGSize);
+ if (!dom) {
+ return SkStringPrintf("Unable to parse file: %s", fPath.c_str());
+ }
+
+ dom->render(canvas);
+
+ return "";
+}
+
+SkISize SVGSrc::size() const {
+ return kSVGSize.toRound();
+}
+
+Name SVGSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
+
+#endif // defined(SK_XML)
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
MSKPSrc::MSKPSrc(Path path) : fPath(path) {
std::unique_ptr<SkStreamAsset> stream(SkStream::NewFromFile(fPath.c_str()));
« no previous file with comments | « dm/DMSrcSink.h ('k') | gyp/dm.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698