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 "WPGDashArray.h"
00033 #include "WPGBitmap.h"
00034 #include <libwpd/libwpd.h>
00035
00036 #include <map>
00037 #include <stack>
00038 #include <vector>
00039
00040 class WPG2TransformMatrix
00041 {
00042 public:
00043 double element[3][3];
00044
00045 WPG2TransformMatrix()
00046 {
00047
00048 element[0][0] = element[1][1] = 1;
00049 element[2][2] = 1;
00050 element[0][1] = element[0][2] = 0;
00051 element[1][0] = element[1][2] = 0;
00052 element[2][0] = element[2][1] = 0;
00053 }
00054
00055 void transform(long &x, long &y) const
00056 {
00057 long rx = (long)(element[0][0]*x + element[1][0]*y + element[2][0]);
00058 long ry = (long)(element[0][1]*x + element[1][1]*y + element[2][1]);
00059 x = rx;
00060 y = ry;
00061 }
00062
00063 ::WPXPropertyList transformPoint(const ::WPXPropertyList &p) const
00064 {
00065 ::WPXPropertyList propList;
00066 propList.insert("svg:x", (element[0][0]*p["svg:x"]->getDouble() + element[1][0]*p["svg:y"]->getDouble() + element[2][0]));
00067 propList.insert("svg:y", (element[0][1]*p["svg:x"]->getDouble() + element[1][1]*p["svg:y"]->getDouble() + element[2][1]));
00068 return propList;
00069 }
00070
00071 ::WPXPropertyList transformRect(const ::WPXPropertyList &r) const
00072 {
00073 ::WPXPropertyList propList;
00074 double oldx1 = r["svg:x"]->getDouble();
00075 double oldy1 = r["svg:y"]->getDouble();
00076 double oldx2 = r["svg:x"]->getDouble() + r["svg:width"]->getDouble();
00077 double oldy2 = r["svg:y"]->getDouble() + r["svg:height"]->getDouble();
00078
00079 double newx1 = element[0][0]*oldx1 + element[1][0]*oldy1 + element[2][0];
00080 double newy1 = element[0][1]*oldx1 + element[1][1]*oldy1 + element[2][1];
00081 double newx2 = element[0][0]*oldx2 + element[1][0]*oldy2 + element[2][0];
00082 double newy2 = element[0][1]*oldx2 + element[1][1]*oldy2 + element[2][1];
00083
00084 propList.insert("svg:x", (double)newx1);
00085 propList.insert("svg:y", (double)newy1);
00086 propList.insert("svg:width", (newx2-newx1));
00087 propList.insert("svg:height", (newy2-newy1));
00088 return propList;
00089 }
00090
00091 WPG2TransformMatrix &transformBy(const WPG2TransformMatrix &m)
00092 {
00093 double result[3][3];
00094
00095 for(int i = 0; i < 3; i++)
00096 for(int j = 0; j < 3; j++)
00097 {
00098 result[i][j] = 0;
00099 for(int k = 0; k < 3; k++)
00100 result[i][j] += m.element[i][k]*element[k][j];
00101 }
00102
00103 for(int x = 0; x < 3; x++)
00104 for(int y = 0; y < 3; y++)
00105 element[x][y] = result[x][y];
00106
00107 return *this;
00108 }
00109 };
00110
00111 class WPGCompoundPolygon
00112 {
00113 public:
00114 WPG2TransformMatrix matrix;
00115 bool isFilled;
00116 bool isFramed;
00117 bool isClosed;
00118
00119 WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
00120 };
00121
00122 class WPGGroupContext
00123 {
00124 public:
00125 unsigned subIndex;
00126 int parentType;
00127 ::WPXPropertyListVector compoundPath;
00128 WPG2TransformMatrix compoundMatrix;
00129 bool compoundWindingRule;
00130 bool compoundFilled;
00131 bool compoundFramed;
00132 bool compoundClosed;
00133
00134 WPGGroupContext(): subIndex(0), parentType(0),
00135 compoundPath(), compoundMatrix(), compoundWindingRule(false),
00136 compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
00137
00138 bool isCompoundPolygon() const
00139 {
00140 return parentType == 0x1a;
00141 }
00142 };
00143
00144 class WPGBitmapContext
00145 {
00146 public:
00147 double x1, y1, x2, y2;
00148 long hres, vres;
00149 WPGBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {}
00150 };
00151
00152 class WPGBinaryDataContext
00153 {
00154 public:
00155 double x1, y1, x2, y2;
00156 int numObjects, objectIndex;
00157 std::vector<WPXString> mimeTypes;
00158 WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
00159 };
00160
00161 class WPGTextDataContext
00162 {
00163 public:
00164 double x1, y1, x2, y2;
00165 unsigned short flags;
00166 unsigned char vertAlign;
00167 unsigned char horAlign;
00168 double baseLineAngle;
00169 WPGTextDataContext(): x1(0), y1(0), x2(0), y2(0), flags(), vertAlign(), horAlign(), baseLineAngle(0.0) {}
00170 };
00171
00172 class WPG2Parser : public WPGXParser
00173 {
00174 public:
00175 WPG2Parser(WPXInputStream *input, libwpg::WPGPaintInterface *painter, bool isEmbedded = false);
00176 bool parse();
00177
00178 private:
00179 void handleStartWPG();
00180 void handleEndWPG();
00181 void handleFormSettings();
00182 void handleLayer();
00183 void handleCompoundPolygon();
00184
00185 void handlePenStyleDefinition();
00186
00187 void handleColorPalette();
00188 void handleDPColorPalette();
00189 void handlePenForeColor();
00190 void handleDPPenForeColor();
00191 void handlePenBackColor();
00192 void handleDPPenBackColor();
00193 void handlePenStyle();
00194 void handlePenSize();
00195 void handleDPPenSize();
00196 void handleLineCap();
00197 void handleLineJoin();
00198 void handleBrushGradient();
00199 void handleDPBrushGradient();
00200 void handleBrushForeColor();
00201 void handleDPBrushForeColor();
00202 void handleBrushBackColor();
00203 void handleDPBrushBackColor();
00204 void handleBrushPattern();
00205
00206 void handlePolyline();
00207 void handlePolyspline();
00208 void handlePolycurve();
00209 void handleRectangle();
00210 void handleArc();
00211
00212 void handleBitmap();
00213 void handleBitmapData();
00214
00215 void handleTextData();
00216 void handleTextLine();
00217 void handleTextBlock();
00218 void handleTextPath();
00219
00220 void handleObjectCapsule();
00221 void handleObjectImage();
00222
00223 void resetPalette();
00224 void flushCompoundPolygon();
00225 void setPenStyle();
00226
00227
00228 int m_recordLength;
00229 long m_recordEnd;
00230 bool m_success;
00231 bool m_exit;
00232 bool m_graphicsStarted;
00233 unsigned int m_xres;
00234 unsigned int m_yres;
00235 long m_xofs;
00236 long m_yofs;
00237 long m_width;
00238 long m_height;
00239 bool m_doublePrecision;
00240 ::WPXPropertyList m_style;
00241 libwpg::WPGColor m_penForeColor;
00242 libwpg::WPGColor m_penBackColor;
00243 libwpg::WPGColor m_brushForeColor;
00244 libwpg::WPGColor m_brushBackColor;
00245 libwpg::WPGDashArray m_dashArray;
00246 ::WPXPropertyListVector m_gradient;
00247 std::map<unsigned int,libwpg::WPGDashArray> m_dashArrayStyles;
00248 bool m_layerOpened;
00249 #ifdef DEBUG
00250 unsigned int m_layerId;
00251 #endif
00252 WPG2TransformMatrix m_matrix;
00253 double m_gradientAngle;
00254 ::WPXPropertyList m_gradientRef;
00255 std::stack<WPGGroupContext> m_groupStack;
00256 WPG2TransformMatrix m_compoundMatrix;
00257 bool m_compoundWindingRule;
00258 bool m_compoundFilled;
00259 bool m_compoundFramed;
00260 bool m_compoundClosed;
00261 WPGBitmapContext m_bitmap;
00262 WPGBinaryDataContext m_binaryData;
00263 bool m_hFlipped, m_vFlipped;
00264 WPGTextDataContext m_textData;
00265 bool m_drawTextData;
00266
00267 class ObjectCharacterization;
00268 void parseCharacterization(ObjectCharacterization *);
00269 #if DUMP_BINARY_DATA
00270 unsigned m_binaryId;
00271 #endif
00272 };
00273
00274 #endif // __WPG2PARSER_H__
00275