ZMFTypes.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is a part of the libzmf 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 ZMFTYPES_H_INCLUDED
11 #define ZMFTYPES_H_INCLUDED
12 
13 #include <vector>
14 #include <memory>
15 
16 #include <boost/optional.hpp>
17 #include <boost/variant.hpp>
18 
19 #include "libzmf_utils.h"
20 
21 namespace libzmf
22 {
23 
24 struct Point
25 {
26  double x;
27  double y;
28 
30  : x(0.0), y(0.0)
31  { }
32 
33  Point(double xVal, double yVal)
34  : x(xVal), y(yVal)
35  { }
36 
37  Point move(double dx, double dy) const;
38  Point rotate(double rotation, const Point &center) const;
39 
40  double distance(const Point &p2) const;
41 };
42 
43 bool operator==(const Point &lhs, const Point &rhs);
44 bool operator!=(const Point &lhs, const Point &rhs);
45 
47 {
48  BoundingBox(const std::vector<Point> &points);
49 
50  const std::vector<Point> &points() const;
51 
52  double width() const;
53  double height() const;
54 
55  Point center() const;
56  Point topLeft() const;
57 
58  double rotation() const;
59 
60  int p1Quadrant() const;
61  int p2Quadrant() const;
62 
63  bool mirrorHorizontal() const;
64  bool mirrorVertical() const;
65 
66 private:
67  int quadrant(const Point &p) const;
68 
69  const std::vector<Point> m_points;
70  double m_width;
71  double m_height;
73  double m_rotation;
78 };
79 
80 enum class CurveType
81 {
82  LINE,
84 };
85 
86 struct Curve
87 {
88  std::vector<Point> points;
89  std::vector<CurveType> sectionTypes;
90  bool closed;
91 
93  : points(), sectionTypes(), closed(false)
94  { }
95 };
96 
97 struct Color
98 {
99  uint8_t red;
100  uint8_t green;
101  uint8_t blue;
102 
104  : red(0), green(0), blue(0)
105  { }
106 
107  Color(uint8_t r, uint8_t g, uint8_t b)
108  : red(r), green(g), blue(b)
109  { }
110 
111  librevenge::RVNGString toString() const;
112 };
113 
114 enum class LineCapType
115 {
116  BUTT,
117  FLAT,
118  ROUND,
119  POINTED
120 };
121 
122 enum class LineJoinType
123 {
124  MITER,
125  ROUND,
126  BEVEL
127 };
128 
129 struct Arrow
130 {
131  std::vector<Curve> curves;
132  double lineEndX;
133 
135  : curves(), lineEndX(0.0)
136  { }
137 };
138 
139 typedef std::shared_ptr<Arrow> ArrowPtr;
140 
141 struct Pen
142 {
144  double width;
147  std::vector<double> dashPattern;
148  double dashDistance;
152 
153  Pen()
154  : color(), width(0.0),
157  startArrow(), endArrow(),
158  isInvisible(false)
159  { }
160 
162  : color(c),
163  width(0.0),
166  startArrow(), endArrow(),
167  isInvisible(false)
168  { }
169 };
170 
172 {
174  double offset;
175 
177  : color(), offset(0.0)
178  { }
179 };
180 
181 enum class GradientType
182 {
183  LINEAR,
184  RADIAL,
185  CONICAL,
186  CROSS,
187  RECTANGULAR,
188  FLEXIBLE
189 };
190 
191 struct Gradient
192 {
194  std::vector<GradientStop> stops;
195  double angle;
197 
199  : type(), stops(), angle(0.0), center(0.5, 0.5)
200  { }
201 };
202 
203 struct Image
204 {
205  uint32_t width;
206  uint32_t height;
207  librevenge::RVNGBinaryData data;
208 
210  : width(0), height(0), data()
211  { }
212 
213  Image(uint32_t w, uint32_t h, librevenge::RVNGBinaryData d)
214  : width(w), height(h), data(d)
215  { }
216 };
217 
218 struct ImageFill
219 {
221  bool tile;
222  double tileWidth;
223  double tileHeight;
224 
226  : image(), tile(false), tileWidth(0.0), tileHeight(0.0)
227  { }
228 };
229 
230 typedef boost::variant<Color, Gradient, ImageFill> Fill;
231 
233 {
235 
236  double opacity() const
237  {
238  return 1.0 - color.red / 255.0;
239  }
240 
242  : color()
243  { }
244 };
245 
246 struct Shadow
247 {
249  double angle;
250  double opacity;
252 
254  : offset(), angle(0.0), opacity(1.0), color()
255  { }
256 };
257 
258 struct Style
259 {
260  boost::optional<Pen> pen;
261  boost::optional<Fill> fill;
262  boost::optional<Transparency> transparency;
263  boost::optional<Shadow> shadow;
264 
266  : pen(), fill(), transparency(), shadow()
267  { }
268 };
269 
270 struct Font
271 {
272  librevenge::RVNGString name;
273  double size;
274  bool isBold;
275  bool isItalic;
276  boost::optional<Fill> fill;
277  boost::optional<Pen> outline;
278 
280  : name("Arial"), size(24.0), isBold(false), isItalic(false),
281  fill(Color(0, 0, 0)), outline()
282  { }
283 };
284 
285 struct Span
286 {
287  librevenge::RVNGString text;
288  uint32_t length;
290 
292  : text(), length(0), font()
293  { }
294 };
295 
297 {
298  LEFT,
299  RIGHT,
300  BLOCK,
301  CENTER,
302  FULL
303 };
304 
306 {
307  TOP,
308  MIDDLE,
309  BOTTOM
310 };
311 
313 {
314  double lineSpacing;
317 
320  { }
321 };
322 
323 struct Paragraph
324 {
325  std::vector<Span> spans;
327 
329  : spans(), style()
330  { }
331 };
332 
333 struct Text
334 {
335  std::vector<Paragraph> paragraphs;
336 
338  : paragraphs()
339  { }
340 };
341 
342 struct Cell
343 {
345  boost::optional<Fill> fill;
346  boost::optional<Pen> leftBorder;
347  boost::optional<Pen> rightBorder;
348  boost::optional<Pen> topBorder;
349  boost::optional<Pen> bottomBorder;
350 
352  : text(), fill(),
354  { }
355 };
356 
357 struct Row
358 {
359  std::vector<Cell> cells;
360  double height;
361 
362  Row()
363  : cells(), height(0.0)
364  { }
365 };
366 
367 struct Column
368 {
369  double width;
370 
372  : width(0.0)
373  { }
374 };
375 
376 struct Table
377 {
378  std::vector<Row> rows;
379  std::vector<Column> columns;
380  double width;
381  double height;
383 
385  : rows(), columns(), width(0.0), height(0.0), topLeftPoint()
386  { }
387 };
388 
390 {
391  double width;
392  double height;
393  double leftOffset;
394  double topOffset;
396 
398  : width(0.0), height(0.0), leftOffset(0.0), topOffset(0.0), color()
399  { }
400  ZMFPageSettings(double w, double h, double left, double top, Color c = Color(255, 255, 255))
401  : width(w), height(h), leftOffset(left), topOffset(top), color(c)
402  { }
403 };
404 
405 }
406 
407 #endif // ZMFTYPES_H_INCLUDED
408 
409 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Table()
Definition: ZMFTypes.h:384
Definition: ZMFTypes.h:24
bool closed
Definition: ZMFTypes.h:90
double rotation() const
Definition: ZMFTypes.cpp:133
GradientType type
Definition: ZMFTypes.h:193
Definition: ZMFTypes.h:285
Definition: ZMFTypes.h:246
double width
Definition: ZMFTypes.h:380
bool isInvisible
Definition: ZMFTypes.h:151
BoundingBox(const std::vector< Point > &points)
Definition: ZMFTypes.cpp:45
std::vector< Column > columns
Definition: ZMFTypes.h:379
Point center() const
Definition: ZMFTypes.cpp:123
Definition: ZMFTypes.h:218
Row()
Definition: ZMFTypes.h:362
std::vector< double > dashPattern
Definition: ZMFTypes.h:147
Color color
Definition: ZMFTypes.h:251
Point(double xVal, double yVal)
Definition: ZMFTypes.h:33
GradientType
Definition: ZMFTypes.h:181
Point m_center
Definition: ZMFTypes.h:72
boost::optional< Fill > fill
Definition: ZMFTypes.h:261
Image image
Definition: ZMFTypes.h:220
bool operator==(const BMIOffset &lhs, const BMIOffset &rhs)
Definition: BMITypes.cpp:15
boost::optional< Fill > fill
Definition: ZMFTypes.h:345
double angle
Definition: ZMFTypes.h:249
Point center
Definition: ZMFTypes.h:196
ZMFPageSettings()
Definition: ZMFTypes.h:397
double lineSpacing
Definition: ZMFTypes.h:314
HorizontalAlignment alignment
Definition: ZMFTypes.h:315
double m_rotation
Definition: ZMFTypes.h:73
Definition: ZMFTypes.h:232
Color color
Definition: ZMFTypes.h:143
ParagraphStyle()
Definition: ZMFTypes.h:318
GradientStop()
Definition: ZMFTypes.h:176
Column()
Definition: ZMFTypes.h:371
Definition: ZMFTypes.h:389
bool operator!=(const BMIOffset &lhs, const BMIOffset &rhs)
Definition: BMITypes.cpp:20
double height
Definition: ZMFTypes.h:360
std::vector< Span > spans
Definition: ZMFTypes.h:325
boost::variant< Color, Gradient, ImageFill > Fill
Definition: ZMFTypes.h:230
LineJoinType
Definition: ZMFTypes.h:122
double width
Definition: ZMFTypes.h:369
uint32_t height
Definition: ZMFTypes.h:206
Text()
Definition: ZMFTypes.h:337
double x
Definition: ZMFTypes.h:26
LineCapType
Definition: ZMFTypes.h:114
Definition: ZMFTypes.h:46
librevenge::RVNGString text
Definition: ZMFTypes.h:287
Definition: ZMFTypes.h:342
ImageFill()
Definition: ZMFTypes.h:225
librevenge::RVNGString toString() const
Definition: ZMFTypes.cpp:177
double dashDistance
Definition: ZMFTypes.h:148
Definition: ZMFTypes.h:312
boost::optional< Pen > bottomBorder
Definition: ZMFTypes.h:349
double offset
Definition: ZMFTypes.h:174
ArrowPtr endArrow
Definition: ZMFTypes.h:150
Curve()
Definition: ZMFTypes.h:92
double opacity() const
Definition: ZMFTypes.h:236
boost::optional< Pen > leftBorder
Definition: ZMFTypes.h:346
Definition: ZMFTypes.h:97
Pen()
Definition: ZMFTypes.h:153
double y
Definition: ZMFTypes.h:27
Definition: ZMFTypes.h:191
double m_height
Definition: ZMFTypes.h:71
Point topLeft() const
Definition: ZMFTypes.cpp:128
std::vector< GradientStop > stops
Definition: ZMFTypes.h:194
bool tile
Definition: ZMFTypes.h:221
boost::optional< Pen > outline
Definition: ZMFTypes.h:277
std::vector< Cell > cells
Definition: ZMFTypes.h:359
Style()
Definition: ZMFTypes.h:265
Definition: ZMFTypes.h:171
Image(uint32_t w, uint32_t h, librevenge::RVNGBinaryData d)
Definition: ZMFTypes.h:213
Shadow()
Definition: ZMFTypes.h:253
double tileWidth
Definition: ZMFTypes.h:222
bool m_mirrorHorizontal
Definition: ZMFTypes.h:76
double height
Definition: ZMFTypes.h:381
double lineEndX
Definition: ZMFTypes.h:132
bool mirrorVertical() const
Definition: ZMFTypes.cpp:153
bool isBold
Definition: ZMFTypes.h:274
LineJoinType lineJoinType
Definition: ZMFTypes.h:146
librevenge::RVNGString name
Definition: ZMFTypes.h:272
double width
Definition: ZMFTypes.h:144
Font font
Definition: ZMFTypes.h:316
Definition: ZMFTypes.h:323
int quadrant(const Point &p) const
Definition: ZMFTypes.cpp:158
Color(uint8_t r, uint8_t g, uint8_t b)
Definition: ZMFTypes.h:107
boost::optional< Shadow > shadow
Definition: ZMFTypes.h:263
uint32_t length
Definition: ZMFTypes.h:288
Definition: ZMFTypes.h:86
Image()
Definition: ZMFTypes.h:209
Cell()
Definition: ZMFTypes.h:351
Point topLeftPoint
Definition: ZMFTypes.h:382
int p2Quadrant() const
Definition: ZMFTypes.cpp:143
Paragraph()
Definition: ZMFTypes.h:328
double m_width
Definition: ZMFTypes.h:70
double height
Definition: ZMFTypes.h:392
CurveType
Definition: ZMFTypes.h:80
boost::optional< Transparency > transparency
Definition: ZMFTypes.h:262
double distance(const Point &p2) const
Definition: ZMFTypes.cpp:39
Color color
Definition: ZMFTypes.h:173
uint8_t blue
Definition: ZMFTypes.h:101
double leftOffset
Definition: ZMFTypes.h:393
Point()
Definition: ZMFTypes.h:29
Definition: BMIHeader.cpp:13
Definition: ZMFTypes.h:357
uint32_t width
Definition: ZMFTypes.h:205
ArrowPtr startArrow
Definition: ZMFTypes.h:149
std::vector< Paragraph > paragraphs
Definition: ZMFTypes.h:335
boost::optional< Pen > rightBorder
Definition: ZMFTypes.h:347
Font()
Definition: ZMFTypes.h:279
Definition: ZMFTypes.h:258
HorizontalAlignment
Definition: ZMFTypes.h:296
Definition: ZMFTypes.h:129
Definition: ZMFTypes.h:141
ZMFPageSettings(double w, double h, double left, double top, Color c=Color(255, 255, 255))
Definition: ZMFTypes.h:400
double topOffset
Definition: ZMFTypes.h:394
boost::optional< Pen > pen
Definition: ZMFTypes.h:260
librevenge::RVNGBinaryData data
Definition: ZMFTypes.h:207
VerticalAlignment
Definition: ZMFTypes.h:305
uint8_t red
Definition: ZMFTypes.h:99
double angle
Definition: ZMFTypes.h:195
Definition: ZMFTypes.h:203
int p1Quadrant() const
Definition: ZMFTypes.cpp:138
Point offset
Definition: ZMFTypes.h:248
std::shared_ptr< Arrow > ArrowPtr
Definition: ZMFTypes.h:139
boost::optional< Pen > topBorder
Definition: ZMFTypes.h:348
std::vector< Curve > curves
Definition: ZMFTypes.h:131
const std::vector< Point > m_points
Definition: ZMFTypes.h:69
bool m_mirrorVertical
Definition: ZMFTypes.h:77
Definition: ZMFTypes.h:376
bool mirrorHorizontal() const
Definition: ZMFTypes.cpp:148
Color()
Definition: ZMFTypes.h:103
Color color
Definition: ZMFTypes.h:234
Arrow()
Definition: ZMFTypes.h:134
Point move(double dx, double dy) const
Definition: ZMFTypes.cpp:27
int m_p1Quadrant
Definition: ZMFTypes.h:74
const std::vector< Point > & points() const
Definition: ZMFTypes.cpp:108
std::vector< CurveType > sectionTypes
Definition: ZMFTypes.h:89
boost::optional< Fill > fill
Definition: ZMFTypes.h:276
Font font
Definition: ZMFTypes.h:289
double width
Definition: ZMFTypes.h:391
Pen(Color c)
Definition: ZMFTypes.h:161
double tileHeight
Definition: ZMFTypes.h:223
Gradient()
Definition: ZMFTypes.h:198
std::vector< Row > rows
Definition: ZMFTypes.h:378
Span()
Definition: ZMFTypes.h:291
double size
Definition: ZMFTypes.h:273
uint8_t green
Definition: ZMFTypes.h:100
double opacity
Definition: ZMFTypes.h:250
Transparency()
Definition: ZMFTypes.h:241
Text text
Definition: ZMFTypes.h:344
Definition: ZMFTypes.h:270
LineCapType lineCapType
Definition: ZMFTypes.h:145
int m_p2Quadrant
Definition: ZMFTypes.h:75
ParagraphStyle style
Definition: ZMFTypes.h:326
double height() const
Definition: ZMFTypes.cpp:118
double width() const
Definition: ZMFTypes.cpp:113
std::vector< Point > points
Definition: ZMFTypes.h:88
bool isItalic
Definition: ZMFTypes.h:275
Color color
Definition: ZMFTypes.h:395
Definition: ZMFTypes.h:333
Point rotate(double rotation, const Point &center) const
Definition: ZMFTypes.cpp:32
Definition: ZMFTypes.h:367

Generated for libzmf by doxygen 1.8.14