- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 <librevenge/librevenge.h>
35
36 #include <map>
37 #include <stack>
38 #include <vector>
39
40 class WPG2TransformMatrix
41 {
42 public:
43 double element[3][3];
44
45 WPG2TransformMatrix()
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 ::librevenge::RVNGPropertyList transformPoint(const ::librevenge::RVNGPropertyList &p) const
64 {
65 ::librevenge::RVNGPropertyList 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 ::librevenge::RVNGPropertyList transformRect(const ::librevenge::RVNGPropertyList &r) const
72 {
73 ::librevenge::RVNGPropertyList 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
91 WPG2TransformMatrix &transformBy(const WPG2TransformMatrix &m)
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
111 class WPGCompoundPolygon
112 {
113 public:
114 WPG2TransformMatrix matrix;
115 bool isFilled;
116 bool isFramed;
117 bool isClosed;
118
119 WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
120 };
121
122 class WPGGroupContext
123 {
124 public:
125 unsigned subIndex;
126 int parentType;
127 ::librevenge::RVNGPropertyListVector compoundPath;
128 WPG2TransformMatrix compoundMatrix;
129 bool compoundWindingRule;
130 bool compoundFilled;
131 bool compoundFramed;
132 bool compoundClosed;
133
134 WPGGroupContext(): subIndex(0), parentType(0),
135 compoundPath(), compoundMatrix(), compoundWindingRule(false),
136 compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
137
138 bool isCompoundPolygon() const
139 {
140 return parentType == 0x1a;
141 }
142 };
143
144 class WPGBitmapContext
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
152 class WPGBinaryDataContext
153 {
154 public:
155 double x1, y1, x2, y2;
156 int numObjects, objectIndex;
157 std::vector<librevenge::RVNGString> mimeTypes;
158 WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
159 };
160
161 class WPGTextDataContext
162 {
163 public:
164 double x1, y1, x2, y2;
165 unsigned short flags;
166 unsigned char vertAlign;
167 unsigned char horAlign;
168 double baseLineAngle;
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(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *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
185 void handlePenStyleDefinition();
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
228 int m_recordLength;
229 long m_recordEnd;
230 bool m_success;
231 bool m_exit;
232 bool m_graphicsStarted;
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;
239 bool m_doublePrecision;
240 ::librevenge::RVNGPropertyList m_style;
241 libwpg::WPGColor m_penForeColor;
242 libwpg::WPGColor m_penBackColor;
243 libwpg::WPGColor m_brushForeColor;
244 libwpg::WPGColor m_brushBackColor;
245 libwpg::WPGDashArray m_dashArray;
246 ::librevenge::RVNGPropertyListVector m_gradient;
247 std::map<unsigned int,libwpg::WPGDashArray> m_dashArrayStyles;
248 bool m_layerOpened;
249 #ifdef DEBUG
250 unsigned int m_layerId;
251 #endif
252 WPG2TransformMatrix m_matrix;
253 double m_gradientAngle;
254 ::librevenge::RVNGPropertyList m_gradientRef;
255 std::stack<WPGGroupContext> m_groupStack;
256 WPG2TransformMatrix m_compoundMatrix;
257 bool m_compoundWindingRule;
258 bool m_compoundFilled;
259 bool m_compoundFramed;
260 bool m_compoundClosed;
261 WPGBitmapContext m_bitmap;
262 WPGBinaryDataContext m_binaryData;
263 bool m_hFlipped, m_vFlipped;
264 WPGTextDataContext m_textData;
265 bool m_drawTextData;
266
267 class ObjectCharacterization;
268 void parseCharacterization(ObjectCharacterization *);
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: */
WPG2Parser::m_brushForeColor
libwpg::WPGColor m_brushForeColor
Definition: WPG2Parser.h:243
WPG2Parser::m_dashArray
libwpg::WPGDashArray m_dashArray
Definition: WPG2Parser.h:245
WPG2Parser::ObjectCharacterization
Definition: WPG2Parser.cpp:170
WPG2Parser::m_brushBackColor
libwpg::WPGColor m_brushBackColor
Definition: WPG2Parser.h:244
WPG2Parser::parseCharacterization
void parseCharacterization(ObjectCharacterization *)
Definition: WPG2Parser.cpp:1311
WPGBitmapContext::vres
long vres
Definition: WPG2Parser.h:148
WPG2Parser::WPG2Parser
WPG2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter, bool isEmbedded=false)
Definition: WPG2Parser.cpp:230
WPG2Parser::handleFormSettings
void handleFormSettings()
Definition: WPG2Parser.cpp:642
WPG2Parser::handleBrushGradient
void handleBrushGradient()
Definition: WPG2Parser.cpp:987
WPGBitmap.h
WPG2Parser::m_penForeColor
libwpg::WPGColor m_penForeColor
Definition: WPG2Parser.h:241
WPGBinaryDataContext::objectIndex
int objectIndex
Definition: WPG2Parser.h:156
WPG2Parser::handlePolyline
void handlePolyline()
Definition: WPG2Parser.cpp:1397
WPG2Parser::handleBitmap
void handleBitmap()
Definition: WPG2Parser.cpp:1723
WPGBinaryDataContext
Definition: WPG2Parser.h:152
WPG2Parser::resetPalette
void resetPalette()
Definition: WPG2Parser.cpp:2375
WPG2Parser::handlePenStyle
void handlePenStyle()
Definition: WPG2Parser.cpp:897
WPGTextDataContext
Definition: WPG2Parser.h:161
WPGBinaryDataContext::y1
double y1
Definition: WPG2Parser.h:155
WPGBitmapContext::x2
double x2
Definition: WPG2Parser.h:147
WPG2Parser::m_recordLength
int m_recordLength
Definition: WPG2Parser.h:228
WPG2TransformMatrix::transformRect
::librevenge::RVNGPropertyList transformRect(const ::librevenge::RVNGPropertyList &r) const
Definition: WPG2Parser.h:71
WPG2Parser::handleBitmapData
void handleBitmapData()
Definition: WPG2Parser.cpp:1773
libwpg::WPGDashArray
Definition: WPGDashArray.h:34
WPG2Parser::m_dashArrayStyles
std::map< unsigned int, libwpg::WPGDashArray > m_dashArrayStyles
Definition: WPG2Parser.h:247
WPG2TransformMatrix::WPG2TransformMatrix
WPG2TransformMatrix()
Definition: WPG2Parser.h:45
WPG2TransformMatrix::element
double element[3][3]
Definition: WPG2Parser.h:43
WPG2Parser::m_yres
unsigned int m_yres
Definition: WPG2Parser.h:234
WPG2Parser::m_gradient
::librevenge::RVNGPropertyListVector m_gradient
Definition: WPG2Parser.h:246
WPGTextDataContext::horAlign
unsigned char horAlign
Definition: WPG2Parser.h:167
libwpg::WPGColor
Definition: WPGColor.h:34
WPG2Parser::handleCompoundPolygon
void handleCompoundPolygon()
Definition: WPG2Parser.cpp:681
WPGBinaryDataContext::WPGBinaryDataContext
WPGBinaryDataContext()
Definition: WPG2Parser.h:158
WPGGroupContext::compoundClosed
bool compoundClosed
Definition: WPG2Parser.h:132
WPG2Parser::m_compoundFilled
bool m_compoundFilled
Definition: WPG2Parser.h:258
WPG2Parser::m_groupStack
std::stack< WPGGroupContext > m_groupStack
Definition: WPG2Parser.h:255
WPGCompoundPolygon::isFilled
bool isFilled
Definition: WPG2Parser.h:115
WPGCompoundPolygon::isFramed
bool isFramed
Definition: WPG2Parser.h:116
WPGBinaryDataContext::x2
double x2
Definition: WPG2Parser.h:155
WPG2Parser::m_doublePrecision
bool m_doublePrecision
Definition: WPG2Parser.h:239
WPGBitmapContext::WPGBitmapContext
WPGBitmapContext()
Definition: WPG2Parser.h:149
WPG2Parser::m_drawTextData
bool m_drawTextData
Definition: WPG2Parser.h:265
WPGXParser.h
WPG2Parser::m_exit
bool m_exit
Definition: WPG2Parser.h:231
WPG2Parser::m_style
::librevenge::RVNGPropertyList m_style
Definition: WPG2Parser.h:240
WPG2Parser::handleDPPenForeColor
void handleDPPenForeColor()
Definition: WPG2Parser.cpp:818
WPG2Parser::handleBrushBackColor
void handleBrushBackColor()
Definition: WPG2Parser.cpp:1244
WPG2Parser::setPenStyle
void setPenStyle()
Definition: WPG2Parser.cpp:883
WPG2Parser::handlePolycurve
void handlePolycurve()
Definition: WPG2Parser.cpp:1501
WPGTextDataContext::flags
unsigned short flags
Definition: WPG2Parser.h:165
WPG2Parser::handleEndWPG
void handleEndWPG()
Definition: WPG2Parser.cpp:629
WPG2Parser::m_layerOpened
bool m_layerOpened
Definition: WPG2Parser.h:248
WPGTextDataContext::x2
double x2
Definition: WPG2Parser.h:164
WPG2Parser::handlePenStyleDefinition
void handlePenStyleDefinition()
Definition: WPG2Parser.cpp:728
WPG2Parser::m_matrix
WPG2TransformMatrix m_matrix
Definition: WPG2Parser.h:252
WPGBinaryDataContext::y2
double y2
Definition: WPG2Parser.h:155
WPGGroupContext
Definition: WPG2Parser.h:122
WPG2Parser::m_yofs
long m_yofs
Definition: WPG2Parser.h:236
WPG2Parser::m_success
bool m_success
Definition: WPG2Parser.h:230
WPG2TransformMatrix::transformBy
WPG2TransformMatrix & transformBy(const WPG2TransformMatrix &m)
Definition: WPG2Parser.h:91
WPG2Parser::handleColorPalette
void handleColorPalette()
Definition: WPG2Parser.cpp:759
WPG2Parser::m_textData
WPGTextDataContext m_textData
Definition: WPG2Parser.h:264
WPG2Parser::m_compoundMatrix
WPG2TransformMatrix m_compoundMatrix
Definition: WPG2Parser.h:256
WPGGroupContext::compoundPath
::librevenge::RVNGPropertyListVector compoundPath
Definition: WPG2Parser.h:127
WPG2Parser::m_compoundClosed
bool m_compoundClosed
Definition: WPG2Parser.h:260
WPG2Parser::m_penBackColor
libwpg::WPGColor m_penBackColor
Definition: WPG2Parser.h:242
WPGGroupContext::isCompoundPolygon
bool isCompoundPolygon() const
Definition: WPG2Parser.h:138
WPGBitmapContext::y1
double y1
Definition: WPG2Parser.h:147
WPG2Parser::handleStartWPG
void handleStartWPG()
Definition: WPG2Parser.cpp:520
WPGGroupContext::compoundMatrix
WPG2TransformMatrix compoundMatrix
Definition: WPG2Parser.h:128
WPG2Parser::handleTextData
void handleTextData()
Definition: WPG2Parser.cpp:2344
WPG2Parser::handleDPBrushBackColor
void handleDPBrushBackColor()
Definition: WPG2Parser.cpp:1266
WPG2Parser::m_width
long m_width
Definition: WPG2Parser.h:237
WPG2TransformMatrix::transform
void transform(long &x, long &y) const
Definition: WPG2Parser.h:55
WPGCompoundPolygon::matrix
WPG2TransformMatrix matrix
Definition: WPG2Parser.h:114
WPGBitmapContext::y2
double y2
Definition: WPG2Parser.h:147
WPGBinaryDataContext::x1
double x1
Definition: WPG2Parser.h:155
WPGGroupContext::compoundWindingRule
bool compoundWindingRule
Definition: WPG2Parser.h:129
WPG2Parser::m_gradientAngle
double m_gradientAngle
Definition: WPG2Parser.h:253
WPG2Parser
Definition: WPG2Parser.h:172
WPGTextDataContext::x1
double x1
Definition: WPG2Parser.h:164
WPGCompoundPolygon
Definition: WPG2Parser.h:111
WPG2Parser::handleRectangle
void handleRectangle()
Definition: WPG2Parser.cpp:1584
WPGBinaryDataContext::mimeTypes
std::vector< librevenge::RVNGString > mimeTypes
Definition: WPG2Parser.h:157
WPGGroupContext::subIndex
unsigned subIndex
Definition: WPG2Parser.h:125
WPGTextDataContext::y2
double y2
Definition: WPG2Parser.h:164
WPG2Parser::handleDPBrushForeColor
void handleDPBrushForeColor()
Definition: WPG2Parser.cpp:1150
WPG2Parser::handleTextBlock
void handleTextBlock()
Definition: WPG2Parser.cpp:2299
WPGBitmapContext::x1
double x1
Definition: WPG2Parser.h:147
WPG2Parser::handlePenBackColor
void handlePenBackColor()
Definition: WPG2Parser.cpp:842
WPG2Parser::m_graphicsStarted
bool m_graphicsStarted
Definition: WPG2Parser.h:232
WPG2Parser::m_compoundWindingRule
bool m_compoundWindingRule
Definition: WPG2Parser.h:257
WPG2Parser::m_recordEnd
long m_recordEnd
Definition: WPG2Parser.h:229
WPGCompoundPolygon::isClosed
bool isClosed
Definition: WPG2Parser.h:117
WPG2Parser::handleBrushPattern
void handleBrushPattern()
Definition: WPG2Parser.cpp:1291
WPGTextDataContext::y1
double y1
Definition: WPG2Parser.h:164
WPG2Parser::handleDPPenSize
void handleDPPenSize()
Definition: WPG2Parser.cpp:940
WPG2Parser::parse
bool parse()
Definition: WPG2Parser.cpp:289
WPGBitmapContext::hres
long hres
Definition: WPG2Parser.h:148
WPG2Parser::m_xres
unsigned int m_xres
Definition: WPG2Parser.h:233
WPG2Parser::handleLayer
void handleLayer()
Definition: WPG2Parser.cpp:664
WPG2Parser::handleLineCap
void handleLineCap()
Definition: WPG2Parser.cpp:959
WPGCompoundPolygon::WPGCompoundPolygon
WPGCompoundPolygon()
Definition: WPG2Parser.h:119
WPG2Parser::handleArc
void handleArc()
Definition: WPG2Parser.cpp:1637
WPG2Parser::m_compoundFramed
bool m_compoundFramed
Definition: WPG2Parser.h:259
WPG2Parser::m_gradientRef
::librevenge::RVNGPropertyList m_gradientRef
Definition: WPG2Parser.h:254
WPGGroupContext::parentType
int parentType
Definition: WPG2Parser.h:126
WPGXParser
Definition: WPGXParser.h:38
WPG2Parser::handleTextPath
void handleTextPath()
Definition: WPG2Parser.cpp:2336
WPGGroupContext::compoundFramed
bool compoundFramed
Definition: WPG2Parser.h:131
WPG2Parser::m_xofs
long m_xofs
Definition: WPG2Parser.h:235
WPG2Parser::handleBrushForeColor
void handleBrushForeColor()
Definition: WPG2Parser.cpp:1057
WPG2Parser::flushCompoundPolygon
void flushCompoundPolygon()
Definition: WPG2Parser.cpp:695
WPG2Parser::handleDPColorPalette
void handleDPColorPalette()
Definition: WPG2Parser.cpp:778
WPGTextDataContext::WPGTextDataContext
WPGTextDataContext()
Definition: WPG2Parser.h:169
WPG2Parser::handlePenForeColor
void handlePenForeColor()
Definition: WPG2Parser.cpp:797
WPGTextDataContext::baseLineAngle
double baseLineAngle
Definition: WPG2Parser.h:168
WPGDashArray.h
WPG2Parser::handlePolyspline
void handlePolyspline()
Definition: WPG2Parser.cpp:1488
WPG2Parser::m_height
long m_height
Definition: WPG2Parser.h:238
WPG2Parser::handleObjectImage
void handleObjectImage()
Definition: WPG2Parser.cpp:2218
WPG2Parser::handlePenSize
void handlePenSize()
Definition: WPG2Parser.cpp:922
WPGBinaryDataContext::numObjects
int numObjects
Definition: WPG2Parser.h:156
WPG2TransformMatrix
Definition: WPG2Parser.h:40
WPGBitmapContext
Definition: WPG2Parser.h:144
WPG2Parser::handleDPPenBackColor
void handleDPPenBackColor()
Definition: WPG2Parser.cpp:862
WPG2Parser::m_binaryData
WPGBinaryDataContext m_binaryData
Definition: WPG2Parser.h:262
WPGTextDataContext::vertAlign
unsigned char vertAlign
Definition: WPG2Parser.h:166
WPG2TransformMatrix::transformPoint
::librevenge::RVNGPropertyList transformPoint(const ::librevenge::RVNGPropertyList &p) const
Definition: WPG2Parser.h:63
WPG2Parser::handleLineJoin
void handleLineJoin()
Definition: WPG2Parser.cpp:973
WPGGroupContext::compoundFilled
bool compoundFilled
Definition: WPG2Parser.h:130
WPG2Parser::handleTextLine
void handleTextLine()
Definition: WPG2Parser.cpp:2262
WPG2Parser::handleDPBrushGradient
void handleDPBrushGradient()
Definition: WPG2Parser.cpp:1022
WPG2Parser::m_hFlipped
bool m_hFlipped
Definition: WPG2Parser.h:263
WPG2Parser::m_bitmap
WPGBitmapContext m_bitmap
Definition: WPG2Parser.h:261
WPG2Parser::m_vFlipped
bool m_vFlipped
Definition: WPG2Parser.h:263
WPGGroupContext::WPGGroupContext
WPGGroupContext()
Definition: WPG2Parser.h:134
WPG2Parser::handleObjectCapsule
void handleObjectCapsule()
Definition: WPG2Parser.cpp:2128