WPG2Parser.h
Go to the documentation of this file.
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 "WPGDashArray.h"
33 #include "WPGBitmap.h"
34 #include <libwpd/libwpd.h>
35 
36 #include <map>
37 #include <stack>
38 #include <vector>
39 
41 {
42 public:
43  double element[3][3];
44 
46  {
47  // identity transformation
48  element[0][0] = element[1][1] = 1; element[2][2] = 1;
49  element[0][1] = element[0][2] = 0;
50  element[1][0] = element[1][2] = 0;
51  element[2][0] = element[2][1] = 0;
52  }
53 
54  void transform(long& x, long& y) const
55  {
56  long rx = (long)(element[0][0]*x + element[1][0]*y + element[2][0]);
57  long ry = (long)(element[0][1]*x + element[1][1]*y + element[2][1]);
58  x = rx;
59  y = ry;
60  }
61 
62  ::WPXPropertyList transformPoint(const ::WPXPropertyList& p) const
63  {
64  ::WPXPropertyList propList;
65  propList.insert("svg:x", (element[0][0]*p["svg:x"]->getDouble() + element[1][0]*p["svg:y"]->getDouble() + element[2][0]));
66  propList.insert("svg:y", (element[0][1]*p["svg:x"]->getDouble() + element[1][1]*p["svg:y"]->getDouble() + element[2][1]));
67  return propList;
68  }
69 
70  ::WPXPropertyList transformRect(const ::WPXPropertyList& r) const
71  {
72  ::WPXPropertyList propList;
73  double oldx1 = r["svg:x"]->getDouble();
74  double oldy1 = r["svg:y"]->getDouble();
75  double oldx2 = r["svg:x"]->getDouble() + r["svg:width"]->getDouble();
76  double oldy2 = r["svg:y"]->getDouble() + r["svg:height"]->getDouble();
77 
78  double newx1 = element[0][0]*oldx1 + element[1][0]*oldy1 + element[2][0];
79  double newy1 = element[0][1]*oldx1 + element[1][1]*oldy1 + element[2][1];
80  double newx2 = element[0][0]*oldx2 + element[1][0]*oldy2 + element[2][0];
81  double newy2 = element[0][1]*oldx2 + element[1][1]*oldy2 + element[2][1];
82 
83  propList.insert("svg:x", (double)newx1);
84  propList.insert("svg:y", (double)newy1);
85  propList.insert("svg:width", (newx2-newx1));
86  propList.insert("svg:height", (newy2-newy1));
87  return propList;
88  }
89 
91  {
92  double result[3][3];
93 
94  for(int i = 0; i < 3; i++)
95  for(int j = 0; j < 3; j++)
96  {
97  result[i][j] = 0;
98  for(int k = 0; k < 3; k++)
99  result[i][j] += m.element[i][k]*element[k][j];
100  }
101 
102  for(int x = 0; x < 3; x++)
103  for(int y = 0; y < 3; y++)
104  element[x][y] = result[x][y];
105 
106  return *this;
107  }
108 };
109 
111 {
112 public:
114  bool isFilled;
115  bool isFramed;
116  bool isClosed;
117 
118  WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
119 };
120 
122 {
123 public:
124  unsigned subIndex;
126  ::WPXPropertyListVector compoundPath;
132 
135  compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
136 
137  bool isCompoundPolygon() const { return parentType == 0x1a; }
138 };
139 
141 {
142 public:
143  double x1, y1, x2, y2;
144  long hres, vres;
145  WPGBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {}
146 };
147 
149 {
150 public:
151  double x1, y1, x2, y2;
153  std::vector<WPXString> mimeTypes;
154  WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
155 };
156 
158 {
159 public:
160  double x1, y1, x2, y2;
161  unsigned short flags;
162  unsigned char vertAlign;
163  unsigned char horAlign;
165  WPGTextDataContext(): x1(0), y1(0), x2(0), y2(0), flags(), vertAlign(), horAlign(), baseLineAngle(0.0) {}
166 };
167 
168 class WPG2Parser : public WPGXParser
169 {
170 public:
171  WPG2Parser(WPXInputStream *input, libwpg::WPGPaintInterface* painter, bool isEmbedded = false);
172  bool parse();
173 
174 private:
175  void handleStartWPG();
176  void handleEndWPG();
177  void handleFormSettings();
178  void handleLayer();
179  void handleCompoundPolygon();
180 
182 // void handlePatternDefinition();
183  void handleColorPalette();
184  void handleDPColorPalette();
185  void handlePenForeColor();
186  void handleDPPenForeColor();
187  void handlePenBackColor();
188  void handleDPPenBackColor();
189  void handlePenStyle();
190  void handlePenSize();
191  void handleDPPenSize();
192  void handleLineCap();
193  void handleLineJoin();
194  void handleBrushGradient();
195  void handleDPBrushGradient();
196  void handleBrushForeColor();
197  void handleDPBrushForeColor();
198  void handleBrushBackColor();
199  void handleDPBrushBackColor();
200  void handleBrushPattern();
201 
202  void handlePolyline();
203  void handlePolyspline();
204  void handlePolycurve();
205  void handleRectangle();
206  void handleArc();
207 
208  void handleBitmap();
209  void handleBitmapData();
210 
211  void handleTextData();
212  void handleTextLine();
213  void handleTextBlock();
214  void handleTextPath();
215 
216  void handleObjectCapsule();
217  void handleObjectImage();
218 
219  void resetPalette();
220  void flushCompoundPolygon();
221  void setPenStyle();
222 
223  // parsing context
226  bool m_success;
227  bool m_exit;
229  unsigned int m_xres;
230  unsigned int m_yres;
231  long m_xofs;
232  long m_yofs;
233  long m_width;
234  long m_height;
236  ::WPXPropertyList m_style;
242  ::WPXPropertyListVector m_gradient;
243  std::map<unsigned int,libwpg::WPGDashArray> m_dashArrayStyles;
245  unsigned int m_layerId;
248  ::WPXPropertyList m_gradientRef;
249  std::stack<WPGGroupContext> m_groupStack;
260 
263  unsigned m_binaryId;
264 
266 };
267 
268 #endif // __WPG2PARSER_H__

Generated for libwpg by doxygen 1.8.1.1