Scribus
Open source desktop publishing at your fingertips
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  */
23 
24 /* "This product is not manufactured, approved, or supported by
25  * Corel Corporation or Corel Corporation Limited."
26  */
27 
28 #ifndef __WPG2PARSER_H__
29 #define __WPG2PARSER_H__
30 
31 #include "WPGXParser.h"
32 #include "WPGBrush.h"
33 #include "WPGPen.h"
34 
35 #include <map>
36 #include <stack>
37 #include <vector>
38 
40 {
41 public:
42  double element[3][3];
43 
45  {
46  // identity transformation
47  element[0][0] = element[1][1] = 1; element[2][2] = 1;
48  element[0][1] = element[0][2] = 0;
49  element[1][0] = element[1][2] = 0;
50  element[2][0] = element[2][1] = 0;
51  }
52 
53  void transform(long& x, long& y) const
54  {
55  long rx = (long)(element[0][0]*x + element[1][0]*y + element[2][0]);
56  long ry = (long)(element[0][1]*x + element[1][1]*y + element[2][1]);
57  x = rx;
58  y = ry;
59  }
60 
61  libwpg::WPGPoint transform(const libwpg::WPGPoint& p) const
62  {
63  libwpg::WPGPoint point;
64  point.x = element[0][0]*p.x + element[1][0]*p.y + element[2][0];
65  point.y = element[0][1]*p.x + element[1][1]*p.y + element[2][1];
66  return point;
67  }
68 
69  libwpg::WPGRect transform(const libwpg::WPGRect& r) const
70  {
71  libwpg::WPGRect rect;
72  rect.x1 = element[0][0]*r.x1 + element[1][0]*r.y1 + element[2][0];
73  rect.y1 = element[0][1]*r.x1 + element[1][1]*r.y1 + element[2][1];
74  rect.x2 = element[0][0]*r.x2 + element[1][0]*r.y2 + element[2][0];
75  rect.y2 = element[0][1]*r.x2 + element[1][1]*r.y2 + element[2][1];
76  return rect;
77  }
78 
79  WPG2TransformMatrix& transformBy(const WPG2TransformMatrix& m)
80  {
81  double result[3][3];
82 
83  for(int i = 0; i < 3; i++)
84  for(int j = 0; j < 3; j++)
85  {
86  result[i][j] = 0;
87  for(int k = 0; k < 3; k++)
88  result[i][j] += m.element[i][k]*element[k][j];
89  }
90 
91  for(int x = 0; x < 3; x++)
92  for(int y = 0; y < 3; y++)
93  element[x][y] = result[x][y];
94 
95  return *this;
96  }
97 };
98 
100 {
101 public:
102  WPG2TransformMatrix matrix;
103  bool isFilled;
104  bool isFramed;
105  bool isClosed;
106 
107  WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
108 };
109 
111 {
112 public:
113  unsigned subIndex;
114  int parentType;
115  libwpg::WPGPath compoundPath;
116  WPG2TransformMatrix compoundMatrix;
117  bool compoundWindingRule;
118  bool compoundFilled;
119  bool compoundFramed;
120  bool compoundClosed;
121 
122  WPGGroupContext(): subIndex(0), parentType(0),
123  compoundPath(), compoundMatrix(), compoundWindingRule(false),
124  compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
125 
126  bool isCompoundPolygon() const { return parentType == 0x1a; }
127 };
128 
130 {
131 public:
132  double x1, y1, x2, y2;
133  long hres, vres;
134  WPGBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {}
135 };
136 
138 {
139 public:
140  double x1, y1, x2, y2;
141  int numObjects, objectIndex;
142  std::vector<libwpg::WPGString> mimeTypes;
143  WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
144 };
145 
146 class WPG2Parser : public WPGXParser
147 {
148 public:
150  bool parse();
151 
152 private:
153  void handleStartWPG();
154  void handleEndWPG();
155  void handleFormSettings();
156  void handleLayer();
157  void handleCompoundPolygon();
158 
159  void handlePenStyleDefinition();
160  void handlePatternDefinition();
161  void handleColorPalette();
162  void handleDPColorPalette();
163  void handlePenForeColor();
164  void handleDPPenForeColor();
165  void handlePenBackColor();
166  void handleDPPenBackColor();
167  void handlePenStyle();
168  void handlePenSize();
169  void handleDPPenSize();
170  void handleLineCap();
171  void handleLineJoin();
172  void handleBrushGradient();
173  void handleDPBrushGradient();
174  void handleBrushForeColor();
175  void handleDPBrushForeColor();
176  void handleBrushBackColor();
177  void handleDPBrushBackColor();
178  void handleBrushPattern();
179 
180  void handlePolyline();
181  void handlePolyspline();
182  void handlePolycurve();
183  void handleRectangle();
184  void handleArc();
185 
186  void handleBitmap();
187  void handleBitmapData();
188 
189  void handleObjectCapsule();
190  void handleObjectImage();
191 
192  void resetPalette();
193  void flushCompoundPolygon();
194 
195  // parsing context
196  int m_recordLength;
197  long m_recordEnd;
198  bool m_success;
199  bool m_exit;
200  bool m_graphicsStarted;
201  unsigned int m_xres;
202  unsigned int m_yres;
203  long m_xofs;
204  long m_yofs;
205  long m_width;
206  long m_height;
207  bool m_doublePrecision;
208  libwpg::WPGPen m_pen;
209  libwpg::WPGBrush m_brush;
210  std::map<unsigned int,libwpg::WPGDashArray> m_penStyles;
211  bool m_layerOpened;
212  unsigned int m_layerId;
213  WPG2TransformMatrix m_matrix;
214  double m_gradientAngle;
215  libwpg::WPGPoint m_gradientRef;
216  std::stack<WPGGroupContext> m_groupStack;
217  WPG2TransformMatrix m_compoundMatrix;
218  bool m_compoundWindingRule;
219  bool m_compoundFilled;
220  bool m_compoundFramed;
221  bool m_compoundClosed;
222  WPGBitmapContext m_bitmap;
223  WPGBinaryDataContext m_binaryData;
224  bool m_hFlipped, m_vFlipped;
225 
227  void parseCharacterization(ObjectCharacterization*);
228 };
229 
230 #endif // __WPG2PARSER_H__
Definition: WPGXParser.h:37
Definition: WPG2Parser.h:39
Definition: WPGPoint.h:34
Definition: WPXStream.h:36
Definition: WPGPath.h:55
Definition: WPGPaintInterface.h:41
Definition: WPG2Parser.h:137
Definition: WPG2Parser.h:99
Definition: WPG2Parser.h:146
Definition: WPGBrush.h:35
Definition: WPGPen.h:51
Definition: WPGRect.h:34
Definition: WPG2Parser.h:110
Definition: WPG2Parser.h:129
Definition: WPG2Parser.cpp:148