ZMFTypes.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is a part of the libzmf project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef ZMFTYPES_H_INCLUDED
00011 #define ZMFTYPES_H_INCLUDED
00012 
00013 #include <vector>
00014 #include <memory>
00015 
00016 #include <boost/optional.hpp>
00017 #include <boost/variant.hpp>
00018 
00019 #include "libzmf_utils.h"
00020 
00021 namespace libzmf
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 rotate(double rotation, const Point &center) 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 BoundingBox
00047 {
00048   BoundingBox(const std::vector<Point> &points);
00049 
00050   const std::vector<Point> &points() const;
00051 
00052   double width() const;
00053   double height() const;
00054 
00055   Point center() const;
00056   Point topLeft() const;
00057 
00058   double rotation() const;
00059 
00060   int p1Quadrant() const;
00061   int p2Quadrant() const;
00062 
00063   bool mirrorHorizontal() const;
00064   bool mirrorVertical() const;
00065 
00066 private:
00067   int quadrant(const Point &p) const;
00068 
00069   const std::vector<Point> m_points;
00070   double m_width;
00071   double m_height;
00072   Point m_center;
00073   double m_rotation;
00074   int m_p1Quadrant;
00075   int m_p2Quadrant;
00076   bool m_mirrorHorizontal;
00077   bool m_mirrorVertical;
00078 };
00079 
00080 enum class CurveType
00081 {
00082   LINE,
00083   BEZIER_CURVE
00084 };
00085 
00086 struct Curve
00087 {
00088   std::vector<Point> points;
00089   std::vector<CurveType> sectionTypes;
00090   bool closed;
00091 
00092   Curve()
00093     : points(), sectionTypes(), closed(false)
00094   {  }
00095 };
00096 
00097 struct Color
00098 {
00099   uint8_t red;
00100   uint8_t green;
00101   uint8_t blue;
00102 
00103   Color()
00104     : red(0), green(0), blue(0)
00105   {  }
00106 
00107   Color(uint8_t r, uint8_t g, uint8_t b)
00108     : red(r), green(g), blue(b)
00109   {  }
00110 
00111   librevenge::RVNGString toString() const;
00112 };
00113 
00114 enum class LineCapType
00115 {
00116   BUTT,
00117   FLAT,
00118   ROUND,
00119   POINTED
00120 };
00121 
00122 enum class LineJoinType
00123 {
00124   MITER,
00125   ROUND,
00126   BEVEL
00127 };
00128 
00129 struct Arrow
00130 {
00131   std::vector<Curve> curves;
00132   double lineEndX;
00133 
00134   Arrow()
00135     : curves(), lineEndX(0.0)
00136   { }
00137 };
00138 
00139 typedef std::shared_ptr<Arrow> ArrowPtr;
00140 
00141 struct Pen
00142 {
00143   Color color;
00144   double width;
00145   LineCapType lineCapType;
00146   LineJoinType lineJoinType;
00147   std::vector<double> dashPattern;
00148   double dashDistance;
00149   ArrowPtr startArrow;
00150   ArrowPtr endArrow;
00151   bool isInvisible;
00152 
00153   Pen()
00154     : color(), width(0.0),
00155       lineCapType(LineCapType::BUTT), lineJoinType(LineJoinType::MITER),
00156       dashPattern(), dashDistance(0),
00157       startArrow(), endArrow(),
00158       isInvisible(false)
00159   {  }
00160 
00161   Pen(Color c)
00162     : color(c),
00163       width(0.0),
00164       lineCapType(LineCapType::BUTT), lineJoinType(LineJoinType::MITER),
00165       dashPattern(), dashDistance(0),
00166       startArrow(), endArrow(),
00167       isInvisible(false)
00168   {  }
00169 };
00170 
00171 struct GradientStop
00172 {
00173   Color color;
00174   double offset;
00175 
00176   GradientStop()
00177     : color(), offset(0.0)
00178   { }
00179 };
00180 
00181 enum class GradientType
00182 {
00183   LINEAR,
00184   RADIAL,
00185   CONICAL,
00186   CROSS,
00187   RECTANGULAR,
00188   FLEXIBLE
00189 };
00190 
00191 struct Gradient
00192 {
00193   GradientType type;
00194   std::vector<GradientStop> stops;
00195   double angle;
00196   Point center;
00197 
00198   Gradient()
00199     : type(), stops(), angle(0.0), center(0.5, 0.5)
00200   { }
00201 };
00202 
00203 struct Image
00204 {
00205   uint32_t width;
00206   uint32_t height;
00207   librevenge::RVNGBinaryData data;
00208 
00209   Image()
00210     : width(0), height(0), data()
00211   { }
00212 
00213   Image(uint32_t w, uint32_t h, librevenge::RVNGBinaryData d)
00214     : width(w), height(h), data(d)
00215   { }
00216 };
00217 
00218 struct ImageFill
00219 {
00220   Image image;
00221   bool tile;
00222   double tileWidth;
00223   double tileHeight;
00224 
00225   ImageFill()
00226     : image(), tile(false), tileWidth(0.0), tileHeight(0.0)
00227   { }
00228 };
00229 
00230 typedef boost::variant<Color, Gradient, ImageFill> Fill;
00231 
00232 struct Transparency
00233 {
00234   Color color;
00235 
00236   double opacity() const
00237   {
00238     return 1.0 - color.red / 255.0;
00239   }
00240 
00241   Transparency()
00242     : color()
00243   { }
00244 };
00245 
00246 struct Shadow
00247 {
00248   Point offset;
00249   double angle;
00250   double opacity;
00251   Color color;
00252 
00253   Shadow()
00254     : offset(), angle(0.0), opacity(1.0), color()
00255   { }
00256 };
00257 
00258 struct Style
00259 {
00260   boost::optional<Pen> pen;
00261   boost::optional<Fill> fill;
00262   boost::optional<Transparency> transparency;
00263   boost::optional<Shadow> shadow;
00264 
00265   Style()
00266     : pen(), fill(), transparency(), shadow()
00267   { }
00268 };
00269 
00270 struct Font
00271 {
00272   librevenge::RVNGString name;
00273   double size;
00274   bool isBold;
00275   bool isItalic;
00276   boost::optional<Fill> fill;
00277   boost::optional<Pen> outline;
00278 
00279   Font()
00280     : name("Arial"), size(24.0), isBold(false), isItalic(false),
00281       fill(Color(0, 0, 0)), outline()
00282   { }
00283 };
00284 
00285 struct Span
00286 {
00287   librevenge::RVNGString text;
00288   uint32_t length;
00289   Font font;
00290 
00291   Span()
00292     : text(), length(0), font()
00293   { }
00294 };
00295 
00296 enum class HorizontalAlignment
00297 {
00298   LEFT,
00299   RIGHT,
00300   BLOCK,
00301   CENTER,
00302   FULL
00303 };
00304 
00305 enum class VerticalAlignment
00306 {
00307   TOP,
00308   MIDDLE,
00309   BOTTOM
00310 };
00311 
00312 struct ParagraphStyle
00313 {
00314   double lineSpacing;
00315   HorizontalAlignment alignment;
00316   Font font;
00317 
00318   ParagraphStyle()
00319     : lineSpacing(1.2), alignment(HorizontalAlignment::LEFT), font()
00320   { }
00321 };
00322 
00323 struct Paragraph
00324 {
00325   std::vector<Span> spans;
00326   ParagraphStyle style;
00327 
00328   Paragraph()
00329     : spans(), style()
00330   { }
00331 };
00332 
00333 struct Text
00334 {
00335   std::vector<Paragraph> paragraphs;
00336 
00337   Text()
00338     : paragraphs()
00339   { }
00340 };
00341 
00342 struct Cell
00343 {
00344   Text text;
00345   boost::optional<Fill> fill;
00346   boost::optional<Pen> leftBorder;
00347   boost::optional<Pen> rightBorder;
00348   boost::optional<Pen> topBorder;
00349   boost::optional<Pen> bottomBorder;
00350 
00351   Cell()
00352     : text(), fill(),
00353       leftBorder(), rightBorder(), topBorder(), bottomBorder()
00354   { }
00355 };
00356 
00357 struct Row
00358 {
00359   std::vector<Cell> cells;
00360   double height;
00361 
00362   Row()
00363     : cells(), height(0.0)
00364   { }
00365 };
00366 
00367 struct Column
00368 {
00369   double width;
00370 
00371   Column()
00372     : width(0.0)
00373   { }
00374 };
00375 
00376 struct Table
00377 {
00378   std::vector<Row> rows;
00379   std::vector<Column> columns;
00380   double width;
00381   double height;
00382   Point topLeftPoint;
00383 
00384   Table()
00385     : rows(), columns(), width(0.0), height(0.0), topLeftPoint()
00386   { }
00387 };
00388 
00389 struct ZMFPageSettings
00390 {
00391   double width;
00392   double height;
00393   double leftOffset;
00394   double topOffset;
00395   Color color;
00396 
00397   ZMFPageSettings()
00398     : width(0.0), height(0.0), leftOffset(0.0), topOffset(0.0), color()
00399   { }
00400   ZMFPageSettings(double w, double h, double left, double top, Color c = Color(255, 255, 255))
00401     : width(w), height(h), leftOffset(left), topOffset(top), color(c)
00402   { }
00403 };
00404 
00405 }
00406 
00407 #endif // ZMFTYPES_H_INCLUDED
00408 
00409 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */