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

Generated for libcdr by doxygen 1.8.5