OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "LazyDecodeBitmap.h" | |
9 #include "SkCommandLineFlags.h" | |
10 #include "SkPicture.h" | |
11 #include "SkStream.h" | |
12 #include "SkSVGDevice.h" | |
13 | |
14 DEFINE_string2(input, i, "", "input skp file"); | |
15 DEFINE_string2(output, o, "", "output svg file (optional)"); | |
16 | |
17 // return codes: | |
18 static const int kSuccess = 0; | |
19 static const int kInvalidArgs = 1; | |
20 static const int kIOError = 2; | |
21 static const int kNotAnSKP = 3; | |
22 | |
23 int tool_main(int argc, char** argv); | |
24 int tool_main(int argc, char** argv) { | |
25 SkCommandLineFlags::SetUsage("Converts an SKP file to SVG."); | |
26 SkCommandLineFlags::Parse(argc, argv); | |
27 | |
28 if (FLAGS_input.count() != 1) { | |
29 SkDebugf("Missing input file\n"); | |
30 return kInvalidArgs; | |
31 } | |
32 | |
33 SkFILEStream stream(FLAGS_input[0]); | |
34 if (!stream.isValid()) { | |
35 SkDebugf("Couldn't open file: %s\n", FLAGS_input[0]); | |
36 return kIOError; | |
37 } | |
38 | |
39 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(&stream, &sk_tools::
LazyDecodeBitmap)); | |
40 if (!SkToBool(pic.get())) { | |
41 SkDebugf("Could not load SKP: %s\n", FLAGS_input[0]); | |
42 return kNotAnSKP; | |
43 } | |
44 | |
45 SkAutoTDelete<SkWStream> outStream; | |
46 if (FLAGS_output.count() > 0) { | |
47 SkFILEWStream* fileStream = SkNEW_ARGS(SkFILEWStream, (FLAGS_output[0]))
; | |
48 if (!fileStream->isValid()) { | |
49 SkDebugf("Couldn't open output file for writing: %s\n", FLAGS_output
[0]); | |
50 return kIOError; | |
51 } | |
52 outStream.reset(fileStream); | |
53 } else { | |
54 outStream.reset(SkNEW(SkDebugWStream)); | |
55 } | |
56 | |
57 SkISize size = pic->cullRect().roundOut().size(); | |
58 SkAutoTUnref<SkBaseDevice> svgDevice(SkSVGDevice::Create(size, outStream)); | |
59 SkCanvas svgCanvas(svgDevice.get()); | |
60 | |
61 pic->playback(&svgCanvas); | |
62 | |
63 return kSuccess; | |
64 } | |
65 | |
66 #if !defined SK_BUILD_FOR_IOS | |
67 int main(int argc, char * const argv[]) { | |
68 return tool_main(argc, (char**) argv); | |
69 } | |
70 #endif | |
OLD | NEW |