Go to the documentation of this file.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 #ifndef __WPG2PARSER_H__
00029 #define __WPG2PARSER_H__
00030
00031 #include "WPGXParser.h"
00032 #include "WPGBrush.h"
00033 #include "WPGPen.h"
00034
00035 #include <map>
00036 #include <stack>
00037 #include <vector>
00038
00039 class WPG2TransformMatrix
00040 {
00041 public:
00042 double element[3][3];
00043
00044 WPG2TransformMatrix()
00045 {
00046
00047 element[0][0] = element[1][1] = 1; element[2][2] = 1;
00048 element[0][1] = element[0][2] = 0;
00049 element[1][0] = element[1][2] = 0;
00050 element[2][0] = element[2][1] = 0;
00051 }
00052
00053 void transform(long& x, long& y) const
00054 {
00055 long rx = (long)(element[0][0]*x + element[1][0]*y + element[2][0]);
00056 long ry = (long)(element[0][1]*x + element[1][1]*y + element[2][1]);
00057 x = rx;
00058 y = ry;
00059 }
00060
00061 libwpg::WPGPoint transform(const libwpg::WPGPoint& p) const
00062 {
00063 libwpg::WPGPoint point;
00064 point.x = element[0][0]*p.x + element[1][0]*p.y + element[2][0];
00065 point.y = element[0][1]*p.x + element[1][1]*p.y + element[2][1];
00066 return point;
00067 }
00068
00069 libwpg::WPGRect transform(const libwpg::WPGRect& r) const
00070 {
00071 libwpg::WPGRect rect;
00072 rect.x1 = element[0][0]*r.x1 + element[1][0]*r.y1 + element[2][0];
00073 rect.y1 = element[0][1]*r.x1 + element[1][1]*r.y1 + element[2][1];
00074 rect.x2 = element[0][0]*r.x2 + element[1][0]*r.y2 + element[2][0];
00075 rect.y2 = element[0][1]*r.x2 + element[1][1]*r.y2 + element[2][1];
00076 return rect;
00077 }
00078
00079 WPG2TransformMatrix& transformBy(const WPG2TransformMatrix& m)
00080 {
00081 double result[3][3];
00082
00083 for(int i = 0; i < 3; i++)
00084 for(int j = 0; j < 3; j++)
00085 {
00086 result[i][j] = 0;
00087 for(int k = 0; k < 3; k++)
00088 result[i][j] += m.element[i][k]*element[k][j];
00089 }
00090
00091 for(int x = 0; x < 3; x++)
00092 for(int y = 0; y < 3; y++)
00093 element[x][y] = result[x][y];
00094
00095 return *this;
00096 }
00097 };
00098
00099 class WPGCompoundPolygon
00100 {
00101 public:
00102 WPG2TransformMatrix matrix;
00103 bool isFilled;
00104 bool isFramed;
00105 bool isClosed;
00106
00107 WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
00108 };
00109
00110 class WPGGroupContext
00111 {
00112 public:
00113 unsigned subIndex;
00114 int parentType;
00115 libwpg::WPGPath compoundPath;
00116 WPG2TransformMatrix compoundMatrix;
00117 bool compoundWindingRule;
00118 bool compoundFilled;
00119 bool compoundFramed;
00120 bool compoundClosed;
00121
00122 WPGGroupContext(): subIndex(0), parentType(0),
00123 compoundPath(), compoundMatrix(), compoundWindingRule(false),
00124 compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
00125
00126 bool isCompoundPolygon() const { return parentType == 0x1a; }
00127 };
00128
00129 class WPGBitmapContext
00130 {
00131 public:
00132 double x1, y1, x2, y2;
00133 long hres, vres;
00134 WPGBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {}
00135 };
00136
00137 class WPGBinaryDataContext
00138 {
00139 public:
00140 double x1, y1, x2, y2;
00141 int numObjects, objectIndex;
00142 std::vector<libwpg::WPGString> mimeTypes;
00143 WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
00144 };
00145
00146 class WPG2Parser : public WPGXParser
00147 {
00148 public:
00149 WPG2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter);
00150 bool parse();
00151
00152 private:
00153 void handleStartWPG();
00154 void handleEndWPG();
00155 void handleLayer();
00156 void handleCompoundPolygon();
00157
00158 void handlePenStyleDefinition();
00159 void handlePatternDefinition();
00160 void handleColorPalette();
00161 void handleDPColorPalette();
00162 void handlePenForeColor();
00163 void handleDPPenForeColor();
00164 void handlePenBackColor();
00165 void handleDPPenBackColor();
00166 void handlePenStyle();
00167 void handlePenSize();
00168 void handleDPPenSize();
00169 void handleBrushGradient();
00170 void handleDPBrushGradient();
00171 void handleBrushForeColor();
00172 void handleDPBrushForeColor();
00173 void handleBrushBackColor();
00174 void handleDPBrushBackColor();
00175 void handleBrushPattern();
00176
00177 void handlePolyline();
00178 void handlePolyspline();
00179 void handlePolycurve();
00180 void handleRectangle();
00181 void handleArc();
00182
00183 void handleBitmap();
00184 void handleBitmapData();
00185
00186 void handleObjectCapsule();
00187 void handleObjectImage();
00188
00189 void resetPalette();
00190 void flushCompoundPolygon();
00191
00192
00193 int m_recordLength;
00194 long m_recordEnd;
00195 bool m_success;
00196 bool m_exit;
00197 bool m_graphicsStarted;
00198 unsigned int m_xres;
00199 unsigned int m_yres;
00200 long m_xofs;
00201 long m_yofs;
00202 long m_width;
00203 long m_height;
00204 bool m_doublePrecision;
00205 libwpg::WPGPen m_pen;
00206 libwpg::WPGBrush m_brush;
00207 std::map<unsigned int,libwpg::WPGDashArray> m_penStyles;
00208 bool m_layerOpened;
00209 unsigned int m_layerId;
00210 WPG2TransformMatrix m_matrix;
00211 double m_gradientAngle;
00212 libwpg::WPGPoint m_gradientRef;
00213 std::stack<WPGGroupContext> m_groupStack;
00214 WPG2TransformMatrix m_compoundMatrix;
00215 bool m_compoundWindingRule;
00216 bool m_compoundFilled;
00217 bool m_compoundFramed;
00218 bool m_compoundClosed;
00219 WPGBitmapContext m_bitmap;
00220 WPGBinaryDataContext m_binaryData;
00221 bool m_hFlipped, m_vFlipped;
00222
00223 class ObjectCharacterization;
00224 void parseCharacterization(ObjectCharacterization*);
00225 unsigned m_binaryId;
00226 };
00227
00228 #endif // __WPG2PARSER_H__