ZMFTypes.h Source File documentation

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
29 Point()
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
46 struct BoundingBox
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;
72 Point m_center;
73 double m_rotation;
74 int m_p1Quadrant;
75 int m_p2Quadrant;
76 bool m_mirrorHorizontal;
77 bool m_mirrorVertical;
78 };
79
80 enum class CurveType
81 {
82 LINE,
83 BEZIER_CURVE
84 };
85
86 struct Curve
87 {
88 std::vector<Point> points;
89 std::vector<CurveType> sectionTypes;
90 bool closed;
91
92 Curve()
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
103 Color()
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
134 Arrow()
135 : curves(), lineEndX(0.0)
136 { }
137 };
138
139 typedef std::shared_ptr<Arrow> ArrowPtr;
140
141 struct Pen
142 {
143 Color color;
144 double width;
145 LineCapType lineCapType;
146 LineJoinType lineJoinType;
147 std::vector<double> dashPattern;
148 double dashDistance;
149 ArrowPtr startArrow;
150 ArrowPtr endArrow;
151 bool isInvisible;
152
153 Pen()
154 : color(), width(0.0),
155 lineCapType(LineCapType::BUTT), lineJoinType(LineJoinType::MITER),
156 dashPattern(), dashDistance(0),
157 startArrow(), endArrow(),
158 isInvisible(false)
159 { }
160
161 Pen(Color c)
162 : color(c),
163 width(0.0),
164 lineCapType(LineCapType::BUTT), lineJoinType(LineJoinType::MITER),
165 dashPattern(), dashDistance(0),
166 startArrow(), endArrow(),
167 isInvisible(false)
168 { }
169 };
170
171 struct GradientStop
172 {
173 Color color;
174 double offset;
175
176 GradientStop()
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 {
193 GradientType type;
194 std::vector<GradientStop> stops;
195 double angle;
196 Point center;
197
198 Gradient()
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
209 Image()
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 {
220 Image image;
221 bool tile;
222 double tileWidth;
223 double tileHeight;
224
225 ImageFill()
226 : image(), tile(false), tileWidth(0.0), tileHeight(0.0)
227 { }
228 };
229
230 typedef boost::variant<Color, Gradient, ImageFill> Fill;
231
232 struct Transparency
233 {
234 Color color;
235
236 double opacity() const
237 {
238 return 1.0 - color.red / 255.0;
239 }
240
241 Transparency()
242 : color()
243 { }
244 };
245
246 struct Shadow
247 {
248 Point offset;
249 double angle;
250 double opacity;
251 Color color;
252
253 Shadow()
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
265 Style()
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
279 Font()
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;
289 Font font;
290
291 Span()
292 : text(), length(0), font()
293 { }
294 };
295
296 enum class HorizontalAlignment
297 {
298 LEFT,
299 RIGHT,
300 BLOCK,
301 CENTER,
302 FULL
303 };
304
305 enum class VerticalAlignment
306 {
307 TOP,
308 MIDDLE,
309 BOTTOM
310 };
311
312 struct ParagraphStyle
313 {
314 double lineSpacing;
315 HorizontalAlignment alignment;
316 Font font;
317
318 ParagraphStyle()
319 : lineSpacing(1.2), alignment(HorizontalAlignment::LEFT), font()
320 { }
321 };
322
323 struct Paragraph
324 {
325 std::vector<Span> spans;
326 ParagraphStyle style;
327
328 Paragraph()
329 : spans(), style()
330 { }
331 };
332
333 struct Text
334 {
335 std::vector<Paragraph> paragraphs;
336
337 Text()
338 : paragraphs()
339 { }
340 };
341
342 struct Cell
343 {
344 Text text;
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
351 Cell()
352 : text(), fill(),
353 leftBorder(), rightBorder(), topBorder(), bottomBorder()
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
371 Column()
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;
382 Point topLeftPoint;
383
384 Table()
385 : rows(), columns(), width(0.0), height(0.0), topLeftPoint()
386 { }
387 };
388
389 struct ZMFPageSettings
390 {
391 double width;
392 double height;
393 double leftOffset;
394 double topOffset;
395 Color color;
396
397 ZMFPageSettings()
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: */
libzmf::Table::Table
Table()
Definition: ZMFTypes.h:384
libzmf::Point
Definition: ZMFTypes.h:24
libzmf::Curve::closed
bool closed
Definition: ZMFTypes.h:90
libzmf::BoundingBox::rotation
double rotation() const
Definition: ZMFTypes.cpp:133
libzmf::Gradient::type
GradientType type
Definition: ZMFTypes.h:193
libzmf::Span
Definition: ZMFTypes.h:285
libzmf::Shadow
Definition: ZMFTypes.h:246
libzmf::LineCapType::BUTT
libzmf::Table::width
double width
Definition: ZMFTypes.h:380
libzmf::Pen::isInvisible
bool isInvisible
Definition: ZMFTypes.h:151
libzmf::BoundingBox::BoundingBox
BoundingBox(const std::vector< Point > &points)
Definition: ZMFTypes.cpp:45
libzmf::Table::columns
std::vector< Column > columns
Definition: ZMFTypes.h:379
libzmf::BoundingBox::center
Point center() const
Definition: ZMFTypes.cpp:123
libzmf::ImageFill
Definition: ZMFTypes.h:218
libzmf::Row::Row
Row()
Definition: ZMFTypes.h:362
libzmf::Pen::dashPattern
std::vector< double > dashPattern
Definition: ZMFTypes.h:147
libzmf::GradientType::CONICAL
libzmf::Shadow::color
Color color
Definition: ZMFTypes.h:251
libzmf::Point::Point
Point(double xVal, double yVal)
Definition: ZMFTypes.h:33
libzmf::GradientType::CROSS
libzmf::GradientType
GradientType
Definition: ZMFTypes.h:181
libzmf::VerticalAlignment::BOTTOM
libzmf::BoundingBox::m_center
Point m_center
Definition: ZMFTypes.h:72
libzmf::Style::fill
boost::optional< Fill > fill
Definition: ZMFTypes.h:261
libzmf::ImageFill::image
Image image
Definition: ZMFTypes.h:220
libzmf::operator==
bool operator==(const BMIOffset &lhs, const BMIOffset &rhs)
Definition: BMITypes.cpp:15
libzmf::CurveType::BEZIER_CURVE
libzmf::Cell::fill
boost::optional< Fill > fill
Definition: ZMFTypes.h:345
libzmf::Shadow::angle
double angle
Definition: ZMFTypes.h:249
libzmf::VerticalAlignment::TOP
libzmf::Gradient::center
Point center
Definition: ZMFTypes.h:196
libzmf::ZMFPageSettings::ZMFPageSettings
ZMFPageSettings()
Definition: ZMFTypes.h:397
libzmf::ParagraphStyle::lineSpacing
double lineSpacing
Definition: ZMFTypes.h:314
libzmf::ParagraphStyle::alignment
HorizontalAlignment alignment
Definition: ZMFTypes.h:315
libzmf::BoundingBox::m_rotation
double m_rotation
Definition: ZMFTypes.h:73
libzmf::Transparency
Definition: ZMFTypes.h:232
libzmf::Pen::color
Color color
Definition: ZMFTypes.h:143
libzmf::ParagraphStyle::ParagraphStyle
ParagraphStyle()
Definition: ZMFTypes.h:318
libzmf::GradientStop::GradientStop
GradientStop()
Definition: ZMFTypes.h:176
libzmf::Column::Column
Column()
Definition: ZMFTypes.h:371
libzmf::ZMFPageSettings
Definition: ZMFTypes.h:389
libzmf::operator!=
bool operator!=(const BMIOffset &lhs, const BMIOffset &rhs)
Definition: BMITypes.cpp:20
libzmf::Row::height
double height
Definition: ZMFTypes.h:360
libzmf::GradientType::LINEAR
libzmf::Paragraph::spans
std::vector< Span > spans
Definition: ZMFTypes.h:325
libzmf::Fill
boost::variant< Color, Gradient, ImageFill > Fill
Definition: ZMFTypes.h:230
libzmf::LineJoinType
LineJoinType
Definition: ZMFTypes.h:122
libzmf::Column::width
double width
Definition: ZMFTypes.h:369
libzmf::Image::height
uint32_t height
Definition: ZMFTypes.h:206
libzmf::Text::Text
Text()
Definition: ZMFTypes.h:337
libzmf::Point::x
double x
Definition: ZMFTypes.h:26
libzmf::VerticalAlignment::MIDDLE
libzmf::LineCapType
LineCapType
Definition: ZMFTypes.h:114
libzmf::BoundingBox
Definition: ZMFTypes.h:46
libzmf::Span::text
librevenge::RVNGString text
Definition: ZMFTypes.h:287
libzmf::Cell
Definition: ZMFTypes.h:342
libzmf::ImageFill::ImageFill
ImageFill()
Definition: ZMFTypes.h:225
libzmf::Color::toString
librevenge::RVNGString toString() const
Definition: ZMFTypes.cpp:177
libzmf::Pen::dashDistance
double dashDistance
Definition: ZMFTypes.h:148
libzmf::ParagraphStyle
Definition: ZMFTypes.h:312
libzmf::Cell::bottomBorder
boost::optional< Pen > bottomBorder
Definition: ZMFTypes.h:349
libzmf::GradientStop::offset
double offset
Definition: ZMFTypes.h:174
libzmf::Pen::endArrow
ArrowPtr endArrow
Definition: ZMFTypes.h:150
libzmf::Curve::Curve
Curve()
Definition: ZMFTypes.h:92
libzmf::Transparency::opacity
double opacity() const
Definition: ZMFTypes.h:236
libzmf::Cell::leftBorder
boost::optional< Pen > leftBorder
Definition: ZMFTypes.h:346
libzmf::Color
Definition: ZMFTypes.h:97
libzmf::Pen::Pen
Pen()
Definition: ZMFTypes.h:153
libzmf::Point::y
double y
Definition: ZMFTypes.h:27
libzmf::Gradient
Definition: ZMFTypes.h:191
libzmf::HorizontalAlignment::BLOCK
libzmf::BoundingBox::m_height
double m_height
Definition: ZMFTypes.h:71
libzmf::BoundingBox::topLeft
Point topLeft() const
Definition: ZMFTypes.cpp:128
libzmf::Gradient::stops
std::vector< GradientStop > stops
Definition: ZMFTypes.h:194
libzmf::ImageFill::tile
bool tile
Definition: ZMFTypes.h:221
libzmf::Font::outline
boost::optional< Pen > outline
Definition: ZMFTypes.h:277
libzmf::Row::cells
std::vector< Cell > cells
Definition: ZMFTypes.h:359
libzmf::Style::Style
Style()
Definition: ZMFTypes.h:265
libzmf::GradientStop
Definition: ZMFTypes.h:171
libzmf::Image::Image
Image(uint32_t w, uint32_t h, librevenge::RVNGBinaryData d)
Definition: ZMFTypes.h:213
libzmf::Shadow::Shadow
Shadow()
Definition: ZMFTypes.h:253
libzmf::ImageFill::tileWidth
double tileWidth
Definition: ZMFTypes.h:222
libzmf::BoundingBox::m_mirrorHorizontal
bool m_mirrorHorizontal
Definition: ZMFTypes.h:76
libzmf::Table::height
double height
Definition: ZMFTypes.h:381
libzmf::Arrow::lineEndX
double lineEndX
Definition: ZMFTypes.h:132
libzmf::CurveType::LINE
libzmf::BoundingBox::mirrorVertical
bool mirrorVertical() const
Definition: ZMFTypes.cpp:153
libzmf::Font::isBold
bool isBold
Definition: ZMFTypes.h:274
libzmf::Pen::lineJoinType
LineJoinType lineJoinType
Definition: ZMFTypes.h:146
libzmf::Font::name
librevenge::RVNGString name
Definition: ZMFTypes.h:272
libzmf::Pen::width
double width
Definition: ZMFTypes.h:144
libzmf::ParagraphStyle::font
Font font
Definition: ZMFTypes.h:316
libzmf::Paragraph
Definition: ZMFTypes.h:323
libzmf::BoundingBox::quadrant
int quadrant(const Point &p) const
Definition: ZMFTypes.cpp:158
libzmf::Color::Color
Color(uint8_t r, uint8_t g, uint8_t b)
Definition: ZMFTypes.h:107
libzmf::HorizontalAlignment::RIGHT
libzmf_utils.h
libzmf::HorizontalAlignment::LEFT
libzmf::Style::shadow
boost::optional< Shadow > shadow
Definition: ZMFTypes.h:263
libzmf::GradientType::RADIAL
libzmf::Span::length
uint32_t length
Definition: ZMFTypes.h:288
libzmf::Curve
Definition: ZMFTypes.h:86
libzmf::Image::Image
Image()
Definition: ZMFTypes.h:209
libzmf::Cell::Cell
Cell()
Definition: ZMFTypes.h:351
libzmf::Table::topLeftPoint
Point topLeftPoint
Definition: ZMFTypes.h:382
libzmf::BoundingBox::p2Quadrant
int p2Quadrant() const
Definition: ZMFTypes.cpp:143
libzmf::Paragraph::Paragraph
Paragraph()
Definition: ZMFTypes.h:328
libzmf::LineJoinType::MITER
libzmf::BoundingBox::m_width
double m_width
Definition: ZMFTypes.h:70
libzmf::ZMFPageSettings::height
double height
Definition: ZMFTypes.h:392
libzmf::LineCapType::FLAT
libzmf::CurveType
CurveType
Definition: ZMFTypes.h:80
libzmf::Style::transparency
boost::optional< Transparency > transparency
Definition: ZMFTypes.h:262
libzmf::Point::distance
double distance(const Point &p2) const
Definition: ZMFTypes.cpp:39
libzmf::GradientStop::color
Color color
Definition: ZMFTypes.h:173
libzmf::Color::blue
uint8_t blue
Definition: ZMFTypes.h:101
libzmf::ZMFPageSettings::leftOffset
double leftOffset
Definition: ZMFTypes.h:393
libzmf::Point::Point
Point()
Definition: ZMFTypes.h:29
libzmf::HorizontalAlignment::CENTER
libzmf
Definition: BMIHeader.cpp:13
libzmf::GradientType::FLEXIBLE
libzmf::Row
Definition: ZMFTypes.h:357
libzmf::Image::width
uint32_t width
Definition: ZMFTypes.h:205
libzmf::Pen::startArrow
ArrowPtr startArrow
Definition: ZMFTypes.h:149
libzmf::Text::paragraphs
std::vector< Paragraph > paragraphs
Definition: ZMFTypes.h:335
libzmf::Cell::rightBorder
boost::optional< Pen > rightBorder
Definition: ZMFTypes.h:347
libzmf::Font::Font
Font()
Definition: ZMFTypes.h:279
libzmf::Style
Definition: ZMFTypes.h:258
libzmf::HorizontalAlignment
HorizontalAlignment
Definition: ZMFTypes.h:296
libzmf::Arrow
Definition: ZMFTypes.h:129
libzmf::Pen
Definition: ZMFTypes.h:141
libzmf::LineCapType::POINTED
libzmf::ZMFPageSettings::ZMFPageSettings
ZMFPageSettings(double w, double h, double left, double top, Color c=Color(255, 255, 255))
Definition: ZMFTypes.h:400
libzmf::ZMFPageSettings::topOffset
double topOffset
Definition: ZMFTypes.h:394
libzmf::Style::pen
boost::optional< Pen > pen
Definition: ZMFTypes.h:260
libzmf::Image::data
librevenge::RVNGBinaryData data
Definition: ZMFTypes.h:207
libzmf::VerticalAlignment
VerticalAlignment
Definition: ZMFTypes.h:305
libzmf::Color::red
uint8_t red
Definition: ZMFTypes.h:99
libzmf::GradientType::RECTANGULAR
libzmf::Gradient::angle
double angle
Definition: ZMFTypes.h:195
libzmf::Image
Definition: ZMFTypes.h:203
libzmf::BoundingBox::p1Quadrant
int p1Quadrant() const
Definition: ZMFTypes.cpp:138
libzmf::Shadow::offset
Point offset
Definition: ZMFTypes.h:248
libzmf::ArrowPtr
std::shared_ptr< Arrow > ArrowPtr
Definition: ZMFTypes.h:139
libzmf::Cell::topBorder
boost::optional< Pen > topBorder
Definition: ZMFTypes.h:348
libzmf::Arrow::curves
std::vector< Curve > curves
Definition: ZMFTypes.h:131
libzmf::BoundingBox::m_points
const std::vector< Point > m_points
Definition: ZMFTypes.h:69
libzmf::BoundingBox::m_mirrorVertical
bool m_mirrorVertical
Definition: ZMFTypes.h:77
libzmf::Table
Definition: ZMFTypes.h:376
libzmf::BoundingBox::mirrorHorizontal
bool mirrorHorizontal() const
Definition: ZMFTypes.cpp:148
libzmf::Color::Color
Color()
Definition: ZMFTypes.h:103
libzmf::Transparency::color
Color color
Definition: ZMFTypes.h:234
libzmf::Arrow::Arrow
Arrow()
Definition: ZMFTypes.h:134
libzmf::Point::move
Point move(double dx, double dy) const
Definition: ZMFTypes.cpp:27
libzmf::BoundingBox::m_p1Quadrant
int m_p1Quadrant
Definition: ZMFTypes.h:74
libzmf::BoundingBox::points
const std::vector< Point > & points() const
Definition: ZMFTypes.cpp:108
libzmf::Curve::sectionTypes
std::vector< CurveType > sectionTypes
Definition: ZMFTypes.h:89
libzmf::Font::fill
boost::optional< Fill > fill
Definition: ZMFTypes.h:276
libzmf::Span::font
Font font
Definition: ZMFTypes.h:289
libzmf::ZMFPageSettings::width
double width
Definition: ZMFTypes.h:391
libzmf::Pen::Pen
Pen(Color c)
Definition: ZMFTypes.h:161
libzmf::ImageFill::tileHeight
double tileHeight
Definition: ZMFTypes.h:223
libzmf::Gradient::Gradient
Gradient()
Definition: ZMFTypes.h:198
libzmf::HorizontalAlignment::FULL
libzmf::Table::rows
std::vector< Row > rows
Definition: ZMFTypes.h:378
libzmf::Span::Span
Span()
Definition: ZMFTypes.h:291
libzmf::Font::size
double size
Definition: ZMFTypes.h:273
libzmf::Color::green
uint8_t green
Definition: ZMFTypes.h:100
libzmf::Shadow::opacity
double opacity
Definition: ZMFTypes.h:250
libzmf::Transparency::Transparency
Transparency()
Definition: ZMFTypes.h:241
libzmf::Cell::text
Text text
Definition: ZMFTypes.h:344
libzmf::Font
Definition: ZMFTypes.h:270
libzmf::Pen::lineCapType
LineCapType lineCapType
Definition: ZMFTypes.h:145
libzmf::BoundingBox::m_p2Quadrant
int m_p2Quadrant
Definition: ZMFTypes.h:75
libzmf::Paragraph::style
ParagraphStyle style
Definition: ZMFTypes.h:326
libzmf::BoundingBox::height
double height() const
Definition: ZMFTypes.cpp:118
libzmf::BoundingBox::width
double width() const
Definition: ZMFTypes.cpp:113
libzmf::Curve::points
std::vector< Point > points
Definition: ZMFTypes.h:88
libzmf::LineJoinType::BEVEL
libzmf::Font::isItalic
bool isItalic
Definition: ZMFTypes.h:275
libzmf::ZMFPageSettings::color
Color color
Definition: ZMFTypes.h:395
libzmf::Text
Definition: ZMFTypes.h:333
libzmf::Point::rotate
Point rotate(double rotation, const Point &center) const
Definition: ZMFTypes.cpp:32
libzmf::Column
Definition: ZMFTypes.h:367
libzmf::LineCapType::ROUND