CDRTypes.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libcdr
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
00017  *
00018  * All Rights Reserved.
00019  *
00020  * For minor contributions see the git repository.
00021  *
00022  * Alternatively, the contents of this file may be used under the terms of
00023  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00024  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00025  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00026  * instead of those above.
00027  */
00028 
00029 #ifndef __CDRTYPES_H__
00030 #define __CDRTYPES_H__
00031 
00032 #include <vector>
00033 #include <math.h>
00034 #include <libwpd/libwpd.h>
00035 
00036 namespace libcdr
00037 {
00038 class CDRPath;
00039 
00040 struct CDRTransform
00041 {
00042   double m_v0;
00043   double m_v1;
00044   double m_x0;
00045   double m_v3;
00046   double m_v4;
00047   double m_y0;
00048   CDRTransform()
00049     : m_v0(1.0), m_v1(0.0), m_x0(0.0),
00050       m_v3(0.0), m_v4(1.0), m_y0(0.0) {}
00051   CDRTransform(double v0, double v1, double x0, double v3, double v4, double y0)
00052     : m_v0(v0), m_v1(v1), m_x0(x0), m_v3(v3), m_v4(v4), m_y0(y0) {}
00053 
00054   void applyToPoint(double &x, double &y) const;
00055   void applyToArc(double &rx, double &ry, double &rotation, bool &sweep, double &x, double &y) const;
00056 };
00057 
00058 struct CDRBBox
00059 {
00060   double m_x;
00061   double m_y;
00062   double m_w;
00063   double m_h;
00064   CDRBBox()
00065     : m_x(0.0), m_y(0.0), m_w(0.0), m_h(0.0) {}
00066   CDRBBox(const CDRBBox &box)
00067     : m_x(box.m_x), m_y(box.m_y), m_w(box.m_w), m_h(box.m_h) {}
00068   CDRBBox(double x0, double y0, double x1, double y1)
00069     : m_x(x0 < x1 ? x0 : x1), m_y(y0 < y1 ? y0 : y1), m_w(fabs(x1-x0)), m_h(fabs(y1-y0)) {}
00070   double getWidth() const
00071   {
00072     return m_w;
00073   }
00074   double getHeight() const
00075   {
00076     return m_h;
00077   }
00078   double getMinX() const
00079   {
00080     return m_x;
00081   }
00082   double getMinY() const
00083   {
00084     return m_y;
00085   }
00086 
00087 };
00088 
00089 struct CDRColor
00090 {
00091   unsigned short m_colorModel;
00092   unsigned m_colorValue;
00093   CDRColor() : m_colorModel(0), m_colorValue(0) {}
00094   CDRColor(unsigned short colorModel, unsigned colorValue)
00095     : m_colorModel(colorModel), m_colorValue(colorValue) {}
00096   CDRColor(const CDRColor &color)
00097     : m_colorModel(color.m_colorModel), m_colorValue(color.m_colorValue) {}
00098 };
00099 
00100 struct CDRGradientStop
00101 {
00102   CDRColor m_color;
00103   double m_offset;
00104   CDRGradientStop() : m_color(), m_offset(0.0) {}
00105   CDRGradientStop(const CDRColor &color, double offset)
00106     : m_color(color), m_offset(offset) {}
00107   CDRGradientStop(const CDRGradientStop &stop)
00108     : m_color(stop.m_color), m_offset(stop.m_offset) {}
00109 };
00110 
00111 struct CDRGradient
00112 {
00113   unsigned char m_type;
00114   unsigned char m_mode;
00115   double m_angle;
00116   double m_midPoint;
00117   int m_edgeOffset;
00118   int m_centerXOffset;
00119   int m_centerYOffset;
00120   std::vector<CDRGradientStop> m_stops;
00121   CDRGradient()
00122     : m_type(0), m_mode(0), m_angle(0.0), m_midPoint(0.0), m_edgeOffset(0), m_centerXOffset(0), m_centerYOffset(0), m_stops() {}
00123   CDRGradient(const CDRGradient &gradient)
00124     : m_type(gradient.m_type), m_mode(gradient.m_mode), m_angle(gradient.m_angle), m_midPoint(gradient.m_midPoint),
00125       m_edgeOffset(gradient.m_edgeOffset), m_centerXOffset(gradient.m_centerXOffset), m_centerYOffset(gradient.m_centerYOffset),
00126       m_stops(gradient.m_stops) {}
00127 };
00128 
00129 struct CDRImageFill
00130 {
00131   unsigned id;
00132   double width;
00133   double height;
00134   bool isRelative;
00135   double xOffset;
00136   double yOffset;
00137   double rcpOffset;
00138   unsigned char flags;
00139   CDRImageFill() : id(0), width(0.0), height(0.0), isRelative(false), xOffset(0.0), yOffset(0.0), rcpOffset(0.0), flags(0)
00140   {}
00141   CDRImageFill(unsigned i, double w, double h, bool r, double x, double y, double o, unsigned char f)
00142     : id(i), width(w), height(h), isRelative(r), xOffset(x), yOffset(y), rcpOffset(o), flags(f) {}
00143 };
00144 
00145 struct CDRFillStyle
00146 {
00147   unsigned short fillType;
00148   CDRColor color1, color2;
00149   CDRGradient gradient;
00150   CDRImageFill imageFill;
00151   CDRFillStyle()
00152     : fillType(0), color1(), color2(), gradient(), imageFill() {}
00153   CDRFillStyle(unsigned short ft, CDRColor c1, CDRColor c2, const CDRGradient &gr, const CDRImageFill &img)
00154     : fillType(ft), color1(c1), color2(c2), gradient(gr), imageFill(img) {}
00155   CDRFillStyle(const CDRFillStyle &style)
00156     : fillType(style.fillType), color1(style.color1), color2(style.color2), gradient(style.gradient), imageFill(style.imageFill) {}
00157 };
00158 
00159 struct CDRLineStyle
00160 {
00161   unsigned short lineType;
00162   unsigned short capsType;
00163   unsigned short joinType;
00164   double lineWidth;
00165   double stretch;
00166   double angle;
00167   CDRColor color;
00168   std::vector<unsigned short> dashArray;
00169   unsigned startMarkerId;
00170   unsigned endMarkerId;
00171   CDRLineStyle()
00172     : lineType(0), capsType(0), joinType(0), lineWidth(0.0),
00173       stretch(0.0), angle(0.0), color(), dashArray(),
00174       startMarkerId(0), endMarkerId(0) {}
00175   CDRLineStyle(unsigned short lt, unsigned short ct, unsigned short jt,
00176                double lw, double st, double a, const CDRColor &c, const std::vector<unsigned short> &da,
00177                unsigned smi, unsigned emi)
00178     : lineType(lt), capsType(ct), joinType(jt), lineWidth(lw),
00179       stretch(st), angle(a), color(c), dashArray(da),
00180       startMarkerId(smi), endMarkerId(emi) {}
00181 };
00182 
00183 struct CDRCharacterStyle
00184 {
00185   unsigned short m_charSet;
00186   unsigned short m_fontId;
00187   double m_fontSize;
00188   CDRCharacterStyle()
00189     : m_charSet(0), m_fontId(0), m_fontSize(0.0) {}
00190   CDRCharacterStyle(unsigned short charSet, unsigned short fontId, double fontSize)
00191     : m_charSet(charSet), m_fontId(fontId), m_fontSize(fontSize) {}
00192   void overrideCharacterStyle(const CDRCharacterStyle &override)
00193   {
00194     if (override.m_charSet)
00195       m_charSet = override.m_charSet;
00196     if (override.m_fontId)
00197       m_fontId = override.m_fontId;
00198     if (override.m_fontSize > 0.0)
00199       m_fontSize = override.m_fontSize;
00200   }
00201 };
00202 
00203 struct CDRPolygon
00204 {
00205   unsigned m_numAngles;
00206   unsigned m_nextPoint;
00207   double m_rx;
00208   double m_ry;
00209   double m_cx;
00210   double m_cy;
00211   CDRPolygon() : m_numAngles(0), m_nextPoint(0), m_rx(0.0), m_ry(0.0), m_cx(0.0), m_cy(0.0) {}
00212   CDRPolygon(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy)
00213     : m_numAngles(numAngles), m_nextPoint(nextPoint), m_rx(rx), m_ry(ry), m_cx(cx), m_cy(cy) {}
00214   void create(CDRPath &path) const;
00215 };
00216 
00217 struct CDRImage
00218 {
00219   WPXBinaryData m_image;
00220   double m_x1;
00221   double m_x2;
00222   double m_y1;
00223   double m_y2;
00224   CDRImage() : m_image(), m_x1(0.0), m_x2(0.0), m_y1(0.0), m_y2(0.0) {}
00225   CDRImage(const WPXBinaryData &image, double x1, double x2, double y1, double y2)
00226     : m_image(image), m_x1(x1), m_x2(x2), m_y1(y1), m_y2(y2) {}
00227   double getMiddleX() const
00228   {
00229     return (m_x1 + m_x2) / 2.0;
00230   }
00231   double getMiddleY() const
00232   {
00233     return (m_y1 + m_y2) / 2.0;
00234   }
00235   double getWidth() const
00236   {
00237     return fabs(m_x1 - m_x2);
00238   }
00239   double getHeight() const
00240   {
00241     return fabs(m_y1 - m_y2);
00242   }
00243   const WPXBinaryData &getImage() const
00244   {
00245     return m_image;
00246   }
00247 };
00248 
00249 struct CDRPattern
00250 {
00251   unsigned width;
00252   unsigned height;
00253   std::vector<unsigned char> pattern;
00254   CDRPattern() : width(0), height(0), pattern() {}
00255   CDRPattern(unsigned w, unsigned h, const std::vector<unsigned char> &p)
00256     : width(w), height(h), pattern(p) {}
00257 };
00258 
00259 struct CDRPage
00260 {
00261   double width;
00262   double height;
00263   double offsetX;
00264   double offsetY;
00265   CDRPage() : width(0.0), height(0.0), offsetX(0.0), offsetY(0.0) {}
00266   CDRPage(double w, double h, double ox, double oy)
00267     : width(w), height(h), offsetX(ox), offsetY(oy) {}
00268   CDRPage(const CDRPage &page)
00269     : width(page.width), height(page.height), offsetX(page.offsetX), offsetY(page.offsetY) {}
00270 };
00271 
00272 struct CDRSplineData
00273 {
00274   std::vector<std::pair<double, double> > points;
00275   std::vector<unsigned> knotVector;
00276   CDRSplineData() : points(), knotVector() {}
00277   CDRSplineData(const std::vector<std::pair<double, double> > &ps, const std::vector<unsigned> &kntv)
00278     : points(ps), knotVector(kntv) {}
00279   CDRSplineData(const CDRSplineData &data)
00280     : points(data.points), knotVector(data.knotVector) {}
00281   void clear()
00282   {
00283     points.clear();
00284     knotVector.clear();
00285   }
00286   bool empty()
00287   {
00288     return (points.empty() || knotVector.empty());
00289   }
00290   void create(CDRPath &path) const;
00291 };
00292 
00293 struct WaldoRecordInfo
00294 {
00295   WaldoRecordInfo(unsigned char t, unsigned i, unsigned o)
00296     : type(t), id(i), offset(o) {}
00297   WaldoRecordInfo() : type(0), id(0), offset(0) {}
00298   unsigned char type;
00299   unsigned id;
00300   unsigned offset;
00301 };
00302 
00303 struct WaldoRecordType1
00304 {
00305   WaldoRecordType1(unsigned id, unsigned short next, unsigned short previous,
00306                    unsigned short child, unsigned short parent, unsigned short flags,
00307                    double x0, double y0, double x1, double y1, const CDRTransform trafo)
00308     : m_id(id), m_next(next), m_previous(previous), m_child(child), m_parent(parent),
00309       m_flags(flags), m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1), m_trafo(trafo) {}
00310   WaldoRecordType1()
00311     : m_id(0), m_next(0), m_previous(0), m_child(0), m_parent(0), m_flags(0),
00312       m_x0(0.0), m_y0(0.0), m_x1(0.0), m_y1(0.0), m_trafo() {}
00313   WaldoRecordType1(const WaldoRecordType1 &record)
00314     : m_id(record.m_id), m_next(record.m_next), m_previous(record.m_previous),
00315       m_child(record.m_child), m_parent(record.m_parent), m_flags(record.m_flags),
00316       m_x0(record.m_x0), m_y0(record.m_y0), m_x1(record.m_x1), m_y1(record.m_y1),
00317       m_trafo(record.m_trafo) {}
00318   unsigned m_id;
00319   unsigned short m_next;
00320   unsigned short m_previous;
00321   unsigned short m_child;
00322   unsigned short m_parent;
00323   unsigned short m_flags;
00324   double m_x0;
00325   double m_y0;
00326   double m_x1;
00327   double m_y1;
00328   CDRTransform m_trafo;
00329 };
00330 
00331 struct CDRCMYKColor
00332 {
00333   CDRCMYKColor(unsigned colorValue, bool percentage = true);
00334   CDRCMYKColor(double cyan, double magenta, double yellow, double black)
00335     : c(cyan), m(magenta), y(yellow), k(black) {}
00336   CDRCMYKColor(const CDRCMYKColor &color)
00337     : c(color.c), m(color.m), y(color.y), k(color.k) {}
00338   ~CDRCMYKColor() {}
00339   double c;
00340   double m;
00341   double y;
00342   double k;
00343   void applyTint(double tint);
00344   unsigned getColorValue() const;
00345 };
00346 
00347 struct CDRRGBColor
00348 {
00349   CDRRGBColor(unsigned colorValue);
00350   CDRRGBColor(double red, double green, double blue)
00351     : r(red), g(green), b(blue) {}
00352   CDRRGBColor(const CDRRGBColor &color)
00353     : r(color.r), g(color.g), b(color.b) {}
00354   ~CDRRGBColor() {}
00355   double r;
00356   double g;
00357   double b;
00358   void applyTint(double tint);
00359   unsigned getColorValue() const;
00360 };
00361 
00362 struct CDRLab2Color
00363 {
00364   CDRLab2Color(unsigned colorValue);
00365   CDRLab2Color(double l, double A, double B)
00366     : L(l), a(A), b(B) {}
00367   CDRLab2Color(const CDRLab2Color &color)
00368     : L(color.L), a(color.a), b(color.b) {}
00369   ~CDRLab2Color() {}
00370   double L;
00371   double a;
00372   double b;
00373   void applyTint(double tint);
00374   unsigned getColorValue() const;
00375 };
00376 
00377 struct CDRLab4Color
00378 {
00379   CDRLab4Color(unsigned colorValue);
00380   CDRLab4Color(double l, double A, double B)
00381     : L(l), a(A), b(B) {}
00382   CDRLab4Color(const CDRLab2Color &color)
00383     : L(color.L), a(color.a), b(color.b) {}
00384   ~CDRLab4Color() {}
00385   double L;
00386   double a;
00387   double b;
00388   void applyTint(double tint);
00389   unsigned getColorValue() const;
00390 };
00391 
00392 struct CDRText
00393 {
00394   CDRText() : m_text(), m_charStyle() {}
00395   CDRText(const WPXString &text, const CDRCharacterStyle &charStyle)
00396     : m_text(text), m_charStyle(charStyle) {}
00397   WPXString m_text;
00398   CDRCharacterStyle m_charStyle;
00399 };
00400 
00401 } // namespace libcdr
00402 
00403 #endif /* __CDRTYPES_H__ */
00404 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */