| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 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 ¢er) 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 |
| 408 |
|
| 409 |
|