| 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* |
| 3 | * This file is part of the libcdr 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 | #include <librevenge/librevenge.h> |
| 18 | #include <librevenge-generators/librevenge-generators.h> |
| 19 | #include <librevenge-stream/librevenge-stream.h> |
| 20 | #include <libcdr/libcdr.h> |
| 21 | |
| 22 | #ifndef VERSION |
| 23 | #define VERSION "UNKNOWN VERSION" |
| 24 | #endif |
| 25 | |
| 26 | namespace |
| 27 | { |
| 28 | |
| 29 | int printUsage() |
| 30 | { |
| 31 | printf("`cdr2xhtml' converts CorelDRAW documents to SVG.\n"); |
| 32 | printf("\n"); |
| 33 | printf("Usage: cdr2xhtml [OPTION] FILE\n"); |
| 34 | printf("\n"); |
| 35 | printf("Options:\n"); |
| 36 | printf("\t--help show this help message\n"); |
| 37 | printf("\t--version show version information and exit\n"); |
| 38 | printf("\n"); |
| 39 | printf("Report bugs to <https://bugs.documentfoundation.org/>.\n"); |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | int printVersion() |
| 44 | { |
| 45 | printf("cdr2xhtml " VERSION "\n"); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | } // anonymous namespace |
| 50 | |
| 51 | int main(int argc, char *argv[]) |
| 52 | { |
| 53 | if (argc < 2) |
| 54 | return printUsage(); |
| 55 | |
| 56 | char *file = nullptr; |
| 57 | |
| 58 | for (int i = 1; i < argc; i++) |
| 59 | { |
| 60 | if (!strcmp(argv[i], "--version")) |
| 61 | return printVersion(); |
| 62 | else if (!file && strncmp(argv[i], "--", 2)) |
| 63 | file = argv[i]; |
| 64 | else |
| 65 | return printUsage(); |
| 66 | } |
| 67 | |
| 68 | if (!file) |
| 69 | return printUsage(); |
| 70 | |
| 71 | librevenge::RVNGFileStream input(file); |
| 72 | librevenge::RVNGStringVector output; |
| 73 | librevenge::RVNGSVGDrawingGenerator painter(output, "svg"); |
| 74 | |
| 75 | if (!libcdr::CDRDocument::isSupported(&input)) |
| 76 | { |
| 77 | if (!libcdr::CMXDocument::isSupported(&input)) |
| 78 | { |
| 79 | fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n"); |
| 80 | return 1; |
| 81 | } |
| 82 | else if (!libcdr::CMXDocument::parse(&input, &painter)) |
| 83 | { |
| 84 | fprintf(stderr, "ERROR: Parsing of document failed!\n"); |
| 85 | return 1; |
| 86 | } |
| 87 | } |
| 88 | else if (!libcdr::CDRDocument::parse(&input, &painter)) |
| 89 | { |
| 90 | fprintf(stderr, "ERROR: Parsing of document failed!\n"); |
| 91 | return 1; |
| 92 | } |
| 93 | |
| 94 | if (output.empty()) |
| 95 | { |
| 96 | std::cerr << "ERROR: No SVG document generated!" << std::endl; |
| 97 | return 1; |
| 98 | } |
| 99 | |
| 100 | std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; |
| 101 | std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << std::endl; |
| 102 | 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; |
| 103 | std::cout << "<body>" << std::endl; |
| 104 | std::cout << "<?import namespace=\"svg\" urn=\"http://www.w3.org/2000/svg\"?>" << std::endl; |
| 105 | |
| 106 | for (unsigned k = 0; k<output.size(); ++k) |
| 107 | { |
| 108 | if (k>0) |
| 109 | std::cout << "<hr/>\n"; |
| 110 | |
| 111 | std::cout << "<!-- \n"; |
| 112 | std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; |
| 113 | std::cout << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\""; |
| 114 | std::cout << " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; |
| 115 | std::cout << " -->\n"; |
| 116 | |
| 117 | std::cout << output[k].cstr() << std::endl; |
| 118 | } |
| 119 | |
| 120 | std::cout << "</body>" << std::endl; |
| 121 | std::cout << "</html>" << std::endl; |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |