WPG2Parser.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwpg
3  * Version: MPL 2.0 / LGPLv2.1+
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * Major Contributor(s):
10  * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
11  * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
12  * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
13  *
14  * For minor contributions see the git repository.
15  *
16  * Alternatively, the contents of this file may be used under the terms
17  * of the GNU Lesser General Public License Version 2.1 or later
18  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19  * applicable instead of those above.
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;
49  element[2][2] = 1;
50  element[0][1] = element[0][2] = 0;
51  element[1][0] = element[1][2] = 0;
52  element[2][0] = element[2][1] = 0;
53  }
54 
55  void transform(long &x, long &y) const
56  {
57  long rx = (long)(element[0][0]*x + element[1][0]*y + element[2][0]);
58  long ry = (long)(element[0][1]*x + element[1][1]*y + element[2][1]);
59  x = rx;
60  y = ry;
61  }
62 
63  ::WPXPropertyList transformPoint(const ::WPXPropertyList &p) const
64  {
65  ::WPXPropertyList propList;
66  propList.insert("svg:x", (element[0][0]*p["svg:x"]->getDouble() + element[1][0]*p["svg:y"]->getDouble() + element[2][0]));
67  propList.insert("svg:y", (element[0][1]*p["svg:x"]->getDouble() + element[1][1]*p["svg:y"]->getDouble() + element[2][1]));
68  return propList;
69  }
70 
71  ::WPXPropertyList transformRect(const ::WPXPropertyList &r) const
72  {
73  ::WPXPropertyList propList;
74  double oldx1 = r["svg:x"]->getDouble();
75  double oldy1 = r["svg:y"]->getDouble();
76  double oldx2 = r["svg:x"]->getDouble() + r["svg:width"]->getDouble();
77  double oldy2 = r["svg:y"]->getDouble() + r["svg:height"]->getDouble();
78 
79  double newx1 = element[0][0]*oldx1 + element[1][0]*oldy1 + element[2][0];
80  double newy1 = element[0][1]*oldx1 + element[1][1]*oldy1 + element[2][1];
81  double newx2 = element[0][0]*oldx2 + element[1][0]*oldy2 + element[2][0];
82  double newy2 = element[0][1]*oldx2 + element[1][1]*oldy2 + element[2][1];
83 
84  propList.insert("svg:x", (double)newx1);
85  propList.insert("svg:y", (double)newy1);
86  propList.insert("svg:width", (newx2-newx1));
87  propList.insert("svg:height", (newy2-newy1));
88  return propList;
89  }
90 
92  {
93  double result[3][3];
94 
95  for(int i = 0; i < 3; i++)
96  for(int j = 0; j < 3; j++)
97  {
98  result[i][j] = 0;
99  for(int k = 0; k < 3; k++)
100  result[i][j] += m.element[i][k]*element[k][j];
101  }
102 
103  for(int x = 0; x < 3; x++)
104  for(int y = 0; y < 3; y++)
105  element[x][y] = result[x][y];
106 
107  return *this;
108  }
109 };
110 
112 {
113 public:
115  bool isFilled;
116  bool isFramed;
117  bool isClosed;
118 
119  WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
120 };
121 
123 {
124 public:
125  unsigned subIndex;
127  ::WPXPropertyListVector compoundPath;
133 
136  compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
137 
138  bool isCompoundPolygon() const
139  {
140  return parentType == 0x1a;
141  }
142 };
143 
145 {
146 public:
147  double x1, y1, x2, y2;
148  long hres, vres;
149  WPGBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {}
150 };
151 
153 {
154 public:
155  double x1, y1, x2, y2;
157  std::vector<WPXString> mimeTypes;
158  WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
159 };
160 
162 {
163 public:
164  double x1, y1, x2, y2;
165  unsigned short flags;
166  unsigned char vertAlign;
167  unsigned char horAlign;
169  WPGTextDataContext(): x1(0), y1(0), x2(0), y2(0), flags(), vertAlign(), horAlign(), baseLineAngle(0.0) {}
170 };
171 
172 class WPG2Parser : public WPGXParser
173 {
174 public:
175  WPG2Parser(WPXInputStream *input, libwpg::WPGPaintInterface *painter, bool isEmbedded = false);
176  bool parse();
177 
178 private:
179  void handleStartWPG();
180  void handleEndWPG();
181  void handleFormSettings();
182  void handleLayer();
183  void handleCompoundPolygon();
184 
186 // void handlePatternDefinition();
187  void handleColorPalette();
188  void handleDPColorPalette();
189  void handlePenForeColor();
190  void handleDPPenForeColor();
191  void handlePenBackColor();
192  void handleDPPenBackColor();
193  void handlePenStyle();
194  void handlePenSize();
195  void handleDPPenSize();
196  void handleLineCap();
197  void handleLineJoin();
198  void handleBrushGradient();
199  void handleDPBrushGradient();
200  void handleBrushForeColor();
201  void handleDPBrushForeColor();
202  void handleBrushBackColor();
203  void handleDPBrushBackColor();
204  void handleBrushPattern();
205 
206  void handlePolyline();
207  void handlePolyspline();
208  void handlePolycurve();
209  void handleRectangle();
210  void handleArc();
211 
212  void handleBitmap();
213  void handleBitmapData();
214 
215  void handleTextData();
216  void handleTextLine();
217  void handleTextBlock();
218  void handleTextPath();
219 
220  void handleObjectCapsule();
221  void handleObjectImage();
222 
223  void resetPalette();
224  void flushCompoundPolygon();
225  void setPenStyle();
226 
227  // parsing context
230  bool m_success;
231  bool m_exit;
233  unsigned int m_xres;
234  unsigned int m_yres;
235  long m_xofs;
236  long m_yofs;
237  long m_width;
238  long m_height;
240  ::WPXPropertyList m_style;
246  ::WPXPropertyListVector m_gradient;
247  std::map<unsigned int,libwpg::WPGDashArray> m_dashArrayStyles;
249 #ifdef DEBUG
250  unsigned int m_layerId;
251 #endif
254  ::WPXPropertyList m_gradientRef;
255  std::stack<WPGGroupContext> m_groupStack;
266 
269 #if DUMP_BINARY_DATA
270  unsigned m_binaryId;
271 #endif
272 };
273 
274 #endif // __WPG2PARSER_H__
275 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */

Generated for libwpg by doxygen 1.8.3.1