Debian Codegraph @

src/conv/svg/qxp2svg.cpp

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libqxp 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 <cstdio>
15 #include <cstring>
16 #include <iostream>
17 #include <sstream>
18
19 #include <librevenge/librevenge.h>
20 #include <librevenge-generators/librevenge-generators.h>
21 #include <librevenge-stream/librevenge-stream.h>
22
23 #include <libqxp/libqxp.h>
24
25 namespace
26 {
27
28 int printUsage()
29 {
30 std::printf("`qxp2svg' converts QuarkXPress documents to SVG.\n");
31 std::printf("\n");
32 std::printf("Usage: qxp2svg [OPTION] FILE\n");
33 std::printf("\n");
34 std::printf("Options:\n");
35 std::printf("\t--help show this help message\n");
36 std::printf("\t--version print version and exit\n");
37 std::printf("\n");
38 std::printf("Report bugs to <http://bugs.documentfoundation.org/>.\n");
39 return -1;
40 }
41
42 int printVersion()
43 {
44 std::printf("qxp2svg " VERSION "\n");
45 return 0;
46 }
47
48
49 } // anonymous namespace
50
51 using libqxp::QXPDocument;
52
53 int main(int argc, char *argv[])
54 {
55 if (argc < 2)
56 return printUsage();
57
58 char *file = 0;
59
60 for (int i = 1; i < argc; i++)
61 {
62 if (!std::strcmp(argv[i], "--version"))
63 return printVersion();
64 else if (!file && std::strncmp(argv[i], "--", 2))
65 file = argv[i];
66 else
67 return printUsage();
68 }
69
70 if (!file)
71 return printUsage();
72
73 librevenge::RVNGFileStream input(file);
74
75 QXPDocument::Type type = QXPDocument::TYPE_UNKNOWN;
76 const bool supported = QXPDocument::isSupported(&input, &type);
77 if (!supported || (type != QXPDocument::TYPE_DOCUMENT && type != QXPDocument::TYPE_TEMPLATE))
78 {
79 std::cerr << "ERROR: Unsupported file format" << std::endl;
80 return 1;
81 }
82
83 librevenge::RVNGStringVector vec;
84 librevenge::RVNGSVGDrawingGenerator generator(vec, "");
85 auto result = QXPDocument::parse(&input, &generator);
86 if (QXPDocument::RESULT_OK != result || vec.empty() || vec[0].empty())
87 {
88 std::cerr << "ERROR: SVG Generation failed!" << std::endl;
89 return 1;
90 }
91
92 #if 1
93 std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
94 std::cout << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"";
95 std::cout << " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";
96 #endif
97 std::cout << vec[0].cstr() << std::endl;
98 return 0;
99 }
100
101 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */