00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __CDRTYPES_H__
00011 #define __CDRTYPES_H__
00012
00013 #include <vector>
00014 #include <math.h>
00015 #include <librevenge/librevenge.h>
00016 #include "CDRTransforms.h"
00017 #include "CDRPath.h"
00018 #include "libcdr_utils.h"
00019
00020 namespace libcdr
00021 {
00022
00023 struct CDRBox
00024 {
00025 double m_x;
00026 double m_y;
00027 double m_w;
00028 double m_h;
00029 CDRBox()
00030 : m_x(0.0), m_y(0.0), m_w(0.0), m_h(0.0) {}
00031 CDRBox(double x0, double y0, double x1, double y1)
00032 : m_x(x0 < x1 ? x0 : x1), m_y(y0 < y1 ? y0 : y1), m_w(fabs(x1-x0)), m_h(fabs(y1-y0)) {}
00033 double getWidth() const
00034 {
00035 return m_w;
00036 }
00037 double getHeight() const
00038 {
00039 return m_h;
00040 }
00041 double getMinX() const
00042 {
00043 return m_x;
00044 }
00045 double getMinY() const
00046 {
00047 return m_y;
00048 }
00049
00050 };
00051
00052 struct CDRColor
00053 {
00054 unsigned short m_colorModel;
00055 unsigned m_colorValue;
00056 CDRColor() : m_colorModel(0), m_colorValue(0) {}
00057 CDRColor(unsigned short colorModel, unsigned colorValue)
00058 : m_colorModel(colorModel), m_colorValue(colorValue) {}
00059 };
00060
00061 struct CDRGradientStop
00062 {
00063 CDRColor m_color;
00064 double m_offset;
00065 CDRGradientStop() : m_color(), m_offset(0.0) {}
00066 CDRGradientStop(const CDRColor &color, double offset)
00067 : m_color(color), m_offset(offset) {}
00068 };
00069
00070 struct CDRGradient
00071 {
00072 unsigned char m_type;
00073 unsigned char m_mode;
00074 double m_angle;
00075 double m_midPoint;
00076 int m_edgeOffset;
00077 int m_centerXOffset;
00078 int m_centerYOffset;
00079 std::vector<CDRGradientStop> m_stops;
00080 CDRGradient()
00081 : 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() {}
00082 };
00083
00084 struct CDRImageFill
00085 {
00086 unsigned id;
00087 double width;
00088 double height;
00089 bool isRelative;
00090 double xOffset;
00091 double yOffset;
00092 double rcpOffset;
00093 unsigned char flags;
00094 CDRImageFill() : id(0), width(0.0), height(0.0), isRelative(false), xOffset(0.0), yOffset(0.0), rcpOffset(0.0), flags(0)
00095 {}
00096 CDRImageFill(unsigned i, double w, double h, bool r, double x, double y, double o, unsigned char f)
00097 : id(i), width(w), height(h), isRelative(r), xOffset(x), yOffset(y), rcpOffset(o), flags(f) {}
00098 };
00099
00100 struct CDRFillStyle
00101 {
00102 unsigned short fillType;
00103 CDRColor color1, color2;
00104 CDRGradient gradient;
00105 CDRImageFill imageFill;
00106 CDRFillStyle()
00107 : fillType((unsigned short)-1), color1(), color2(), gradient(), imageFill() {}
00108 CDRFillStyle(unsigned short ft, CDRColor c1, CDRColor c2, const CDRGradient &gr, const CDRImageFill &img)
00109 : fillType(ft), color1(c1), color2(c2), gradient(gr), imageFill(img) {}
00110 };
00111
00112 struct CDRLineStyle
00113 {
00114 unsigned short lineType;
00115 unsigned short capsType;
00116 unsigned short joinType;
00117 double lineWidth;
00118 double stretch;
00119 double angle;
00120 CDRColor color;
00121 std::vector<unsigned> dashArray;
00122 CDRPath startMarker;
00123 CDRPath endMarker;
00124 CDRLineStyle()
00125 : lineType((unsigned short)-1), capsType(0), joinType(0), lineWidth(0.0),
00126 stretch(0.0), angle(0.0), color(), dashArray(),
00127 startMarker(), endMarker() {}
00128 CDRLineStyle(unsigned short lt, unsigned short ct, unsigned short jt,
00129 double lw, double st, double a, const CDRColor &c, const std::vector<unsigned> &da,
00130 const CDRPath &sm, const CDRPath &em)
00131 : lineType(lt), capsType(ct), joinType(jt), lineWidth(lw),
00132 stretch(st), angle(a), color(c), dashArray(da),
00133 startMarker(sm), endMarker(em) {}
00134 };
00135
00136 struct CDRCharacterStyle
00137 {
00138 unsigned short m_charSet;
00139 librevenge::RVNGString m_fontName;
00140 double m_fontSize;
00141 unsigned m_align;
00142 double m_leftIndent, m_firstIndent, m_rightIndent;
00143 CDRLineStyle m_lineStyle;
00144 CDRFillStyle m_fillStyle;
00145 unsigned m_parentId;
00146 CDRCharacterStyle()
00147 : m_charSet((unsigned short)-1), m_fontName(),
00148 m_fontSize(0.0), m_align(0), m_leftIndent(0.0), m_firstIndent(0.0),
00149 m_rightIndent(0.0), m_lineStyle(), m_fillStyle(), m_parentId(0)
00150 {
00151 m_fontName.clear();
00152 }
00153 void overrideCharacterStyle(const CDRCharacterStyle &override)
00154 {
00155 if (override.m_charSet != (unsigned short)-1 || override.m_fontName.len())
00156 {
00157 m_charSet = override.m_charSet;
00158 m_fontName = override.m_fontName;
00159 }
00160 if (!CDR_ALMOST_ZERO(override.m_fontSize))
00161 m_fontSize = override.m_fontSize;
00162 if (override.m_align)
00163 m_align = override.m_align;
00164 if (override.m_leftIndent != 0.0 && override.m_firstIndent != 0.0 && override.m_rightIndent != 0.0)
00165 {
00166 m_leftIndent = override.m_leftIndent;
00167 m_firstIndent = override.m_firstIndent;
00168 m_rightIndent = override.m_rightIndent;
00169 }
00170 if (override.m_lineStyle.lineType != (unsigned short)-1)
00171 m_lineStyle = override.m_lineStyle;
00172 if (override.m_fillStyle.fillType != (unsigned short)-1)
00173 m_fillStyle = override.m_fillStyle;
00174 }
00175 };
00176
00177 struct CDRPolygon
00178 {
00179 unsigned m_numAngles;
00180 unsigned m_nextPoint;
00181 double m_rx;
00182 double m_ry;
00183 double m_cx;
00184 double m_cy;
00185 CDRPolygon() : m_numAngles(0), m_nextPoint(0), m_rx(0.0), m_ry(0.0), m_cx(0.0), m_cy(0.0) {}
00186 CDRPolygon(unsigned numAngles, unsigned nextPoint, double rx, double ry, double cx, double cy)
00187 : m_numAngles(numAngles), m_nextPoint(nextPoint), m_rx(rx), m_ry(ry), m_cx(cx), m_cy(cy) {}
00188 void create(CDRPath &path) const;
00189 };
00190
00191 struct CDRImage
00192 {
00193 librevenge::RVNGBinaryData m_image;
00194 double m_x1;
00195 double m_x2;
00196 double m_y1;
00197 double m_y2;
00198 CDRImage() : m_image(), m_x1(0.0), m_x2(0.0), m_y1(0.0), m_y2(0.0) {}
00199 CDRImage(const librevenge::RVNGBinaryData &image, double x1, double x2, double y1, double y2)
00200 : m_image(image), m_x1(x1), m_x2(x2), m_y1(y1), m_y2(y2) {}
00201 double getMiddleX() const
00202 {
00203 return (m_x1 + m_x2) / 2.0;
00204 }
00205 double getMiddleY() const
00206 {
00207 return (m_y1 + m_y2) / 2.0;
00208 }
00209 const librevenge::RVNGBinaryData &getImage() const
00210 {
00211 return m_image;
00212 }
00213 };
00214
00215 struct CDRPattern
00216 {
00217 unsigned width;
00218 unsigned height;
00219 std::vector<unsigned char> pattern;
00220 CDRPattern() : width(0), height(0), pattern() {}
00221 CDRPattern(unsigned w, unsigned h, const std::vector<unsigned char> &p)
00222 : width(w), height(h), pattern(p) {}
00223 };
00224
00225 struct CDRPage
00226 {
00227 double width;
00228 double height;
00229 double offsetX;
00230 double offsetY;
00231 CDRPage() : width(0.0), height(0.0), offsetX(0.0), offsetY(0.0) {}
00232 CDRPage(double w, double h, double ox, double oy)
00233 : width(w), height(h), offsetX(ox), offsetY(oy) {}
00234 };
00235
00236 struct CDRSplineData
00237 {
00238 std::vector<std::pair<double, double> > points;
00239 std::vector<unsigned> knotVector;
00240 CDRSplineData() : points(), knotVector() {}
00241 CDRSplineData(const std::vector<std::pair<double, double> > &ps, const std::vector<unsigned> &kntv)
00242 : points(ps), knotVector(kntv) {}
00243 void clear()
00244 {
00245 points.clear();
00246 knotVector.clear();
00247 }
00248 bool empty()
00249 {
00250 return (points.empty() || knotVector.empty());
00251 }
00252 void create(CDRPath &path) const;
00253 };
00254
00255 struct WaldoRecordInfo
00256 {
00257 WaldoRecordInfo(unsigned char t, unsigned i, unsigned o)
00258 : type(t), id(i), offset(o) {}
00259 WaldoRecordInfo() : type(0), id(0), offset(0) {}
00260 unsigned char type;
00261 unsigned id;
00262 unsigned offset;
00263 };
00264
00265 struct WaldoRecordType1
00266 {
00267 WaldoRecordType1(unsigned id, unsigned short next, unsigned short previous,
00268 unsigned short child, unsigned short parent, unsigned short flags,
00269 double x0, double y0, double x1, double y1, const CDRTransform &trafo)
00270 : m_id(id), m_next(next), m_previous(previous), m_child(child), m_parent(parent),
00271 m_flags(flags), m_x0(x0), m_y0(y0), m_x1(x1), m_y1(y1), m_trafo(trafo) {}
00272 WaldoRecordType1()
00273 : m_id(0), m_next(0), m_previous(0), m_child(0), m_parent(0), m_flags(0),
00274 m_x0(0.0), m_y0(0.0), m_x1(0.0), m_y1(0.0), m_trafo() {}
00275 unsigned m_id;
00276 unsigned short m_next;
00277 unsigned short m_previous;
00278 unsigned short m_child;
00279 unsigned short m_parent;
00280 unsigned short m_flags;
00281 double m_x0;
00282 double m_y0;
00283 double m_x1;
00284 double m_y1;
00285 CDRTransform m_trafo;
00286 };
00287
00288 struct CDRCMYKColor
00289 {
00290 CDRCMYKColor(double cyan, double magenta, double yellow, double black)
00291 : c(cyan), m(magenta), y(yellow), k(black) {}
00292 ~CDRCMYKColor() {}
00293 double c;
00294 double m;
00295 double y;
00296 double k;
00297 };
00298
00299 struct CDRRGBColor
00300 {
00301 CDRRGBColor(double red, double green, double blue)
00302 : r(red), g(green), b(blue) {}
00303 ~CDRRGBColor() {}
00304 double r;
00305 double g;
00306 double b;
00307 };
00308
00309 struct CDRLab2Color
00310 {
00311 CDRLab2Color(double l, double A, double B)
00312 : L(l), a(A), b(B) {}
00313 ~CDRLab2Color() {}
00314 double L;
00315 double a;
00316 double b;
00317 };
00318
00319 struct CDRLab4Color
00320 {
00321 CDRLab4Color(double l, double A, double B)
00322 : L(l), a(A), b(B) {}
00323 ~CDRLab4Color() {}
00324 double L;
00325 double a;
00326 double b;
00327 };
00328
00329 struct CDRText
00330 {
00331 CDRText() : m_text(), m_charStyle() {}
00332 CDRText(const librevenge::RVNGString &text, const CDRCharacterStyle &charStyle)
00333 : m_text(text), m_charStyle(charStyle) {}
00334 librevenge::RVNGString m_text;
00335 CDRCharacterStyle m_charStyle;
00336 };
00337
00338 struct CDRTextLine
00339 {
00340 CDRTextLine() : m_line() {}
00341 CDRTextLine(const CDRTextLine &line) : m_line(line.m_line) {}
00342 void append(const CDRText &text)
00343 {
00344 m_line.push_back(text);
00345 }
00346 void clear()
00347 {
00348 m_line.clear();
00349 }
00350 std::vector<CDRText> m_line;
00351 };
00352
00353 struct CDRFont
00354 {
00355 CDRFont() : m_name(), m_encoding(0) {}
00356 CDRFont(const librevenge::RVNGString &name, unsigned short encoding)
00357 : m_name(name), m_encoding(encoding) {}
00358 CDRFont(const CDRFont &font)
00359 : m_name(font.m_name), m_encoding(font.m_encoding) {}
00360 librevenge::RVNGString m_name;
00361 unsigned short m_encoding;
00362 };
00363
00364 }
00365
00366 #endif
00367