Code

437148873615e816923ea1e9ff16849acd29026d
[inkscape.git] / src / extension / internal / odf.h
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         name          = other.name;
84         stroke        = other.stroke;
85         strokeColor   = other.strokeColor;
86         strokeWidth   = other.strokeWidth;
87         strokeOpacity = other.strokeOpacity;
88         fill          = other.fill;
89         fillColor     = other.fillColor;
90         fillOpacity   = other.fillOpacity;
91         }
93     void init()
94         {
95         name          = "none";
96         stroke        = "none";
97         strokeColor   = "none";
98         strokeWidth   = "none";
99         strokeOpacity = "none";
100         fill          = "none";
101         fillColor     = "none";
102         fillOpacity   = "none";
103         }
105     virtual ~StyleInfo()
106         {}
108     //used for eliminating duplicates in the styleTable
109     bool equals(const StyleInfo &other)
110         {
111         if (
112             stroke        != other.stroke        ||
113             strokeColor   != other.strokeColor   ||
114             strokeWidth   != other.strokeWidth   ||
115             strokeOpacity != other.strokeOpacity ||
116             fill          != other.fill          ||
117             fillColor     != other.fillColor     ||
118             fillOpacity   != other.fillOpacity
119            )
120             return false;
121         return true;
122         }
124     std::string name;
125     std::string stroke;
126     std::string strokeColor;
127     std::string strokeWidth;
128     std::string strokeOpacity;
129     std::string fill;
130     std::string fillColor;
131     std::string fillOpacity;
133 };
137 class OdfOutput : public Inkscape::Extension::Implementation::Implementation
140 public:
142     bool check (Inkscape::Extension::Extension * module);
144     void save  (Inkscape::Extension::Output *mod,
145                 SPDocument *doc,
146                 const gchar *uri);
148     static void   init  (void);
150 private:
152     /* Style table
153        Uses a two-stage lookup to avoid style duplication.
154        Use like:
155        StyleInfo si = styleTable[styleLookupTable[id]];
156        but check for errors, of course
157     */
158     //element id -> style entry name
159     std::map<std::string, std::string> styleLookupTable;
160     //style entry name -> style info
161     std::vector<StyleInfo> styleTable;
163     //for renaming image file names
164     std::map<std::string, std::string> imageTable;
166     void preprocess(ZipFile &zf, Inkscape::XML::Node *node);
168     bool writeManifest(ZipFile &zf);
170     bool writeMeta(ZipFile &zf);
172     bool writeStyle(Writer &outs);
174     bool writeTree(Writer &outs, Inkscape::XML::Node *node);
176     bool writeContent(ZipFile &zf, Inkscape::XML::Node *node);
178 };
183 }  //namespace Internal
184 }  //namespace Extension
185 }  //namespace Inkscape
189 #endif /* EXTENSION_INTERNAL_ODG_OUT_H */