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