Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
odf.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
/*
5 * Authors:
6 * Bob Jamison
7 * Abhishek Sharma
8 *
9 * Copyright (C) 2018 Authors
10 * Released under GNU LGPL v2.1+, read the file 'COPYING' for more information.
11 */
12
13#ifndef EXTENSION_INTERNAL_ODG_OUT_H
14#define EXTENSION_INTERNAL_ODG_OUT_H
15
16#include <map> // for map
17#include <string> // for string
18#include <vector> // for vector
19
20#include <glibmm/ustring.h> // for ustring, operat...
21
22#include "extension/implementation/implementation.h" // for Implementation
23#include "io/stream/inkscapestream.h" // for Writer
24
25class SPDocument;
26class SPItem;
27class ZipFile;
28
29namespace Geom {
30class Affine;
31} // namespace Geom
32
34
36
38{
39public:
40
42 {
43 init();
44 }
45
46 StyleInfo(const StyleInfo &other)
47 {
48 assign(other);
49 }
50
52 {
53 assign(other);
54 return *this;
55 }
56
57 void assign(const StyleInfo &other)
58 {
59 name = other.name;
60 stroke = other.stroke;
64 fill = other.fill;
65 fillColor = other.fillColor;
67 }
68
69 void init()
70 {
71 name = "none";
72 stroke = "none";
73 strokeColor = "none";
74 strokeWidth = "none";
75 strokeOpacity = "none";
76 fill = "none";
77 fillColor = "none";
78 fillOpacity = "none";
79 }
80
81 virtual ~StyleInfo()
82 = default;
83
84 //used for eliminating duplicates in the styleTable
85 bool equals(const StyleInfo &other)
86 {
87 if (
88 stroke != other.stroke ||
89 strokeColor != other.strokeColor ||
90 strokeWidth != other.strokeWidth ||
92 fill != other.fill ||
93 fillColor != other.fillColor ||
95 )
96 return false;
97 return true;
98 }
99
100 Glib::ustring name;
101 Glib::ustring stroke;
102 Glib::ustring strokeColor;
103 Glib::ustring strokeWidth;
104 Glib::ustring strokeOpacity;
105 Glib::ustring fill;
106 Glib::ustring fillColor;
107 Glib::ustring fillOpacity;
108
109};
110
111
112
113
115{
116public:
118 {}
119 GradientStop(unsigned long rgbArg, double opacityArg)
120 { rgb = rgbArg; opacity = opacityArg; }
122 = default;
124 { assign(other); }
125 virtual GradientStop& operator=(const GradientStop &other)
126 { assign(other); return *this; }
127 void assign(const GradientStop &other)
128 {
129 rgb = other.rgb;
130 opacity = other.opacity;
131 }
132 unsigned long rgb;
133 double opacity;
134};
135
136
137
139{
140public:
141
143 {
144 init();
145 }
146
148 {
149 assign(other);
150 }
151
153 {
154 assign(other);
155 return *this;
156 }
157
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 stops = other.stops;
172 }
173
174 void init()
175 {
176 name = "none";
177 style = "none";
178 cx = 0.0;
179 cy = 0.0;
180 fx = 0.0;
181 fy = 0.0;
182 r = 0.0;
183 x1 = 0.0;
184 y1 = 0.0;
185 x2 = 0.0;
186 y2 = 0.0;
187 stops.clear();
188 }
189
191 = default;
192
193 //used for eliminating duplicates in the styleTable
194 bool equals(const GradientInfo &other)
195 {
196 if (
197 name != other.name ||
198 style != other.style ||
199 cx != other.cx ||
200 cy != other.cy ||
201 fx != other.fx ||
202 fy != other.fy ||
203 r != other.r ||
204 x1 != other.x1 ||
205 y1 != other.y1 ||
206 x2 != other.x2 ||
207 y2 != other.y2
208 )
209 return false;
210 if (stops.size() != other.stops.size())
211 return false;
212 for (unsigned int i=0 ; i<stops.size() ; i++)
213 {
214 GradientStop g1 = stops[i];
215 GradientStop g2 = other.stops[i];
216 if (g1.rgb != g2.rgb)
217 return false;
218 if (g1.opacity != g2.opacity)
219 return false;
220 }
221 return true;
222 }
223
224 Glib::ustring name;
225 Glib::ustring style;
226 double cx;
227 double cy;
228 double fx;
229 double fy;
230 double r;
231 double x1;
232 double y1;
233 double x2;
234 double y2;
235 std::vector<GradientStop> stops;
236
237};
238
239
240
253{
254
255public:
256
257 bool check (Inkscape::Extension::Extension * module) override;
258
260 SPDocument *doc,
261 char const *filename) override;
262
263 static void init ();
264
265private:
266
267 std::string docBaseUri;
268
269 void reset();
270
271 //cc or dc metadata name/value pairs
272 std::map<Glib::ustring, Glib::ustring> metadata;
273
274 /* Style table
275 Uses a two-stage lookup to avoid style duplication.
276 Use like:
277 StyleInfo si = styleTable[styleLookupTable[id]];
278 but check for errors, of course
279 */
280 //element id -> style entry name
281 std::map<Glib::ustring, Glib::ustring> styleLookupTable;
282 //style entry name -> style info
283 std::vector<StyleInfo> styleTable;
284
285 //element id -> gradient entry name
286 std::map<Glib::ustring, Glib::ustring> gradientLookupTable;
287 //gradient entry name -> gradient info
288 std::vector<GradientInfo> gradientTable;
289
290 //for renaming image file names
291 std::map<Glib::ustring, Glib::ustring> imageTable;
292
294
295 bool writeManifest(ZipFile &zf);
296
297 bool writeMeta(ZipFile &zf);
298
300
301 bool processStyle(SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke, Glib::ustring& output);
302
304 const Glib::ustring &id, Geom::Affine &tf, Glib::ustring& gradientName, Glib::ustring& output, bool checkFillGradient = true);
305
306 bool writeStyleHeader(Writer &outs);
307
308 bool writeStyleFooter(Writer &outs);
309
310 bool writeContentHeader(Writer &outs);
311
312 bool writeContentFooter(Writer &outs);
313
314 bool writeTree(Writer &couts, Writer &souts, SPDocument *doc, Inkscape::XML::Node *node);
315
316 bool writeContent(ZipFile &zf, SPDocument *doc);
317
318};
319
320} //namespace Inkscape::Extension::Internal
321
322#endif /* EXTENSION_INTERNAL_ODG_OUT_H */
323
324/*
325 Local Variables:
326 mode:c++
327 c-file-style:"stroustrup"
328 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
329 indent-tabs-mode:nil
330 fill-column:99
331 End:
332*/
333// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
334
3x3 matrix representing an affine transformation.
Definition affine.h:70
The object that is the basis for the Extension system.
Definition extension.h:133
Base class for all implementations of modules.
void assign(const GradientInfo &other)
Definition odf.h:158
std::vector< GradientStop > stops
Definition odf.h:235
bool equals(const GradientInfo &other)
Definition odf.h:194
GradientInfo & operator=(const GradientInfo &other)
Definition odf.h:152
GradientInfo(const GradientInfo &other)
Definition odf.h:147
GradientStop(const GradientStop &other)
Definition odf.h:123
virtual GradientStop & operator=(const GradientStop &other)
Definition odf.h:125
void assign(const GradientStop &other)
Definition odf.h:127
GradientStop(unsigned long rgbArg, double opacityArg)
Definition odf.h:119
OpenDocument <drawing> input and output.
Definition odf.h:253
bool check(Inkscape::Extension::Extension *module) override
Make sure that we are in the database.
Definition odf.cpp:2101
bool writeContentHeader(Writer &outs)
Write the header for the content.xml file.
Definition odf.cpp:1881
std::map< Glib::ustring, Glib::ustring > styleLookupTable
Definition odf.h:281
std::map< Glib::ustring, Glib::ustring > imageTable
Definition odf.h:291
std::map< Glib::ustring, Glib::ustring > gradientLookupTable
Definition odf.h:286
void save(Inkscape::Extension::Output *mod, SPDocument *doc, char const *filename) override
Descends into the SVG tree, mapping things to ODF when appropriate.
Definition odf.cpp:2041
void preprocess(ZipFile &zf, SPDocument *doc, Inkscape::XML::Node *node)
FIRST PASS.
Definition odf.cpp:993
bool writeContentFooter(Writer &outs)
Write the footer for the content.xml file.
Definition odf.cpp:1948
bool processStyle(SPItem *item, const Glib::ustring &id, const Glib::ustring &gradientNameFill, const Glib::ustring &gradientNameStroke, Glib::ustring &output)
Definition odf.cpp:1273
std::vector< GradientInfo > gradientTable
Definition odf.h:288
void reset()
Resets class to its pristine condition, ready to use again.
Definition odf.cpp:2027
bool writeManifest(ZipFile &zf)
Writes the manifest.
Definition odf.cpp:1065
bool writeTree(Writer &couts, Writer &souts, SPDocument *doc, Inkscape::XML::Node *node)
SECOND PASS.
Definition odf.cpp:1565
std::vector< StyleInfo > styleTable
Definition odf.h:283
bool writeMeta(ZipFile &zf)
This writes the document meta information to meta.xml.
Definition odf.cpp:1123
std::map< Glib::ustring, Glib::ustring > metadata
Definition odf.h:272
static void init()
This is the definition of PovRay output.
Definition odf.cpp:2080
bool writeStyleHeader(Writer &outs)
Write the header for the content.xml file.
Definition odf.cpp:1770
bool writeContent(ZipFile &zf, SPDocument *doc)
Write the content.xml file.
Definition odf.cpp:1966
bool processGradient(SPItem *item, const Glib::ustring &id, Geom::Affine &tf, Glib::ustring &gradientName, Glib::ustring &output, bool checkFillGradient=true)
Definition odf.cpp:1399
bool writeStyleFooter(Writer &outs)
Write the footer for the style.xml file.
Definition odf.cpp:1833
bool equals(const StyleInfo &other)
Definition odf.h:85
void assign(const StyleInfo &other)
Definition odf.h:57
StyleInfo(const StyleInfo &other)
Definition odf.h:46
StyleInfo & operator=(const StyleInfo &other)
Definition odf.h:51
This interface and its descendants are for unicode character-oriented output.
Interface for refcounted XML nodes.
Definition node.h:80
Typed SVG document implementation.
Definition document.h:101
Base class for visual SVG elements.
Definition sp-item.h:109
This class sits over the zlib and gzip code to implement a PKWare or Info-Zip .zip file reader and wr...
Definition ziptool.h:395
SPItem * item
Inkscape::XML::Node * node
Various utility functions.
Definition affine.h:22
Inkscape::IO::Writer Writer
Definition odf.h:35