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 };
138 class GradientInfo
139 {
140 public:
142 GradientInfo()
143 {
144 init();
145 }
147 GradientInfo(const GradientInfo &other)
148 {
149 assign(other);
150 }
152 GradientInfo &operator=(const GradientInfo &other)
153 {
154 assign(other);
155 return *this;
156 }
158 void assign(const GradientInfo &other)
159 {
160 name = other.name;
161 style = other.style;
162 cx = other.cx;
163 cy = other.cy;
164 fx = other.fx;
165 fy = other.fy;
166 r = other.r;
167 x1 = other.x1;
168 y1 = other.y1;
169 x2 = other.x2;
170 y2 = other.y2;
171 }
173 void init()
174 {
175 name = "none";
176 style = "none";
177 cx = 0.0;
178 cy = 0.0;
179 fx = 0.0;
180 fy = 0.0;
181 r = 0.0;
182 x1 = 0.0;
183 y1 = 0.0;
184 x2 = 0.0;
185 y2 = 0.0;
186 }
188 virtual ~GradientInfo()
189 {}
191 //used for eliminating duplicates in the styleTable
192 bool equals(const GradientInfo &other)
193 {
194 if (
195 name != other.name ||
196 style != other.style ||
197 cx != other.cx ||
198 cy != other.cy ||
199 fx != other.fx ||
200 fy != other.fy ||
201 r != other.r ||
202 x1 != other.x1 ||
203 y1 != other.y1 ||
204 x2 != other.x2 ||
205 y2 != other.y2
206 )
207 return false;
208 return true;
209 }
211 std::string name;
212 std::string style;
213 double cx;
214 double cy;
215 double fx;
216 double fy;
217 double r;
218 double x1;
219 double y1;
220 double x2;
221 double y2;
223 };
227 class OdfOutput : public Inkscape::Extension::Implementation::Implementation
228 {
230 public:
232 bool check (Inkscape::Extension::Extension * module);
234 void save (Inkscape::Extension::Output *mod,
235 SPDocument *doc,
236 const gchar *uri);
238 static void init (void);
240 private:
242 URI documentUri;
244 void reset();
246 /* Style table
247 Uses a two-stage lookup to avoid style duplication.
248 Use like:
249 StyleInfo si = styleTable[styleLookupTable[id]];
250 but check for errors, of course
251 */
252 //element id -> style entry name
253 std::map<std::string, std::string> styleLookupTable;
254 //style entry name -> style info
255 std::vector<StyleInfo> styleTable;
257 //element id -> gradient entry name
258 std::map<std::string, std::string> gradientLookupTable;
259 //gradient entry name -> gradient info
260 std::vector<GradientInfo> gradientTable;
262 //for renaming image file names
263 std::map<std::string, std::string> imageTable;
265 void preprocess(ZipFile &zf, Inkscape::XML::Node *node);
267 bool writeManifest(ZipFile &zf);
269 bool writeMeta(ZipFile &zf);
271 bool writeStyle(Writer &outs);
273 bool writeTree(Writer &outs, Inkscape::XML::Node *node);
275 bool writeContent(ZipFile &zf, Inkscape::XML::Node *node);
277 };
282 } //namespace Internal
283 } //namespace Extension
284 } //namespace Inkscape
288 #endif /* EXTENSION_INTERNAL_ODG_OUT_H */