WPG2Parser.h

Go to the documentation of this file.
00001 /* libwpg
00002  * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
00003  * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
00004  * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Library General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Library General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA  02111-1301 USA
00020  *
00021  * For further information visit http://libwpg.sourceforge.net
00022  */
00023 
00024 /* "This product is not manufactured, approved, or supported by
00025  * Corel Corporation or Corel Corporation Limited."
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                 // identity transformation
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 handlePolycurve();
00179         void handleRectangle();
00180         void handleArc();
00181 
00182         void handleBitmap();
00183         void handleBitmapData();
00184         
00185         void handleObjectCapsule();
00186         void handleObjectImage();
00187 
00188         void resetPalette();
00189         void flushCompoundPolygon();
00190 
00191         // parsing context
00192         int m_recordLength;
00193         long m_recordEnd;
00194         bool m_success;
00195         bool m_exit;
00196         bool m_graphicsStarted;
00197         unsigned int m_xres;
00198         unsigned int m_yres;
00199         long m_xofs;
00200         long m_yofs;
00201         long m_width;
00202         long m_height;
00203         bool m_doublePrecision;
00204         libwpg::WPGPen m_pen;
00205         libwpg::WPGBrush m_brush;
00206         std::map<unsigned int,libwpg::WPGDashArray> m_penStyles;
00207         bool m_layerOpened;
00208         unsigned int m_layerId;
00209         WPG2TransformMatrix m_matrix;
00210         double m_gradientAngle;
00211         libwpg::WPGPoint m_gradientRef;
00212         std::stack<WPGGroupContext> m_groupStack;
00213         WPG2TransformMatrix m_compoundMatrix;
00214         bool m_compoundWindingRule;
00215         bool m_compoundFilled;
00216         bool m_compoundFramed;
00217         bool m_compoundClosed;
00218         WPGBitmapContext m_bitmap;
00219         WPGBinaryDataContext m_binaryData;
00220 
00221         class ObjectCharacterization;
00222         void parseCharacterization(ObjectCharacterization*);
00223 };
00224 
00225 #endif // __WPG2PARSER_H__

Generated on Sun Sep 16 12:42:41 2007 for libwpg by doxygen 1.5.3