1 /*
2 * This file came from libwpg as a source, their utility wpg2svg
3 * specifically. It has been modified to work as an Inkscape extension.
4 * The Inkscape extension code is covered by this copyright, but the
5 * rest is covered by the one bellow.
6 *
7 * Authors:
8 * Ted Gould <ted@gould.cx>
9 *
10 * Copyright (C) 2006 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 *
14 */
16 /* libwpg
17 * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
18 * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
24 *
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
29 *
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 *
34 * For further information visit http://libwpg.sourceforge.net
35 */
37 /* "This product is not manufactured, approved, or supported by
38 * Corel Corporation or Corel Corporation Limited."
39 */
41 #include <stdio.h>
42 #include "config.h"
44 #ifdef WITH_LIBWPG
46 #include "wpg-input.h"
47 #include "extension/system.h"
48 #include "extension/input.h"
49 #include "document.h"
51 #include "libwpg/libwpg.h"
52 #include "libwpg/WPGStreamImplementation.h"
55 using namespace libwpg;
57 namespace Inkscape {
58 namespace Extension {
59 namespace Internal {
62 SPDocument *
63 WpgInput::open(Inkscape::Extension::Input * mod, const gchar * uri) {
64 WPXInputStream* input = new libwpg::WPGFileStream(uri);
65 if (input->isOLEStream()) {
66 WPXInputStream* olestream = input->getDocumentOLEStream();
67 if (olestream) {
68 delete input;
69 input = olestream;
70 }
71 }
73 if (!WPGraphics::isSupported(input)) {
74 //! \todo Dialog here
75 // fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
76 // printf("I'm giving up not supported\n");
77 delete input;
78 return NULL;
79 }
81 libwpg::WPGString output;
82 if (!libwpg::WPGraphics::generateSVG(input, output)) {
83 delete input;
84 return NULL;
85 }
87 //printf("I've got a doc: \n%s", painter.document.c_str());
89 SPDocument * doc = sp_document_new_from_mem(output.cstr(), strlen(output.cstr()), TRUE);
90 delete input;
91 return doc;
92 }
94 #include "clear-n_.h"
96 void
97 WpgInput::init(void) {
98 Inkscape::Extension::Extension * ext;
100 ext = Inkscape::Extension::build_from_mem(
101 "<inkscape-extension>\n"
102 "<name>" N_("WPG Input") "</name>\n"
103 "<id>org.inkscape.input.wpg</id>\n"
104 "<input>\n"
105 "<extension>.wpg</extension>\n"
106 "<mimetype>image/x-wpg</mimetype>\n"
107 "<filetypename>" N_("WordPerfect Graphics (*.wpg)") "</filetypename>\n"
108 "<filetypetooltip>" N_("Vector graphics format used by Corel WordPerfect") "</filetypetooltip>\n"
109 "</input>\n"
110 "</inkscape-extension>", new WpgInput());
111 } // init
113 } } } /* namespace Inkscape, Extension, Implementation */
114 #endif /* WITH_LIBWPG */
116 /*
117 Local Variables:
118 mode:c++
119 c-file-style:"stroustrup"
120 c-file-offsets:((innamespace . 0)(inline-open . 0))
121 indent-tabs-mode:nil
122 fill-column:99
123 End:
124 */
125 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :