CDRTypes.h
Go to the documentation of this file.
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;
48  : m_x(0.0), m_y(0.0), m_w(0.0), m_h(0.0) {}
49  CDRBBox(double x0, double y0, double x1, double y1)
50  : m_x(x0 < x1 ? x0 : x1), m_y(y0 < y1 ? y0 : y1), m_w(fabs(x1-x0)), m_h(fabs(y1-y0)) {}
51  double getWidth() const
52  {
53  return m_w;
54  }
55  double getHeight() const
56  {
57  return m_h;
58  }
59  double getMinX() const
60  {
61  return m_x;
62  }
63  double getMinY() const
64  {
65  return m_y;
66  }
67 
68 };
69 
70 struct CDRColor
71 {
72  unsigned short m_colorModel;
73  unsigned m_colorValue;
75  CDRColor(unsigned short colorModel, unsigned colorValue)
76  : m_colorModel(colorModel), m_colorValue(colorValue) {}
77 };
78 
80 {
82  double m_offset;
84  CDRGradientStop(const CDRColor &color, double offset)
85  : m_color(color), m_offset(offset) {}
86 };
87 
89 {
90  unsigned char m_type;
91  unsigned char m_mode;
92  double m_angle;
93  double m_midPoint;
97  std::vector<CDRGradientStop> m_stops;
99  : 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 
103 {
104  unsigned id;
105  double width;
106  double height;
108  double xOffset;
109  double yOffset;
110  double rcpOffset;
111  unsigned char flags;
112  CDRImageFill() : id(0), width(0.0), height(0.0), isRelative(false), xOffset(0.0), yOffset(0.0), rcpOffset(0.0), flags(0)
113  {}
114  CDRImageFill(unsigned i, double w, double h, bool r, double x, double y, double o, unsigned char f)
115  : id(i), width(w), height(h), isRelative(r), xOffset(x), yOffset(y), rcpOffset(o), flags(f) {}
116 };
117 
119 {
120  unsigned short fillType;
125  : fillType(0), color1(), color2(), gradient(), imageFill() {}
126  CDRFillStyle(unsigned short ft, CDRColor c1, CDRColor c2, const CDRGradient &gr, const CDRImageFill &img)
127  : fillType(ft), color1(c1), color2(c2), gradient(gr), imageFill(img) {}
128 };
129 
131 {
132  unsigned short lineType;
133  unsigned short capsType;
134  unsigned short joinType;
135  double lineWidth;
136  double stretch;
137  double angle;
139  std::vector<unsigned short> dashArray;
140  unsigned startMarkerId;
141  unsigned endMarkerId;
143  : lineType(0), capsType(0), joinType(0), lineWidth(0.0),
144  stretch(0.0), angle(0.0), color(), dashArray(),
145  startMarkerId(0), endMarkerId(0) {}
146  CDRLineStyle(unsigned short lt, unsigned short ct, unsigned short jt,
147  double lw, double st, double a, const CDRColor &c, const std::vector<unsigned short> &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  startMarkerId(smi), endMarkerId(emi) {}
152 };
153 
155 {
156  unsigned short m_charSet;
157  unsigned short m_fontId;
158  double m_fontSize;
160  : 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) {}
164  {
165  if (override.m_charSet)
166  m_charSet = override.m_charSet;
167  if (override.m_fontId)
168  m_fontId = override.m_fontId;
169  if (override.m_fontSize > 0.0)
170  m_fontSize = override.m_fontSize;
171  }
172 };
173 
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  CDRPolygon(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy)
184  : 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 struct CDRImage
189 {
190  WPXBinaryData m_image;
191  double m_x1;
192  double m_x2;
193  double m_y1;
194  double m_y2;
195  CDRImage() : m_image(), m_x1(0.0), m_x2(0.0), m_y1(0.0), m_y2(0.0) {}
196  CDRImage(const WPXBinaryData &image, double x1, double x2, double y1, double y2)
197  : m_image(image), m_x1(x1), m_x2(x2), m_y1(y1), m_y2(y2) {}
198  double getMiddleX() const
199  {
200  return (m_x1 + m_x2) / 2.0;
201  }
202  double getMiddleY() const
203  {
204  return (m_y1 + m_y2) / 2.0;
205  }
206  double getWidth() const
207  {
208  return fabs(m_x1 - m_x2);
209  }
210  double getHeight() const
211  {
212  return fabs(m_y1 - m_y2);
213  }
214  const WPXBinaryData &getImage() const
215  {
216  return m_image;
217  }
218 };
219 
221 {
222  unsigned width;
223  unsigned height;
224  std::vector<unsigned char> pattern;
225  CDRPattern() : width(0), height(0), pattern() {}
226  CDRPattern(unsigned w, unsigned h, const std::vector<unsigned char> &p)
227  : 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  CDRPage(double w, double h, double ox, double oy)
238  : width(w), height(h), offsetX(ox), offsetY(oy) {}
239 };
240 
242 {
243  std::vector<std::pair<double, double> > points;
244  std::vector<unsigned> knotVector;
246  CDRSplineData(const std::vector<std::pair<double, double> > &ps, const std::vector<unsigned> &kntv)
247  : points(ps), knotVector(kntv) {}
248  void clear()
249  {
250  points.clear();
251  knotVector.clear();
252  }
253  bool empty()
254  {
255  return (points.empty() || knotVector.empty());
256  }
257  void create(CDRPath &path) const;
258 };
259 
261 {
262  WaldoRecordInfo(unsigned char t, unsigned i, unsigned o)
263  : type(t), id(i), offset(o) {}
264  WaldoRecordInfo() : type(0), id(0), offset(0) {}
265  unsigned char type;
266  unsigned id;
267  unsigned offset;
268 };
269 
271 {
272  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  m_flags(flags), m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1), m_trafo(trafo) {}
278  : m_id(0), m_next(0), m_previous(0), m_child(0), m_parent(0), m_flags(0),
279  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;
291 };
292 
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) {}
299  double c;
300  double m;
301  double y;
302  double k;
303  void applyTint(double tint);
304  unsigned getColorValue() const;
305 };
306 
308 {
309  CDRRGBColor(unsigned colorValue);
310  CDRRGBColor(double red, double green, double blue)
311  : r(red), g(green), b(blue) {}
313  double r;
314  double g;
315  double b;
316  void applyTint(double tint);
317  unsigned getColorValue() const;
318 };
319 
321 {
322  CDRLab2Color(unsigned colorValue);
323  CDRLab2Color(double l, double A, double B)
324  : L(l), a(A), b(B) {}
326  double L;
327  double a;
328  double b;
329  void applyTint(double tint);
330  unsigned getColorValue() const;
331 };
332 
334 {
335  CDRLab4Color(unsigned colorValue);
336  CDRLab4Color(double l, double A, double B)
337  : L(l), a(A), b(B) {}
339  double L;
340  double a;
341  double b;
342  void applyTint(double tint);
343  unsigned getColorValue() const;
344 };
345 
346 struct CDRText
347 {
349  CDRText(const WPXString &text, const CDRCharacterStyle &charStyle)
350  : m_text(text), m_charStyle(charStyle) {}
351  WPXString m_text;
353 };
354 
355 } // namespace libcdr
356 
357 #endif /* __CDRTYPES_H__ */
358 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libcdr by doxygen 1.8.2