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>
38 #include <glib.h>
39 #include "extension/implementation/implementation.h"
42 #include <xml/repr.h>
44 #include <string>
45 #include <map>
47 #include <dom/util/ziptool.h>
48 #include <dom/io/domstream.h>
50 typedef org::w3c::dom::io::Writer Writer;
52 namespace Inkscape
53 {
54 namespace Extension
55 {
56 namespace Internal
57 {
61 class StyleInfo
62 {
63 public:
65 StyleInfo()
66 {
67 init();
68 }
70 StyleInfo(const StyleInfo &other)
71 {
72 assign(other);
73 }
75 StyleInfo &operator=(const StyleInfo &other)
76 {
77 assign(other);
78 return *this;
79 }
81 void assign(const StyleInfo &other)
82 {
83 stroke = other.stroke;
84 strokeColor = other.strokeColor;
85 strokeWidth = other.strokeWidth;
86 strokeOpacity = other.strokeOpacity;
87 fill = other.fill;
88 fillColor = other.fillColor;
89 fillOpacity = other.fillOpacity;
90 }
92 void init()
93 {
94 stroke = "none";
95 strokeColor = "none";
96 strokeWidth = "none";
97 strokeOpacity = "none";
98 fill = "none";
99 fillColor = "none";
100 fillOpacity = "none";
101 }
103 virtual ~StyleInfo()
104 {}
106 //used for eliminating duplicates in the styleTable
107 bool equals(const StyleInfo &other)
108 {
109 if (
110 stroke != other.stroke ||
111 strokeColor != other.strokeColor ||
112 strokeWidth != other.strokeWidth ||
113 strokeOpacity != other.strokeOpacity ||
114 fill != other.fill ||
115 fillColor != other.fillColor ||
116 fillOpacity != other.fillOpacity
117 )
118 return false;
119 return true;
120 }
122 std::string stroke;
123 std::string strokeColor;
124 std::string strokeWidth;
125 std::string strokeOpacity;
126 std::string fill;
127 std::string fillColor;
128 std::string fillOpacity;
130 };
134 class OdfOutput : public Inkscape::Extension::Implementation::Implementation
135 {
137 public:
139 bool check (Inkscape::Extension::Extension * module);
141 void save (Inkscape::Extension::Output *mod,
142 SPDocument *doc,
143 const gchar *uri);
145 static void init (void);
147 private:
149 /* Style table
150 Uses a two-stage lookup to avoid style duplication.
151 Use like:
152 StyleInfo si = styleTable[styleLookupTable[id]];
153 but check for errors, of course
154 */
155 //element id -> style entry name
156 std::map<std::string, std::string> styleLookupTable;
157 //style entry name -> style info
158 std::map<std::string, StyleInfo> styleTable;
160 //for renaming image file names
161 std::map<std::string, std::string> imageTable;
163 void preprocess(ZipFile &zf, Inkscape::XML::Node *node);
165 bool writeManifest(ZipFile &zf);
167 bool writeMeta(ZipFile &zf);
169 bool writeStyle(Writer &outs);
171 bool writeTree(Writer &outs, Inkscape::XML::Node *node);
173 bool writeContent(ZipFile &zf, Inkscape::XML::Node *node);
175 };
180 } //namespace Internal
181 } //namespace Extension
182 } //namespace Inkscape
186 #endif /* EXTENSION_INTERNAL_ODG_OUT_H */