1 /**
2 * OpenDocument <drawing> input and output
3 *
4 * This is an an entry in the extensions mechanism to begin to enable
5 * the inputting and outputting of OpenDocument Format (ODF) files from
6 * within Inkscape. Although the initial implementations will be very lossy
7 * do to the differences in the models of SVG and ODF, they will hopefully
8 * improve greatly with time.
9 *
10 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11 *
12 * Authors:
13 * Bob Jamison
14 *
15 * Copyright (C) 2006 Bob Jamison
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */
32 #ifndef EXTENSION_INTERNAL_ODG_OUT_H
33 #define EXTENSION_INTERNAL_ODG_OUT_H
35 #include <dom/dom.h>
36 #include <dom/io/stringstream.h>
37 #include <dom/uri.h>
39 #include <glib.h>
40 #include "extension/implementation/implementation.h"
43 #include <xml/repr.h>
45 #include <string>
46 #include <map>
48 #include <dom/util/ziptool.h>
49 #include <dom/io/domstream.h>
52 namespace Inkscape
53 {
54 namespace Extension
55 {
56 namespace Internal
57 {
59 typedef org::w3c::dom::URI URI;
60 typedef org::w3c::dom::io::Writer Writer;
63 class StyleInfo
64 {
65 public:
67 StyleInfo()
68 {
69 init();
70 }
72 StyleInfo(const StyleInfo &other)
73 {
74 assign(other);
75 }
77 StyleInfo &operator=(const StyleInfo &other)
78 {
79 assign(other);
80 return *this;
81 }
83 void assign(const StyleInfo &other)
84 {
85 name = other.name;
86 stroke = other.stroke;
87 strokeColor = other.strokeColor;
88 strokeWidth = other.strokeWidth;
89 strokeOpacity = other.strokeOpacity;
90 fill = other.fill;
91 fillColor = other.fillColor;
92 fillOpacity = other.fillOpacity;
93 }
95 void init()
96 {
97 name = "none";
98 stroke = "none";
99 strokeColor = "none";
100 strokeWidth = "none";
101 strokeOpacity = "none";
102 fill = "none";
103 fillColor = "none";
104 fillOpacity = "none";
105 }
107 virtual ~StyleInfo()
108 {}
110 //used for eliminating duplicates in the styleTable
111 bool equals(const StyleInfo &other)
112 {
113 if (
114 stroke != other.stroke ||
115 strokeColor != other.strokeColor ||
116 strokeWidth != other.strokeWidth ||
117 strokeOpacity != other.strokeOpacity ||
118 fill != other.fill ||
119 fillColor != other.fillColor ||
120 fillOpacity != other.fillOpacity
121 )
122 return false;
123 return true;
124 }
126 std::string name;
127 std::string stroke;
128 std::string strokeColor;
129 std::string strokeWidth;
130 std::string strokeOpacity;
131 std::string fill;
132 std::string fillColor;
133 std::string fillOpacity;
135 };
139 class OdfOutput : public Inkscape::Extension::Implementation::Implementation
140 {
142 public:
144 bool check (Inkscape::Extension::Extension * module);
146 void save (Inkscape::Extension::Output *mod,
147 SPDocument *doc,
148 const gchar *uri);
150 static void init (void);
152 private:
154 URI documentUri;
156 /* Style table
157 Uses a two-stage lookup to avoid style duplication.
158 Use like:
159 StyleInfo si = styleTable[styleLookupTable[id]];
160 but check for errors, of course
161 */
162 //element id -> style entry name
163 std::map<std::string, std::string> styleLookupTable;
164 //style entry name -> style info
165 std::vector<StyleInfo> styleTable;
167 //for renaming image file names
168 std::map<std::string, std::string> imageTable;
170 void preprocess(ZipFile &zf, Inkscape::XML::Node *node);
172 bool writeManifest(ZipFile &zf);
174 bool writeMeta(ZipFile &zf);
176 bool writeStyle(Writer &outs);
178 bool writeTree(Writer &outs, Inkscape::XML::Node *node);
180 bool writeContent(ZipFile &zf, Inkscape::XML::Node *node);
182 };
187 } //namespace Internal
188 } //namespace Extension
189 } //namespace Inkscape
193 #endif /* EXTENSION_INTERNAL_ODG_OUT_H */