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

Generated on Mon Aug 6 10:06:04 2007 for libwpg by doxygen 1.5.3