| 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 "SkSVGCanvas.h" | |
| 13 #include "SkXMLWriter.h" | |
| 14 | |
| 15 DEFINE_string2(input, i, "", "input skp file"); | |
| 16 DEFINE_string2(output, o, "", "output svg file (optional)"); | |
| 17 | |
| 18 // return codes: | |
| 19 static const int kSuccess = 0; | |
| 20 static const int kInvalidArgs = 1; | |
| 21 static const int kIOError = 2; | |
| 22 static const int kNotAnSKP = 3; | |
| 23 | |
| 24 int tool_main(int argc, char** argv); | |
| 25 int tool_main(int argc, char** argv) { | |
| 26 SkCommandLineFlags::SetUsage("Converts an SKP file to SVG."); | |
| 27 SkCommandLineFlags::Parse(argc, argv); | |
| 28 | |
| 29 if (FLAGS_input.count() != 1) { | |
| 30 SkDebugf("Missing input file\n"); | |
| 31 return kInvalidArgs; | |
| 32 } | |
| 33 | |
| 34 SkFILEStream stream(FLAGS_input[0]); | |
| 35 if (!stream.isValid()) { | |
| 36 SkDebugf("Couldn't open file: %s\n", FLAGS_input[0]); | |
| 37 return kIOError; | |
| 38 } | |
| 39 | |
| 40 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(&stream, &sk_tools::
LazyDecodeBitmap)); | |
| 41 if (!SkToBool(pic.get())) { | |
| 42 SkDebugf("Could not load SKP: %s\n", FLAGS_input[0]); | |
| 43 return kNotAnSKP; | |
| 44 } | |
| 45 | |
| 46 SkAutoTDelete<SkWStream> outStream; | |
| 47 if (FLAGS_output.count() > 0) { | |
| 48 SkFILEWStream* fileStream = new SkFILEWStream(FLAGS_output[0]); | |
| 49 if (!fileStream->isValid()) { | |
| 50 SkDebugf("Couldn't open output file for writing: %s\n", FLAGS_output
[0]); | |
| 51 return kIOError; | |
| 52 } | |
| 53 outStream.reset(fileStream); | |
| 54 } else { | |
| 55 outStream.reset(new SkDebugWStream); | |
| 56 } | |
| 57 | |
| 58 SkAutoTDelete<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(outStream.get()))
; | |
| 59 SkAutoTUnref<SkCanvas> svgCanvas(SkSVGCanvas::Create(pic->cullRect(), xmlWri
ter.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 |