| 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* |
| 3 | * This file is a part of the libzmf project. |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | */ |
| 9 | |
| 10 | #ifdef HAVE_CONFIG_H |
| 11 | #include "config.h" |
| 12 | #endif |
| 13 | |
| 14 | #include <iostream> |
| 15 | #include <stdio.h> |
| 16 | #include <string.h> |
| 17 | |
| 18 | #include <librevenge-generators/librevenge-generators.h> |
| 19 | #include <librevenge-stream/librevenge-stream.h> |
| 20 | |
| 21 | #include <libzmf/libzmf.h> |
| 22 | |
| 23 | #ifndef VERSION |
| 24 | #define VERSION "UNKNOWN VERSION" |
| 25 | #endif |
| 26 | |
| 27 | namespace |
| 28 | { |
| 29 | |
| 30 | int printUsage() |
| 31 | { |
| 32 | printf("`zmf2svg' converts Zoner Draw documents to SVG.\n"); |
| 33 | printf("\n"); |
| 34 | printf("Usage: zmf2svg [OPTION] INPUT\n"); |
| 35 | printf("\n"); |
| 36 | printf("Options:\n"); |
| 37 | printf("\t--help show this help message\n"); |
| 38 | printf("\t--version show version information and exit\n"); |
| 39 | return -1; |
| 40 | } |
| 41 | |
| 42 | int printVersion() |
| 43 | { |
| 44 | printf("zmf2svg " VERSION "\n"); |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | } // anonymous namespace |
| 49 | |
| 50 | int main(int argc, char *argv[]) |
| 51 | { |
| 52 | if (argc < 2) |
| 53 | return printUsage(); |
| 54 | |
| 55 | char *file = 0; |
| 56 | |
| 57 | for (int i = 1; i < argc; i++) |
| 58 | { |
| 59 | if (!strcmp(argv[i], "--version")) |
| 60 | return printVersion(); |
| 61 | else if (!file && strncmp(argv[i], "--", 2)) |
| 62 | file = argv[i]; |
| 63 | else |
| 64 | return printUsage(); |
| 65 | } |
| 66 | |
| 67 | if (!file) |
| 68 | return printUsage(); |
| 69 | |
| 70 | librevenge::RVNGFileStream input(file); |
| 71 | |
| 72 | if (!libzmf::ZMFDocument::isSupported(&input)) |
| 73 | { |
| 74 | std::cerr << "ERROR: Unsupported file format (unsupported version) or file is encrypted!" << std::endl; |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | librevenge::RVNGStringVector output; |
| 79 | librevenge::RVNGSVGDrawingGenerator generator(output, "svg"); |
| 80 | if (!libzmf::ZMFDocument::parse(&input, &generator)) |
| 81 | { |
| 82 | std::cerr << "ERROR: SVG Generation failed!" << std::endl; |
| 83 | return 1; |
| 84 | } |
| 85 | |
| 86 | if (output.empty()) |
| 87 | { |
| 88 | std::cerr << "ERROR: No SVG document generated!" << std::endl; |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; |
| 93 | std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << std::endl; |
| 94 | std::cout << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" << std::endl; |
| 95 | std::cout << "<body>" << std::endl; |
| 96 | std::cout << "<?import namespace=\"svg\" urn=\"http://www.w3.org/2000/svg\"?>" << std::endl; |
| 97 | |
| 98 | for (unsigned k = 0; k<output.size(); ++k) |
| 99 | { |
| 100 | if (k>0) |
| 101 | std::cout << "<hr/>\n"; |
| 102 | |
| 103 | std::cout << "<!-- \n"; |
| 104 | std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; |
| 105 | std::cout << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\""; |
| 106 | std::cout << " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; |
| 107 | std::cout << " -->\n"; |
| 108 | |
| 109 | std::cout << output[k].cstr() << std::endl; |
| 110 | } |
| 111 | |
| 112 | std::cout << "</body>" << std::endl; |
| 113 | std::cout << "</html>" << std::endl; |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |