Code

Cleaned up virtual destructor problem and compile warnings.
[inkscape.git] / src / extension / internal / libwpg / WPG2Parser.h
1 /* libwpg
2  * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
3  * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
4  * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the 
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
19  * Boston, MA  02111-1301 USA
20  *
21  * For further information visit http://libwpg.sourceforge.net
22  */
24 /* "This product is not manufactured, approved, or supported by
25  * Corel Corporation or Corel Corporation Limited."
26  */
28 #ifndef __WPG2PARSER_H__
29 #define __WPG2PARSER_H__
31 #include "WPGXParser.h"
32 #include "WPGBrush.h"
33 #include "WPGPen.h"
35 #include <map>
36 #include <stack>
38 class WPG2TransformMatrix
39 {
40 public:
41         double element[3][3];
43         WPG2TransformMatrix()
44         {
45                 // identity transformation
46                 element[0][0] = element[1][1] = 1; element[2][2] = 1;
47                 element[0][1] = element[0][2] = 0;
48                 element[1][0] = element[1][2] = 0;
49                 element[2][0] = element[2][1] = 0;
50         }
52         void transform(long& x, long& y) const
53         {
54                 long rx = (long)(element[0][0]*x + element[1][0]*y + element[2][0]); 
55                 long ry = (long)(element[0][1]*x + element[1][1]*y + element[2][1]); 
56                 x = rx;
57                 y = ry;
58         }
60         WPGPoint transform(const WPGPoint& p) const
61         {
62                 WPGPoint point;
63                 point.x = element[0][0]*p.x + element[1][0]*p.y + element[2][0]; 
64                 point.y = element[0][1]*p.x + element[1][1]*p.y + element[2][1]; 
65                 return point;
66         }
68         WPGRect transform(const WPGRect& r) const
69         {
70                 WPGRect rect;
71                 rect.x1 = element[0][0]*r.x1 + element[1][0]*r.y1 + element[2][0]; 
72                 rect.y1 = element[0][1]*r.x1 + element[1][1]*r.y1 + element[2][1]; 
73                 rect.x2 = element[0][0]*r.x2 + element[1][0]*r.y2 + element[2][0]; 
74                 rect.y2 = element[0][1]*r.x2 + element[1][1]*r.y2 + element[2][1]; 
75                 return rect;
76         }
78         WPG2TransformMatrix& transformBy(const WPG2TransformMatrix& m)
79         {
80                 double result[3][3];
82                 for(int i = 0; i < 3; i++)
83                         for(int j = 0; j < 3; j++)
84                         {
85                                 result[i][j] = 0;
86                                 for(int k = 0; k < 3; k++)
87                                         result[i][j] += m.element[i][k]*element[k][j];
88                         }
90                 for(int x = 0; x < 3; x++)
91                         for(int y = 0; y < 3; y++)
92                                 element[x][y] = result[x][y];
93         
94                 return *this;
95         }
96 };
98 class WPGCompoundPolygon
99 {
100 public:
101         WPG2TransformMatrix matrix;
102         bool isFilled;
103         bool isFramed;
104         bool isClosed;
106         WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
107 };
109 class WPGGroupContext
111 public:
112         unsigned subIndex;
113         int parentType;
114         WPGPath compoundPath;
115         WPG2TransformMatrix compoundMatrix;
116         bool compoundWindingRule;
117         bool compoundFilled;
118         bool compoundFramed;
119         bool compoundClosed;
121         WPGGroupContext(): subIndex(0), parentType(0), 
122         compoundPath(), compoundMatrix(), compoundWindingRule(false),
123         compoundFilled(false), compoundFramed(true), compoundClosed(false)      {}
125         bool isCompoundPolygon() const { return parentType == 0x1a; }
126 };
128 class WPG2Parser : public WPGXParser
130 public:
131         WPG2Parser(WPGInputStream *input, WPGPaintInterface* painter);
132         bool parse();
133         
134 private:
135         void handleStartWPG();
136         void handleEndWPG();
137         void handleLayer();
138         void handleCompoundPolygon();
139         
140         void handlePenStyleDefinition();
141         void handlePatternDefinition();
142         void handleColorPalette();
143         void handleDPColorPalette();
144         void handlePenForeColor();
145         void handleDPPenForeColor();
146         void handlePenBackColor();
147         void handleDPPenBackColor();
148         void handlePenStyle();
149         void handlePenSize();
150         void handleDPPenSize();
151         void handleBrushGradient();
152         void handleDPBrushGradient();
153         void handleBrushForeColor();
154         void handleDPBrushForeColor();
155         void handleBrushBackColor();
156         void handleDPBrushBackColor();
157         void handleBrushPattern();
159         void handlePolyline();
160         void handlePolycurve();
161         void handleRectangle();
162         void handleArc();
163         
164         void resetPalette();
165         void flushCompoundPolygon();
167         // parsing context
168         bool m_success;
169         bool m_exit;
170         unsigned int m_xres;
171         unsigned int m_yres;
172         long m_xofs;
173         long m_yofs;
174         long m_width;
175         long m_height;
176         bool m_doublePrecision;  
177         WPGPen m_pen;
178         WPGBrush m_brush;
179         std::map<unsigned int,WPGDashArray> m_penStyles;
180         bool m_layerOpened;
181         unsigned int m_layerId;
182         WPG2TransformMatrix m_matrix;
183         double m_gradientAngle;
184         WPGPoint m_gradientRef;
185         std::stack<WPGGroupContext> m_groupStack;
186         WPG2TransformMatrix m_compoundMatrix;
187         bool m_compoundWindingRule;
188         bool m_compoundFilled;
189         bool m_compoundFramed;
190         bool m_compoundClosed;
192         class ObjectCharacterization;
193         void parseCharacterization(ObjectCharacterization*);
194 };
196 #endif // __WPG2PARSER_H__