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

Unified Diff: experimental/svg/skp2svg.cpp

Issue 892533002: Initial SVG backend stubbing (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: optional output file arg Created 5 years, 11 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 | « experimental/svg/SkSVGDevice.cpp ('k') | gyp/tools.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/svg/skp2svg.cpp
diff --git a/experimental/svg/skp2svg.cpp b/experimental/svg/skp2svg.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..95bb04a061ffbc465197114c6785942298f75778
--- /dev/null
+++ b/experimental/svg/skp2svg.cpp
@@ -0,0 +1,70 @@
+/*
+ * 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 "LazyDecodeBitmap.h"
+#include "SkCommandLineFlags.h"
+#include "SkPicture.h"
+#include "SkStream.h"
+#include "SkSVGDevice.h"
+
+DEFINE_string2(input, i, "", "input skp file");
+DEFINE_string2(output, o, "", "output svg file (optional)");
+
+// return codes:
+static const int kSuccess = 0;
+static const int kInvalidArgs = 1;
+static const int kIOError = 2;
+static const int kNotAnSKP = 3;
+
+int tool_main(int argc, char** argv);
+int tool_main(int argc, char** argv) {
+ SkCommandLineFlags::SetUsage("Converts an SKP file to SVG.");
+ SkCommandLineFlags::Parse(argc, argv);
+
+ if (FLAGS_input.count() != 1) {
+ SkDebugf("Missing input file\n");
+ return kInvalidArgs;
+ }
+
+ SkFILEStream stream(FLAGS_input[0]);
+ if (!stream.isValid()) {
+ SkDebugf("Couldn't open file: %s\n", FLAGS_input[0]);
+ return kIOError;
+ }
+
+ SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(&stream, &sk_tools::LazyDecodeBitmap));
+ if (!SkToBool(pic.get())) {
+ SkDebugf("Could not load SKP: %s\n", FLAGS_input[0]);
+ return kNotAnSKP;
+ }
+
+ SkAutoTDelete<SkWStream> outStream;
+ if (FLAGS_output.count() > 0) {
+ SkFILEWStream* fileStream = SkNEW_ARGS(SkFILEWStream, (FLAGS_output[0]));
+ if (!fileStream->isValid()) {
+ SkDebugf("Couldn't open output file for writing: %s\n", FLAGS_output[0]);
+ return kIOError;
+ }
+ outStream.reset(fileStream);
+ } else {
+ outStream.reset(SkNEW(SkDebugWStream));
+ }
+
+ SkISize size = pic->cullRect().roundOut().size();
+ SkAutoTUnref<SkBaseDevice> svgDevice(SkSVGDevice::Create(size, outStream));
+ SkCanvas svgCanvas(svgDevice.get());
+
+ pic->playback(&svgCanvas);
+
+ return kSuccess;
+}
+
+#if !defined SK_BUILD_FOR_IOS
+int main(int argc, char * const argv[]) {
+ return tool_main(argc, (char**) argv);
+}
+#endif
« no previous file with comments | « experimental/svg/SkSVGDevice.cpp ('k') | gyp/tools.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698