Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* libcdr
3 : * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
24 : * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
25 : * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #ifndef __CDRTYPES_H__
30 : #define __CDRTYPES_H__
31 :
32 : #include <vector>
33 : #include <math.h>
34 : #include <libwpd/libwpd.h>
35 : #include "CDRTransforms.h"
36 :
37 : namespace libcdr
38 : {
39 : class CDRPath;
40 :
41 : struct CDRBBox
42 : {
43 : double m_x;
44 : double m_y;
45 : double m_w;
46 : double m_h;
47 0 : CDRBBox()
48 0 : : m_x(0.0), m_y(0.0), m_w(0.0), m_h(0.0) {}
49 0 : CDRBBox(double x0, double y0, double x1, double y1)
50 0 : : m_x(x0 < x1 ? x0 : x1), m_y(y0 < y1 ? y0 : y1), m_w(fabs(x1-x0)), m_h(fabs(y1-y0)) {}
51 0 : double getWidth() const
52 : {
53 0 : return m_w;
54 : }
55 0 : double getHeight() const
56 : {
57 0 : return m_h;
58 : }
59 0 : double getMinX() const
60 : {
61 0 : return m_x;
62 : }
63 0 : double getMinY() const
64 : {
65 0 : return m_y;
66 : }
67 :
68 : };
69 :
70 : struct CDRColor
71 : {
72 : unsigned short m_colorModel;
73 : unsigned m_colorValue;
74 0 : CDRColor() : m_colorModel(0), m_colorValue(0) {}
75 0 : CDRColor(unsigned short colorModel, unsigned colorValue)
76 0 : : m_colorModel(colorModel), m_colorValue(colorValue) {}
77 : };
78 :
79 : struct CDRGradientStop
80 : {
81 : CDRColor m_color;
82 : double m_offset;
83 0 : CDRGradientStop() : m_color(), m_offset(0.0) {}
84 : CDRGradientStop(const CDRColor &color, double offset)
85 : : m_color(color), m_offset(offset) {}
86 : };
87 :
88 0 : struct CDRGradient
89 : {
90 : unsigned char m_type;
91 : unsigned char m_mode;
92 : double m_angle;
93 : double m_midPoint;
94 : int m_edgeOffset;
95 : int m_centerXOffset;
96 : int m_centerYOffset;
97 : std::vector<CDRGradientStop> m_stops;
98 0 : CDRGradient()
99 0 : : m_type(0), m_mode(0), m_angle(0.0), m_midPoint(0.0), m_edgeOffset(0), m_centerXOffset(0), m_centerYOffset(0), m_stops() {}
100 : };
101 :
102 : struct CDRImageFill
103 : {
104 : unsigned id;
105 : double width;
106 : double height;
107 : bool isRelative;
108 : double xOffset;
109 : double yOffset;
110 : double rcpOffset;
111 : unsigned char flags;
112 0 : CDRImageFill() : id(0), width(0.0), height(0.0), isRelative(false), xOffset(0.0), yOffset(0.0), rcpOffset(0.0), flags(0)
113 0 : {}
114 0 : CDRImageFill(unsigned i, double w, double h, bool r, double x, double y, double o, unsigned char f)
115 0 : : id(i), width(w), height(h), isRelative(r), xOffset(x), yOffset(y), rcpOffset(o), flags(f) {}
116 : };
117 :
118 0 : struct CDRFillStyle
119 : {
120 : unsigned short fillType;
121 : CDRColor color1, color2;
122 : CDRGradient gradient;
123 : CDRImageFill imageFill;
124 0 : CDRFillStyle()
125 0 : : fillType(0), color1(), color2(), gradient(), imageFill() {}
126 0 : CDRFillStyle(unsigned short ft, CDRColor c1, CDRColor c2, const CDRGradient &gr, const CDRImageFill &img)
127 0 : : fillType(ft), color1(c1), color2(c2), gradient(gr), imageFill(img) {}
128 : };
129 :
130 0 : struct CDRLineStyle
131 : {
132 : unsigned short lineType;
133 : unsigned short capsType;
134 : unsigned short joinType;
135 : double lineWidth;
136 : double stretch;
137 : double angle;
138 : CDRColor color;
139 : std::vector<unsigned> dashArray;
140 : unsigned startMarkerId;
141 : unsigned endMarkerId;
142 0 : CDRLineStyle()
143 : : lineType(0), capsType(0), joinType(0), lineWidth(0.0),
144 : stretch(0.0), angle(0.0), color(), dashArray(),
145 0 : startMarkerId(0), endMarkerId(0) {}
146 0 : CDRLineStyle(unsigned short lt, unsigned short ct, unsigned short jt,
147 : double lw, double st, double a, const CDRColor &c, const std::vector<unsigned> &da,
148 : unsigned smi, unsigned emi)
149 : : lineType(lt), capsType(ct), joinType(jt), lineWidth(lw),
150 : stretch(st), angle(a), color(c), dashArray(da),
151 0 : startMarkerId(smi), endMarkerId(emi) {}
152 : };
153 :
154 : struct CDRCharacterStyle
155 : {
156 : unsigned short m_charSet;
157 : unsigned short m_fontId;
158 : double m_fontSize;
159 0 : CDRCharacterStyle()
160 0 : : m_charSet(0), m_fontId(0), m_fontSize(0.0) {}
161 : CDRCharacterStyle(unsigned short charSet, unsigned short fontId, double fontSize)
162 : : m_charSet(charSet), m_fontId(fontId), m_fontSize(fontSize) {}
163 0 : void overrideCharacterStyle(const CDRCharacterStyle &override)
164 : {
165 0 : if (override.m_charSet)
166 0 : m_charSet = override.m_charSet;
167 0 : if (override.m_fontId)
168 0 : m_fontId = override.m_fontId;
169 0 : if (override.m_fontSize > 0.0)
170 0 : m_fontSize = override.m_fontSize;
171 0 : }
172 : };
173 :
174 : struct CDRPolygon
175 : {
176 : unsigned m_numAngles;
177 : unsigned m_nextPoint;
178 : double m_rx;
179 : double m_ry;
180 : double m_cx;
181 : double m_cy;
182 : CDRPolygon() : m_numAngles(0), m_nextPoint(0), m_rx(0.0), m_ry(0.0), m_cx(0.0), m_cy(0.0) {}
183 0 : CDRPolygon(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy)
184 0 : : m_numAngles(numAngles), m_nextPoint(nextPoint), m_rx(rx), m_ry(ry), m_cx(cx), m_cy(cy) {}
185 : void create(CDRPath &path) const;
186 : };
187 :
188 0 : struct CDRImage
189 : {
190 : WPXBinaryData m_image;
191 : double m_x1;
192 : double m_x2;
193 : double m_y1;
194 : double m_y2;
195 0 : CDRImage() : m_image(), m_x1(0.0), m_x2(0.0), m_y1(0.0), m_y2(0.0) {}
196 0 : CDRImage(const WPXBinaryData &image, double x1, double x2, double y1, double y2)
197 0 : : m_image(image), m_x1(x1), m_x2(x2), m_y1(y1), m_y2(y2) {}
198 0 : double getMiddleX() const
199 : {
200 0 : return (m_x1 + m_x2) / 2.0;
201 : }
202 0 : double getMiddleY() const
203 : {
204 0 : return (m_y1 + m_y2) / 2.0;
205 : }
206 0 : double getWidth() const
207 : {
208 0 : return fabs(m_x1 - m_x2);
209 : }
210 0 : double getHeight() const
211 : {
212 0 : return fabs(m_y1 - m_y2);
213 : }
214 0 : const WPXBinaryData &getImage() const
215 : {
216 0 : return m_image;
217 : }
218 : };
219 :
220 0 : struct CDRPattern
221 : {
222 : unsigned width;
223 : unsigned height;
224 : std::vector<unsigned char> pattern;
225 0 : CDRPattern() : width(0), height(0), pattern() {}
226 0 : CDRPattern(unsigned w, unsigned h, const std::vector<unsigned char> &p)
227 0 : : width(w), height(h), pattern(p) {}
228 : };
229 :
230 : struct CDRPage
231 : {
232 : double width;
233 : double height;
234 : double offsetX;
235 : double offsetY;
236 : CDRPage() : width(0.0), height(0.0), offsetX(0.0), offsetY(0.0) {}
237 0 : CDRPage(double w, double h, double ox, double oy)
238 0 : : width(w), height(h), offsetX(ox), offsetY(oy) {}
239 : };
240 :
241 0 : struct CDRSplineData
242 : {
243 : std::vector<std::pair<double, double> > points;
244 : std::vector<unsigned> knotVector;
245 0 : CDRSplineData() : points(), knotVector() {}
246 0 : CDRSplineData(const std::vector<std::pair<double, double> > &ps, const std::vector<unsigned> &kntv)
247 0 : : points(ps), knotVector(kntv) {}
248 0 : void clear()
249 : {
250 0 : points.clear();
251 0 : knotVector.clear();
252 0 : }
253 0 : bool empty()
254 : {
255 0 : return (points.empty() || knotVector.empty());
256 : }
257 : void create(CDRPath &path) const;
258 : };
259 :
260 : struct WaldoRecordInfo
261 : {
262 0 : WaldoRecordInfo(unsigned char t, unsigned i, unsigned o)
263 0 : : type(t), id(i), offset(o) {}
264 0 : WaldoRecordInfo() : type(0), id(0), offset(0) {}
265 : unsigned char type;
266 : unsigned id;
267 : unsigned offset;
268 : };
269 :
270 0 : struct WaldoRecordType1
271 : {
272 0 : WaldoRecordType1(unsigned id, unsigned short next, unsigned short previous,
273 : unsigned short child, unsigned short parent, unsigned short flags,
274 : double x0, double y0, double x1, double y1, const CDRTransform &trafo)
275 : : m_id(id), m_next(next), m_previous(previous), m_child(child), m_parent(parent),
276 0 : m_flags(flags), m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1), m_trafo(trafo) {}
277 0 : WaldoRecordType1()
278 : : m_id(0), m_next(0), m_previous(0), m_child(0), m_parent(0), m_flags(0),
279 0 : m_x0(0.0), m_y0(0.0), m_x1(0.0), m_y1(0.0), m_trafo() {}
280 : unsigned m_id;
281 : unsigned short m_next;
282 : unsigned short m_previous;
283 : unsigned short m_child;
284 : unsigned short m_parent;
285 : unsigned short m_flags;
286 : double m_x0;
287 : double m_y0;
288 : double m_x1;
289 : double m_y1;
290 : CDRTransform m_trafo;
291 : };
292 :
293 : struct CDRCMYKColor
294 : {
295 : CDRCMYKColor(unsigned colorValue, bool percentage = true);
296 : CDRCMYKColor(double cyan, double magenta, double yellow, double black)
297 : : c(cyan), m(magenta), y(yellow), k(black) {}
298 : ~CDRCMYKColor() {}
299 : double c;
300 : double m;
301 : double y;
302 : double k;
303 : void applyTint(double tint);
304 : unsigned getColorValue() const;
305 : };
306 :
307 : struct CDRRGBColor
308 : {
309 : CDRRGBColor(unsigned colorValue);
310 : CDRRGBColor(double red, double green, double blue)
311 : : r(red), g(green), b(blue) {}
312 : ~CDRRGBColor() {}
313 : double r;
314 : double g;
315 : double b;
316 : void applyTint(double tint);
317 : unsigned getColorValue() const;
318 : };
319 :
320 : struct CDRLab2Color
321 : {
322 : CDRLab2Color(unsigned colorValue);
323 : CDRLab2Color(double l, double A, double B)
324 : : L(l), a(A), b(B) {}
325 : ~CDRLab2Color() {}
326 : double L;
327 : double a;
328 : double b;
329 : void applyTint(double tint);
330 : unsigned getColorValue() const;
331 : };
332 :
333 : struct CDRLab4Color
334 : {
335 : CDRLab4Color(unsigned colorValue);
336 : CDRLab4Color(double l, double A, double B)
337 : : L(l), a(A), b(B) {}
338 : ~CDRLab4Color() {}
339 : double L;
340 : double a;
341 : double b;
342 : void applyTint(double tint);
343 : unsigned getColorValue() const;
344 : };
345 :
346 0 : struct CDRText
347 : {
348 0 : CDRText() : m_text(), m_charStyle() {}
349 0 : CDRText(const WPXString &text, const CDRCharacterStyle &charStyle)
350 0 : : m_text(text), m_charStyle(charStyle) {}
351 : WPXString m_text;
352 : CDRCharacterStyle m_charStyle;
353 : };
354 :
355 : } // namespace libcdr
356 :
357 : #endif /* __CDRTYPES_H__ */
358 : /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
|