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