00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef QXPTYPES_H_INCLUDED
00011 #define QXPTYPES_H_INCLUDED
00012
00013 #include "libqxp_utils.h"
00014 #include <boost/optional.hpp>
00015 #include <boost/variant.hpp>
00016
00017 #include <memory>
00018 #include <vector>
00019 #include <utility>
00020
00021 namespace libqxp
00022 {
00023
00024 struct Point
00025 {
00026 double x;
00027 double y;
00028
00029 Point()
00030 : x(0.0), y(0.0)
00031 { }
00032
00033 Point(double xVal, double yVal)
00034 : x(xVal), y(yVal)
00035 { }
00036
00037 Point move(double dx, double dy) const;
00038 Point rotateDeg(double rotationDeg, const Point ¢er) const;
00039
00040 double distance(const Point &p2) const;
00041 };
00042
00043 bool operator==(const Point &lhs, const Point &rhs);
00044 bool operator!=(const Point &lhs, const Point &rhs);
00045
00046 struct Rect
00047 {
00048 double top;
00049 double right;
00050 double bottom;
00051 double left;
00052
00053 Rect();
00054 Rect(double t, double r, double b, double l);
00055
00056 double width() const;
00057 double height() const;
00058
00059 Point center() const;
00060 Point topLeft() const;
00061 Point topRight() const;
00062 Point bottomRight() const;
00063 Point bottomLeft() const;
00064
00065 Rect shrink(const double diff) const;
00066 };
00067
00068 struct Color
00069 {
00070 uint8_t red;
00071 uint8_t green;
00072 uint8_t blue;
00073
00074 Color()
00075 : red(0), green(0), blue(0)
00076 { }
00077
00078 Color(uint8_t r, uint8_t g, uint8_t b)
00079 : red(r), green(g), blue(b)
00080 { }
00081
00082 librevenge::RVNGString toString() const;
00083
00084 Color applyShade(double shade) const;
00085 };
00086
00087 enum class GradientType
00088 {
00089 LINEAR,
00090 MIDLINEAR,
00091 RECTANGULAR,
00092 DIAMOND,
00093 CIRCULAR,
00094 FULLCIRCULAR
00095 };
00096
00097 struct Gradient
00098 {
00099 GradientType type;
00100 Color color1;
00101 Color color2;
00102 double angle;
00103
00104 Gradient()
00105 : type(), color1(), color2(), angle(0.0)
00106 { }
00107 };
00108
00109 typedef boost::variant<Color, Gradient> Fill;
00110
00111 enum class LineCapType
00112 {
00113 BUTT,
00114 ROUND,
00115 RECT,
00116 STRETCH
00117 };
00118
00119 enum class LineJoinType
00120 {
00121 MITER,
00122 ROUND,
00123 BEVEL
00124 };
00125
00126 struct LineStyle
00127 {
00128 std::vector<double> segmentLengths;
00129 bool isStripe;
00130 bool isProportional;
00131 double patternLength;
00132 LineCapType endcapType;
00133 LineJoinType joinType;
00134
00135 LineStyle()
00136 : segmentLengths(), isStripe(false), isProportional(true), patternLength(6.0), endcapType(LineCapType::BUTT), joinType(LineJoinType::MITER)
00137 { }
00138
00139 LineStyle(std::vector<double> segments, bool proportional, double pattern, LineCapType endcap, LineJoinType join)
00140 : segmentLengths(std::move(segments)), isStripe(false), isProportional(proportional), patternLength(pattern), endcapType(endcap), joinType(join)
00141 { }
00142 };
00143
00144 struct CharFormat
00145 {
00146 librevenge::RVNGString fontName;
00147 double fontSize;
00148 double baselineShift;
00149 Color color;
00150 bool bold;
00151 bool italic;
00152 bool underline;
00153 bool outline;
00154 bool shadow;
00155 bool superscript;
00156 bool subscript;
00157 bool superior;
00158 bool strike;
00159 bool allCaps;
00160 bool smallCaps;
00161 bool wordUnderline;
00162
00163 bool isControlChars;
00164
00165 CharFormat()
00166 : fontName("Arial"), fontSize(12.0), baselineShift(0.0), color(0, 0, 0),
00167 bold(false), italic(false), underline(false), outline(false), shadow(false), superscript(false), subscript(false), superior(false),
00168 strike(false), allCaps(false), smallCaps(false), wordUnderline(false),
00169 isControlChars(false)
00170 { }
00171 };
00172
00173 struct HJ
00174 {
00175 HJ()
00176 : hyphenate(true)
00177 , minBefore(3)
00178 , minAfter(2)
00179 , maxInRow(0)
00180 , singleWordJustify(true)
00181 {
00182 }
00183
00184 bool hyphenate;
00185 unsigned minBefore;
00186 unsigned minAfter;
00187 unsigned maxInRow;
00188 bool singleWordJustify;
00189 };
00190
00191 enum class HorizontalAlignment
00192 {
00193 LEFT,
00194 CENTER,
00195 RIGHT,
00196 JUSTIFIED,
00197 FORCED
00198 };
00199
00200 enum class VerticalAlignment
00201 {
00202 TOP,
00203 CENTER,
00204 BOTTOM,
00205 JUSTIFIED
00206 };
00207
00208 enum class TabStopType
00209 {
00210 LEFT,
00211 CENTER,
00212 RIGHT,
00213 ALIGN
00214 };
00215
00216 struct TabStop
00217 {
00218 TabStopType type;
00219 double position;
00220 librevenge::RVNGString fillChar;
00221 librevenge::RVNGString alignChar;
00222
00223 bool isDefined() const
00224 {
00225 return position >= 0;
00226 }
00227
00228 TabStop()
00229 : type(TabStopType::LEFT), position(0.0), fillChar(), alignChar()
00230 { }
00231 };
00232
00233 struct ParagraphRule
00234 {
00235 double width;
00236 Color color;
00237 const LineStyle *lineStyle;
00238 double leftMargin;
00239 double rightMargin;
00240 double offset;
00241
00242 ParagraphRule()
00243 : width(1.0), color(0, 0, 0), lineStyle(nullptr), leftMargin(0), rightMargin(0), offset(0)
00244 { }
00245 };
00246
00247 struct ParagraphFormat
00248 {
00249 HorizontalAlignment alignment;
00250 Rect margin;
00251 double firstLineIndent;
00252 double leading;
00253 bool incrementalLeading;
00254 std::shared_ptr<ParagraphRule> ruleAbove;
00255 std::shared_ptr<ParagraphRule> ruleBelow;
00256 std::vector<TabStop> tabStops;
00257 std::shared_ptr<HJ> hj;
00258
00259 ParagraphFormat()
00260 : alignment(HorizontalAlignment::LEFT), margin(), firstLineIndent(0), leading(0), incrementalLeading(false),
00261 ruleAbove(nullptr), ruleBelow(nullptr), tabStops(), hj(nullptr)
00262 { }
00263 };
00264
00265 enum class ContentType
00266 {
00267 UNKNOWN,
00268 OBJECTS,
00269 NONE,
00270 TEXT,
00271 PICTURE
00272 };
00273
00274 struct TextSpec
00275 {
00276 const unsigned startIndex;
00277 const unsigned length;
00278
00279 unsigned endIndex() const
00280 {
00281 return startIndex + length - 1;
00282 }
00283
00284 unsigned afterEndIndex() const
00285 {
00286 return startIndex + length;
00287 }
00288
00289 bool overlaps(const TextSpec &other) const;
00290
00291 protected:
00292 TextSpec(unsigned start, unsigned len)
00293 : startIndex(start), length(len)
00294 { }
00295 };
00296
00297 struct CharFormatSpec : public TextSpec
00298 {
00299 std::shared_ptr<CharFormat> format;
00300
00301 CharFormatSpec(const std::shared_ptr<CharFormat> &f, unsigned start, unsigned len)
00302 : TextSpec(start, len), format(f)
00303 { }
00304 };
00305
00306 struct ParagraphSpec : public TextSpec
00307 {
00308 std::shared_ptr<ParagraphFormat> format;
00309
00310 ParagraphSpec(const std::shared_ptr<ParagraphFormat> &f, unsigned start, unsigned len)
00311 : TextSpec(start, len), format(f)
00312 { }
00313 };
00314
00315 struct Text
00316 {
00317 std::string text;
00318 const char *encoding;
00319 std::vector<ParagraphSpec> paragraphs;
00320 std::vector<CharFormatSpec> charFormats;
00321
00322 double maxFontSize() const;
00323 double maxFontSize(const ParagraphSpec ¶graph) const;
00324
00325 Text()
00326 : text(), encoding("cp1252"), paragraphs(), charFormats()
00327 { }
00328
00329 Text(const Text &other) = default;
00330 Text &operator=(const Text &other) = default;
00331 };
00332
00333 struct Arrow
00334 {
00335 const std::string path;
00336 const std::string viewbox;
00337 const double scale;
00338
00339 explicit Arrow(const std::string &d, const std::string &vbox = "0 0 10 10", double s = 3)
00340 : path(d), viewbox(vbox), scale(s)
00341 { }
00342 };
00343
00344 struct Frame
00345 {
00346 double width;
00347 boost::optional<Color> color;
00348 boost::optional<Color> gapColor;
00349 const LineStyle *lineStyle;
00350 const Arrow *startArrow;
00351 const Arrow *endArrow;
00352
00353 Frame()
00354 : width(1.0), color(), gapColor(), lineStyle(nullptr), startArrow(nullptr), endArrow(nullptr)
00355 { }
00356
00357 Frame(const Frame &other) = default;
00358 Frame &operator=(const Frame &other) = default;
00359 };
00360
00361 struct LinkedTextSettings
00362 {
00363 unsigned linkId;
00364 unsigned offsetIntoText;
00365 unsigned linkedIndex;
00366 unsigned nextLinkedIndex;
00367 boost::optional<unsigned> textLength;
00368
00369 LinkedTextSettings()
00370 : linkId(0), offsetIntoText(0), linkedIndex(0), nextLinkedIndex(0), textLength()
00371 { }
00372 };
00373
00374 struct TextObject
00375 {
00376 LinkedTextSettings linkSettings;
00377 boost::optional<std::shared_ptr<Text>> text;
00378
00379 TextObject()
00380 : linkSettings(), text()
00381 { }
00382
00383 bool isLinked() const;
00384 };
00385
00386 struct TextSettings
00387 {
00388 unsigned columnsCount;
00389 double gutterWidth;
00390 VerticalAlignment verticalAlignment;
00391 Rect inset;
00392 double rotation;
00393 double skew;
00394
00395 TextSettings()
00396 : columnsCount(1), gutterWidth(12.0), verticalAlignment(VerticalAlignment::TOP), inset(), rotation(0), skew(0)
00397 { }
00398 };
00399
00400 enum class TextPathAlignment
00401 {
00402 ASCENT,
00403 CENTER,
00404 BASELINE,
00405 DESCENT
00406 };
00407
00408 enum class TextPathLineAlignment
00409 {
00410 TOP,
00411 CENTER,
00412 BOTTOM
00413 };
00414
00415 struct TextPathSettings
00416 {
00417 bool rotate;
00418 bool skew;
00419 TextPathAlignment alignment;
00420 TextPathLineAlignment lineAlignment;
00421
00422 TextPathSettings()
00423 : rotate(false), skew(false), alignment(TextPathAlignment::BASELINE), lineAlignment(TextPathLineAlignment::TOP)
00424 { }
00425 };
00426
00427 struct CurveComponent
00428 {
00429 Rect boundingBox;
00430 std::vector<Point> points;
00431
00432 CurveComponent()
00433 : boundingBox(), points()
00434 { }
00435 };
00436
00437 struct Object
00438 {
00439 Rect boundingBox;
00440 bool runaround;
00441 unsigned zIndex;
00442
00443 protected:
00444 Object()
00445 : boundingBox(), runaround(false), zIndex(0)
00446 { }
00447 };
00448
00449 struct Line : Object
00450 {
00451 double rotation;
00452 Frame style;
00453 std::vector<CurveComponent> curveComponents;
00454
00455 Line()
00456 : rotation(0), style(), curveComponents()
00457 { }
00458 };
00459
00460 struct TextPath : Line, TextObject
00461 {
00462 TextPathSettings settings;
00463
00464 TextPath()
00465 : settings()
00466 { }
00467 };
00468
00469 enum class CornerType
00470 {
00471 DEFAULT,
00472 ROUNDED,
00473 BEVELED,
00474 CONCAVE
00475 };
00476
00477 enum class BoxType
00478 {
00479 UNKNOWN,
00480 RECTANGLE,
00481 OVAL,
00482 POLYGON,
00483 BEZIER
00484 };
00485
00486 struct Box : Object
00487 {
00488 boost::optional<Fill> fill;
00489 Frame frame;
00490 BoxType boxType;
00491 CornerType cornerType;
00492 double cornerRadius;
00493 double rotation;
00494 std::vector<Point> customPoints;
00495 std::vector<CurveComponent> curveComponents;
00496
00497 Box()
00498 : fill(), frame(), boxType(BoxType::UNKNOWN), cornerType(CornerType::DEFAULT), cornerRadius(0.0), rotation(0),
00499 customPoints(), curveComponents()
00500 { }
00501 };
00502
00503 struct TextBox : Box, TextObject
00504 {
00505 TextSettings settings;
00506
00507 TextBox()
00508 : settings()
00509 { }
00510 };
00511
00512 struct PictureBox : Box
00513 {
00514 double pictureRotation;
00515 double pictureSkew;
00516 double offsetLeft;
00517 double offsetTop;
00518 double scaleHor;
00519 double scaleVert;
00520
00521 PictureBox()
00522 : pictureRotation(0.0), pictureSkew(0.0),
00523 offsetLeft(0.0), offsetTop(0.0), scaleHor(0.0), scaleVert(0.0)
00524 { }
00525 };
00526
00527 struct Group : Object
00528 {
00529 std::vector<unsigned> objectsIndexes;
00530
00531 Group()
00532 : objectsIndexes()
00533 { }
00534 };
00535
00536 struct PageSettings
00537 {
00538 Rect offset;
00539
00540 PageSettings()
00541 : offset()
00542 { }
00543 };
00544
00545 struct Page
00546 {
00547 std::vector<PageSettings> pageSettings;
00548 unsigned objectsCount;
00549
00550 Page()
00551 : pageSettings(), objectsCount(0)
00552 { }
00553
00554 bool isFacing() const
00555 {
00556 return pageSettings.size() == 2;
00557 }
00558 };
00559
00560 struct QXPDocumentProperties
00561 {
00562 QXPDocumentProperties()
00563 : superscriptOffset(1.0 / 3)
00564 , superscriptHScale(1.0)
00565 , superscriptVScale(1.0)
00566 , subscriptOffset(-1.0 / 3)
00567 , subscriptHScale(1.0)
00568 , subscriptVScale(1.0)
00569 , superiorHScale(0.5)
00570 , superiorVScale(0.5)
00571 , m_autoLeading(0.2)
00572 {
00573 }
00574
00575 double superscriptOffset;
00576 double superscriptHScale;
00577 double superscriptVScale;
00578 double subscriptOffset;
00579 double subscriptHScale;
00580 double subscriptVScale;
00581 double superiorHScale;
00582 double superiorVScale;
00583
00584 void setAutoLeading(const double val);
00585 double autoLeading() const;
00586
00587
00588 bool isIncrementalAutoLeading() const
00589 {
00590 return autoLeading() < 0 || autoLeading() > 1;
00591 }
00592
00593 private:
00594 double m_autoLeading;
00595 };
00596
00597 }
00598
00599 #endif // QXPTYPES_H_INCLUDED
00600
00601