1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libcdr project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef __CDRTYPES_H__
11 #define __CDRTYPES_H__
12 
13 #include <utility>
14 #include <vector>
15 #include <math.h>
16 #include <librevenge/librevenge.h>
17 #include "CDRTransforms.h"
18 #include "CDRPath.h"
19 #include "libcdr_utils.h"
20 
21 namespace libcdr
22 {
23 
24 struct CDRBox
25 {
26   double m_x;
27   double m_y;
28   double m_w;
29   double m_h;
CDRBoxCDRBox30   CDRBox()
31     : m_x(0.0), m_y(0.0), m_w(0.0), m_h(0.0) {}
CDRBoxCDRBox32   CDRBox(double x0, double y0, double x1, double y1)
33     : m_x(x0 < x1 ? x0 : x1), m_y(y0 < y1 ? y0 : y1), m_w(fabs(x1-x0)), m_h(fabs(y1-y0)) {}
getWidthCDRBox34   double getWidth() const
35   {
36     return m_w;
37   }
getHeightCDRBox38   double getHeight() const
39   {
40     return m_h;
41   }
getMinXCDRBox42   double getMinX() const
43   {
44     return m_x;
45   }
getMinYCDRBox46   double getMinY() const
47   {
48     return m_y;
49   }
50 
51 };
52 
53 struct CDRColor
54 {
55   unsigned short m_colorModel;
56   unsigned short m_colorPalette;
57   unsigned m_colorValue;
CDRColorCDRColor58   CDRColor(unsigned short colorModel, unsigned short colorPalette, unsigned colorValue)
59     : m_colorModel(colorModel), m_colorPalette(colorPalette), m_colorValue(colorValue) {}
CDRColorCDRColor60   CDRColor()
61     : m_colorModel(0), m_colorPalette(0), m_colorValue(0) {}
CDRColorCDRColor62   CDRColor(unsigned short colorModel, unsigned colorValue)
63     : m_colorModel(colorModel), m_colorPalette(0), m_colorValue(colorValue) {}
64 };
65 
66 struct CDRGradientStop
67 {
68   CDRColor m_color;
69   double m_offset;
CDRGradientStopCDRGradientStop70   CDRGradientStop() : m_color(), m_offset(0.0) {}
CDRGradientStopCDRGradientStop71   CDRGradientStop(const CDRColor &color, double offset)
72     : m_color(color), m_offset(offset) {}
73 };
74 
75 struct CDRGradient
76 {
77   unsigned char m_type;
78   unsigned char m_mode;
79   double m_angle;
80   double m_midPoint;
81   int m_edgeOffset;
82   int m_centerXOffset;
83   int m_centerYOffset;
84   std::vector<CDRGradientStop> m_stops;
CDRGradientCDRGradient85   CDRGradient()
86     : 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() {}
87 };
88 
89 struct CDRImageFill
90 {
91   unsigned id;
92   double width;
93   double height;
94   bool isRelative;
95   double xOffset;
96   double yOffset;
97   double rcpOffset;
98   unsigned char flags;
CDRImageFillCDRImageFill99   CDRImageFill() : id(0), width(0.0), height(0.0), isRelative(false), xOffset(0.0), yOffset(0.0), rcpOffset(0.0), flags(0)
100   {}
CDRImageFillCDRImageFill101   CDRImageFill(unsigned i, double w, double h, bool r, double x, double y, double o, unsigned char f)
102     : id(i), width(w), height(h), isRelative(r), xOffset(x), yOffset(y), rcpOffset(o), flags(f) {}
103 };
104 
105 struct CDRFillStyle
106 {
107   unsigned short fillType;
108   CDRColor color1, color2;
109   CDRGradient gradient;
110   CDRImageFill imageFill;
CDRFillStyleCDRFillStyle111   CDRFillStyle()
112     : fillType((unsigned short)-1), color1(), color2(), gradient(), imageFill() {}
CDRFillStyleCDRFillStyle113   CDRFillStyle(unsigned short ft, CDRColor c1, CDRColor c2, const CDRGradient &gr, const CDRImageFill &img)
114     : fillType(ft), color1(c1), color2(c2), gradient(gr), imageFill(img) {}
115 };
116 
117 struct CDRLineStyle
118 {
119   unsigned short lineType;
120   unsigned short capsType;
121   unsigned short joinType;
122   double lineWidth;
123   double stretch;
124   double angle;
125   CDRColor color;
126   std::vector<unsigned> dashArray;
127   CDRPath startMarker;
128   CDRPath endMarker;
CDRLineStyleCDRLineStyle129   CDRLineStyle()
130     : lineType((unsigned short)-1), capsType(0), joinType(0), lineWidth(0.0),
131       stretch(0.0), angle(0.0), color(), dashArray(),
132       startMarker(), endMarker() {}
CDRLineStyleCDRLineStyle133   CDRLineStyle(unsigned short lt, unsigned short ct, unsigned short jt,
134                double lw, double st, double a, const CDRColor &c, const std::vector<unsigned> &da,
135                const CDRPath &sm, const CDRPath &em)
136     : lineType(lt), capsType(ct), joinType(jt), lineWidth(lw),
137       stretch(st), angle(a), color(c), dashArray(da),
138       startMarker(sm), endMarker(em) {}
139 };
140 
141 struct CDRStyle
142 {
143   unsigned short m_charSet;
144   librevenge::RVNGString m_fontName;
145   double m_fontSize;
146   unsigned m_align;
147   double m_leftIndent, m_firstIndent, m_rightIndent;
148   CDRLineStyle m_lineStyle;
149   CDRFillStyle m_fillStyle;
150   unsigned m_parentId;
CDRStyleCDRStyle151   CDRStyle()
152     : m_charSet((unsigned short)-1), m_fontName(),
153       m_fontSize(0.0), m_align(0), m_leftIndent(0.0), m_firstIndent(0.0),
154       m_rightIndent(0.0), m_lineStyle(), m_fillStyle(), m_parentId(0)
155   {
156     m_fontName.clear();
157   }
overrideStyleCDRStyle158   void overrideStyle(const CDRStyle &override)
159   {
160     if (override.m_charSet != (unsigned short)-1 || override.m_fontName.len())
161     {
162       m_charSet = override.m_charSet;
163       m_fontName = override.m_fontName;
164     }
165     if (!CDR_ALMOST_ZERO(override.m_fontSize))
166       m_fontSize = override.m_fontSize;
167     if (override.m_align)
168       m_align = override.m_align;
169     if (override.m_leftIndent != 0.0 && override.m_firstIndent != 0.0 && override.m_rightIndent != 0.0)
170     {
171       m_leftIndent = override.m_leftIndent;
172       m_firstIndent = override.m_firstIndent;
173       m_rightIndent = override.m_rightIndent;
174     }
175     if (override.m_lineStyle.lineType != (unsigned short)-1)
176       m_lineStyle = override.m_lineStyle;
177     if (override.m_fillStyle.fillType != (unsigned short)-1)
178       m_fillStyle = override.m_fillStyle;
179   }
180 };
181 
182 struct CDRPolygon
183 {
184   unsigned m_numAngles;
185   unsigned m_nextPoint;
186   double m_rx;
187   double m_ry;
188   double m_cx;
189   double m_cy;
CDRPolygonCDRPolygon190   CDRPolygon() : m_numAngles(0), m_nextPoint(0), m_rx(0.0), m_ry(0.0), m_cx(0.0), m_cy(0.0) {}
CDRPolygonCDRPolygon191   CDRPolygon(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy)
192     : m_numAngles(numAngles), m_nextPoint(nextPoint), m_rx(rx), m_ry(ry), m_cx(cx), m_cy(cy) {}
193   void create(CDRPath &path) const;
194 };
195 
196 struct CDRImage
197 {
198   librevenge::RVNGBinaryData m_image;
199   double m_x1;
200   double m_x2;
201   double m_y1;
202   double m_y2;
CDRImageCDRImage203   CDRImage() : m_image(), m_x1(0.0), m_x2(0.0), m_y1(0.0), m_y2(0.0) {}
CDRImageCDRImage204   CDRImage(const librevenge::RVNGBinaryData &image, double x1, double x2, double y1, double y2)
205     : m_image(image), m_x1(x1), m_x2(x2), m_y1(y1), m_y2(y2) {}
getMiddleXCDRImage206   double getMiddleX() const
207   {
208     return (m_x1 + m_x2) / 2.0;
209   }
getMiddleYCDRImage210   double getMiddleY() const
211   {
212     return (m_y1 + m_y2) / 2.0;
213   }
getImageCDRImage214   const librevenge::RVNGBinaryData &getImage() const
215   {
216     return m_image;
217   }
218 };
219 
220 struct CDRPattern
221 {
222   unsigned width;
223   unsigned height;
224   std::vector<unsigned char> pattern;
CDRPatternCDRPattern225   CDRPattern() : width(0), height(0), pattern() {}
CDRPatternCDRPattern226   CDRPattern(unsigned w, unsigned h, const std::vector<unsigned char> &p)
227     : width(w), height(h), pattern(p) {}
228 };
229 
230 struct CDRBitmap
231 {
232   unsigned colorModel;
233   unsigned width;
234   unsigned height;
235   unsigned bpp;
236   std::vector<unsigned> palette;
237   std::vector<unsigned char> bitmap;
CDRBitmapCDRBitmap238   CDRBitmap() : colorModel(0), width(0), height(0), bpp(0), palette(), bitmap() {}
CDRBitmapCDRBitmap239   CDRBitmap(unsigned cm, unsigned w, unsigned h, unsigned b, const std::vector<unsigned> &p, const std::vector<unsigned char> &bmp)
240     : colorModel(cm), width(w), height(h), bpp(b), palette(p), bitmap(bmp) {}
241 };
242 
243 struct CDRPage
244 {
245   double width;
246   double height;
247   double offsetX;
248   double offsetY;
CDRPageCDRPage249   CDRPage() : width(0.0), height(0.0), offsetX(0.0), offsetY(0.0) {}
CDRPageCDRPage250   CDRPage(double w, double h, double ox, double oy)
251     : width(w), height(h), offsetX(ox), offsetY(oy) {}
252 };
253 
254 struct CDRSplineData
255 {
256   std::vector<std::pair<double, double> > points;
257   std::vector<unsigned> knotVector;
CDRSplineDataCDRSplineData258   CDRSplineData() : points(), knotVector() {}
CDRSplineDataCDRSplineData259   CDRSplineData(const std::vector<std::pair<double, double> > &ps, const std::vector<unsigned> &kntv)
260     : points(ps), knotVector(kntv) {}
clearCDRSplineData261   void clear()
262   {
263     points.clear();
264     knotVector.clear();
265   }
emptyCDRSplineData266   bool empty()
267   {
268     return (points.empty() || knotVector.empty());
269   }
270   void create(CDRPath &path) const;
271 };
272 
273 struct WaldoRecordInfo
274 {
WaldoRecordInfoWaldoRecordInfo275   WaldoRecordInfo(unsigned char t, unsigned i, unsigned o)
276     : type(t), id(i), offset(o) {}
WaldoRecordInfoWaldoRecordInfo277   WaldoRecordInfo() : type(0), id(0), offset(0) {}
278   unsigned char type;
279   unsigned id;
280   unsigned offset;
281 };
282 
283 struct WaldoRecordType1
284 {
WaldoRecordType1WaldoRecordType1285   WaldoRecordType1(unsigned id, unsigned short next, unsigned short previous,
286                    unsigned short child, unsigned short parent, unsigned short flags,
287                    double x0, double y0, double x1, double y1, const CDRTransform &trafo)
288     : m_id(id), m_next(next), m_previous(previous), m_child(child), m_parent(parent),
289       m_flags(flags), m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1), m_trafo(trafo) {}
WaldoRecordType1WaldoRecordType1290   WaldoRecordType1()
291     : m_id(0), m_next(0), m_previous(0), m_child(0), m_parent(0), m_flags(0),
292       m_x0(0.0), m_y0(0.0), m_x1(0.0), m_y1(0.0), m_trafo() {}
293   unsigned m_id;
294   unsigned short m_next;
295   unsigned short m_previous;
296   unsigned short m_child;
297   unsigned short m_parent;
298   unsigned short m_flags;
299   double m_x0;
300   double m_y0;
301   double m_x1;
302   double m_y1;
303   CDRTransform m_trafo;
304 };
305 
306 struct CDRCMYKColor
307 {
CDRCMYKColorCDRCMYKColor308   CDRCMYKColor(double cyan, double magenta, double yellow, double black)
309     : c(cyan), m(magenta), y(yellow), k(black) {}
~CDRCMYKColorCDRCMYKColor310   ~CDRCMYKColor() {}
311   double c;
312   double m;
313   double y;
314   double k;
315 };
316 
317 struct CDRRGBColor
318 {
CDRRGBColorCDRRGBColor319   CDRRGBColor(double red, double green, double blue)
320     : r(red), g(green), b(blue) {}
~CDRRGBColorCDRRGBColor321   ~CDRRGBColor() {}
322   double r;
323   double g;
324   double b;
325 };
326 
327 struct CDRLab2Color
328 {
CDRLab2ColorCDRLab2Color329   CDRLab2Color(double l, double A, double B)
330     : L(l), a(A), b(B) {}
~CDRLab2ColorCDRLab2Color331   ~CDRLab2Color() {}
332   double L;
333   double a;
334   double b;
335 };
336 
337 struct CDRLab4Color
338 {
CDRLab4ColorCDRLab4Color339   CDRLab4Color(double l, double A, double B)
340     : L(l), a(A), b(B) {}
~CDRLab4ColorCDRLab4Color341   ~CDRLab4Color() {}
342   double L;
343   double a;
344   double b;
345 };
346 
347 struct CDRText
348 {
CDRTextCDRText349   CDRText() : m_text(), m_style() {}
CDRTextCDRText350   CDRText(const librevenge::RVNGString &text, const CDRStyle &style)
351     : m_text(text), m_style(style) {}
352   librevenge::RVNGString m_text;
353   CDRStyle m_style;
354 };
355 
356 struct CDRTextLine
357 {
CDRTextLineCDRTextLine358   CDRTextLine() : m_line() {}
CDRTextLineCDRTextLine359   CDRTextLine(const CDRTextLine &line) : m_line(line.m_line) {}
appendCDRTextLine360   void append(const CDRText &text)
361   {
362     m_line.push_back(text);
363   }
clearCDRTextLine364   void clear()
365   {
366     m_line.clear();
367   }
368   std::vector<CDRText> m_line;
369 };
370 
371 struct CDRFont
372 {
CDRFontCDRFont373   CDRFont() : m_name(), m_encoding(0) {}
CDRFontCDRFont374   CDRFont(const librevenge::RVNGString &name, unsigned short encoding)
375     : m_name(name), m_encoding(encoding) {}
376   CDRFont(const CDRFont &font) = default;
377   CDRFont &operator=(const CDRFont &font) = default;
378   librevenge::RVNGString m_name;
379   unsigned short m_encoding;
380 };
381 
382 } // namespace libcdr
383 
384 #endif /* __CDRTYPES_H__ */
385 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
386