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 
36 namespace libcdr
37 {
38 class CDRPath;
39 
41 {
42  double m_v0;
43  double m_v1;
44  double m_x0;
45  double m_v3;
46  double m_v4;
47  double m_y0;
49  : m_v0(1.0), m_v1(0.0), m_x0(0.0),
50  m_v3(0.0), m_v4(1.0), m_y0(0.0) {}
51  CDRTransform(double v0, double v1, double x0, double v3, double v4, double y0)
52  : m_v0(v0), m_v1(v1), m_x0(x0), m_v3(v3), m_v4(v4), m_y0(y0) {}
53 
54  void applyToPoint(double &x, double &y) const;
55  void applyToArc(double &rx, double &ry, double &rotation, bool &sweep, double &x, double &y) const;
56 };
57 
58 struct CDRBBox
59 {
60  double m_x;
61  double m_y;
62  double m_w;
63  double m_h;
65  : m_x(0.0), m_y(0.0), m_w(0.0), m_h(0.0) {}
66  CDRBBox(const CDRBBox &box)
67  : m_x(box.m_x), m_y(box.m_y), m_w(box.m_w), m_h(box.m_h) {}
68  CDRBBox(double x0, double y0, double x1, double y1)
69  : m_x(x0 < x1 ? x0 : x1), m_y(y0 < y1 ? y0 : y1), m_w(fabs(x1-x0)), m_h(fabs(y1-y0)) {}
70  double getWidth() const
71  {
72  return m_w;
73  }
74  double getHeight() const
75  {
76  return m_h;
77  }
78  double getMinX() const
79  {
80  return m_x;
81  }
82  double getMinY() const
83  {
84  return m_y;
85  }
86 
87 };
88 
89 struct CDRColor
90 {
91  unsigned short m_colorModel;
92  unsigned m_colorValue;
94  CDRColor(unsigned short colorModel, unsigned colorValue)
95  : m_colorModel(colorModel), m_colorValue(colorValue) {}
96  CDRColor(const CDRColor &color)
98 };
99 
101 {
103  double m_offset;
105  CDRGradientStop(const CDRColor &color, double offset)
106  : m_color(color), m_offset(offset) {}
108  : m_color(stop.m_color), m_offset(stop.m_offset) {}
109 };
110 
112 {
113  unsigned char m_type;
114  unsigned char m_mode;
115  double m_angle;
116  double m_midPoint;
120  std::vector<CDRGradientStop> m_stops;
122  : 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() {}
123  CDRGradient(const CDRGradient &gradient)
124  : m_type(gradient.m_type), m_mode(gradient.m_mode), m_angle(gradient.m_angle), m_midPoint(gradient.m_midPoint),
126  m_stops(gradient.m_stops) {}
127 };
128 
130 {
131  unsigned id;
132  double width;
133  double height;
135  double xOffset;
136  double yOffset;
137  double rcpOffset;
138  unsigned char flags;
139  CDRImageFill() : id(0), width(0.0), height(0.0), isRelative(false), xOffset(0.0), yOffset(0.0), rcpOffset(0.0), flags(0)
140  {}
141  CDRImageFill(unsigned i, double w, double h, bool r, double x, double y, double o, unsigned char f)
142  : id(i), width(w), height(h), isRelative(r), xOffset(x), yOffset(y), rcpOffset(o), flags(f) {}
143 };
144 
146 {
147  unsigned short fillType;
152  : fillType(0), color1(), color2(), gradient(), imageFill() {}
153  CDRFillStyle(unsigned short ft, CDRColor c1, CDRColor c2, const CDRGradient &gr, const CDRImageFill &img)
154  : fillType(ft), color1(c1), color2(c2), gradient(gr), imageFill(img) {}
156  : fillType(style.fillType), color1(style.color1), color2(style.color2), gradient(style.gradient), imageFill(style.imageFill) {}
157 };
158 
160 {
161  unsigned short lineType;
162  unsigned short capsType;
163  unsigned short joinType;
164  double lineWidth;
165  double stretch;
166  double angle;
168  std::vector<unsigned short> dashArray;
169  unsigned startMarkerId;
170  unsigned endMarkerId;
172  : lineType(0), capsType(0), joinType(0), lineWidth(0.0),
173  stretch(0.0), angle(0.0), color(), dashArray(),
174  startMarkerId(0), endMarkerId(0) {}
175  CDRLineStyle(unsigned short lt, unsigned short ct, unsigned short jt,
176  double lw, double st, double a, const CDRColor &c, const std::vector<unsigned short> &da,
177  unsigned smi, unsigned emi)
178  : lineType(lt), capsType(ct), joinType(jt), lineWidth(lw),
179  stretch(st), angle(a), color(c), dashArray(da),
180  startMarkerId(smi), endMarkerId(emi) {}
181 };
182 
184 {
185  unsigned short m_charSet;
186  unsigned short m_fontId;
187  double m_fontSize;
189  : m_charSet(0), m_fontId(0), m_fontSize(0.0) {}
190  CDRCharacterStyle(unsigned short charSet, unsigned short fontId, double fontSize)
191  : m_charSet(charSet), m_fontId(fontId), m_fontSize(fontSize) {}
193  {
194  if (override.m_charSet)
195  m_charSet = override.m_charSet;
196  if (override.m_fontId)
197  m_fontId = override.m_fontId;
198  if (override.m_fontSize > 0.0)
199  m_fontSize = override.m_fontSize;
200  }
201 };
202 
204 {
205  unsigned m_numAngles;
206  unsigned m_nextPoint;
207  double m_rx;
208  double m_ry;
209  double m_cx;
210  double m_cy;
211  CDRPolygon() : m_numAngles(0), m_nextPoint(0), m_rx(0.0), m_ry(0.0), m_cx(0.0), m_cy(0.0) {}
212  CDRPolygon(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy)
213  : m_numAngles(numAngles), m_nextPoint(nextPoint), m_rx(rx), m_ry(ry), m_cx(cx), m_cy(cy) {}
214  void create(CDRPath &path) const;
215 };
216 
217 struct CDRImage
218 {
219  WPXBinaryData m_image;
220  double m_x1;
221  double m_x2;
222  double m_y1;
223  double m_y2;
224  CDRImage() : m_image(), m_x1(0.0), m_x2(0.0), m_y1(0.0), m_y2(0.0) {}
225  CDRImage(const WPXBinaryData &image, double x1, double x2, double y1, double y2)
226  : m_image(image), m_x1(x1), m_x2(x2), m_y1(y1), m_y2(y2) {}
227  double getMiddleX() const
228  {
229  return (m_x1 + m_x2) / 2.0;
230  }
231  double getMiddleY() const
232  {
233  return (m_y1 + m_y2) / 2.0;
234  }
235  double getWidth() const
236  {
237  return fabs(m_x1 - m_x2);
238  }
239  double getHeight() const
240  {
241  return fabs(m_y1 - m_y2);
242  }
243  const WPXBinaryData &getImage() const
244  {
245  return m_image;
246  }
247 };
248 
250 {
251  unsigned width;
252  unsigned height;
253  std::vector<unsigned char> pattern;
254  CDRPattern() : width(0), height(0), pattern() {}
255  CDRPattern(unsigned w, unsigned h, const std::vector<unsigned char> &p)
256  : width(w), height(h), pattern(p) {}
257 };
258 
259 struct CDRPage
260 {
261  double width;
262  double height;
263  double offsetX;
264  double offsetY;
265  CDRPage() : width(0.0), height(0.0), offsetX(0.0), offsetY(0.0) {}
266  CDRPage(double w, double h, double ox, double oy)
267  : width(w), height(h), offsetX(ox), offsetY(oy) {}
268  CDRPage(const CDRPage &page)
269  : width(page.width), height(page.height), offsetX(page.offsetX), offsetY(page.offsetY) {}
270 };
271 
273 {
274  std::vector<std::pair<double, double> > points;
275  std::vector<unsigned> knotVector;
277  CDRSplineData(const std::vector<std::pair<double, double> > &ps, const std::vector<unsigned> &kntv)
278  : points(ps), knotVector(kntv) {}
280  : points(data.points), knotVector(data.knotVector) {}
281  void clear()
282  {
283  points.clear();
284  knotVector.clear();
285  }
286  bool empty()
287  {
288  return (points.empty() || knotVector.empty());
289  }
290  void create(CDRPath &path) const;
291 };
292 
294 {
295  WaldoRecordInfo(unsigned char t, unsigned i, unsigned o)
296  : type(t), id(i), offset(o) {}
297  WaldoRecordInfo() : type(0), id(0), offset(0) {}
298  unsigned char type;
299  unsigned id;
300  unsigned offset;
301 };
302 
304 {
305  WaldoRecordType1(unsigned id, unsigned short next, unsigned short previous,
306  unsigned short child, unsigned short parent, unsigned short flags,
307  double x0, double y0, double x1, double y1, const CDRTransform trafo)
308  : m_id(id), m_next(next), m_previous(previous), m_child(child), m_parent(parent),
309  m_flags(flags), m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1), m_trafo(trafo) {}
311  : m_id(0), m_next(0), m_previous(0), m_child(0), m_parent(0), m_flags(0),
312  m_x0(0.0), m_y0(0.0), m_x1(0.0), m_y1(0.0), m_trafo() {}
314  : m_id(record.m_id), m_next(record.m_next), m_previous(record.m_previous),
315  m_child(record.m_child), m_parent(record.m_parent), m_flags(record.m_flags),
316  m_x0(record.m_x0), m_y0(record.m_y0), m_x1(record.m_x1), m_y1(record.m_y1),
317  m_trafo(record.m_trafo) {}
318  unsigned m_id;
319  unsigned short m_next;
320  unsigned short m_previous;
321  unsigned short m_child;
322  unsigned short m_parent;
323  unsigned short m_flags;
324  double m_x0;
325  double m_y0;
326  double m_x1;
327  double m_y1;
329 };
330 
332 {
333  CDRCMYKColor(unsigned colorValue, bool percentage = true);
334  CDRCMYKColor(double cyan, double magenta, double yellow, double black)
335  : c(cyan), m(magenta), y(yellow), k(black) {}
337  : c(color.c), m(color.m), y(color.y), k(color.k) {}
339  double c;
340  double m;
341  double y;
342  double k;
343  void applyTint(double tint);
344  unsigned getColorValue() const;
345 };
346 
348 {
349  CDRRGBColor(unsigned colorValue);
350  CDRRGBColor(double red, double green, double blue)
351  : r(red), g(green), b(blue) {}
352  CDRRGBColor(const CDRRGBColor &color)
353  : r(color.r), g(color.g), b(color.b) {}
355  double r;
356  double g;
357  double b;
358  void applyTint(double tint);
359  unsigned getColorValue() const;
360 };
361 
363 {
364  CDRLab2Color(unsigned colorValue);
365  CDRLab2Color(double l, double A, double B)
366  : L(l), a(A), b(B) {}
368  : L(color.L), a(color.a), b(color.b) {}
370  double L;
371  double a;
372  double b;
373  void applyTint(double tint);
374  unsigned getColorValue() const;
375 };
376 
378 {
379  CDRLab4Color(unsigned colorValue);
380  CDRLab4Color(double l, double A, double B)
381  : L(l), a(A), b(B) {}
383  : L(color.L), a(color.a), b(color.b) {}
385  double L;
386  double a;
387  double b;
388  void applyTint(double tint);
389  unsigned getColorValue() const;
390 };
391 
392 struct CDRText
393 {
395  CDRText(const WPXString &text, const CDRCharacterStyle &charStyle)
396  : m_text(text), m_charStyle(charStyle) {}
397  WPXString m_text;
399 };
400 
401 } // namespace libcdr
402 
403 #endif /* __CDRTYPES_H__ */
404 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libcdr by doxygen 1.8.3