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