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 <limits>
32#include <map>
33#include <stack>
34#include <vector>
35
36#include <librevenge/librevenge.h>
37
38#include "WPGBitmap.h"
39#include "WPGDashArray.h"
40#include "WPGXParser.h"
41
43{
44public:
45 double element[3][3];
46
48 {
49 // identity transformation
50 element[0][0] = element[1][1] = 1;
51 element[2][2] = 1;
52 element[0][1] = element[0][2] = 0;
53 element[1][0] = element[1][2] = 0;
54 element[2][0] = element[2][1] = 0;
55 }
56
57 void transform(long &x, long &y) const
58 {
59 const double rx = element[0][0]*x + element[1][0]*y + element[2][0];
60 const double ry = element[0][1]*x + element[1][1]*y + element[2][1];
61 x = toLong(rx);
62 y = toLong(ry);
63 }
64
65 librevenge::RVNGPropertyList transformPoint(const ::librevenge::RVNGPropertyList &p) const
66 {
67 librevenge::RVNGPropertyList propList;
68 propList.insert("svg:x", (element[0][0]*p["svg:x"]->getDouble() + element[1][0]*p["svg:y"]->getDouble() + element[2][0]));
69 propList.insert("svg:y", (element[0][1]*p["svg:x"]->getDouble() + element[1][1]*p["svg:y"]->getDouble() + element[2][1]));
70 return propList;
71 }
72
73 librevenge::RVNGPropertyList transformRect(const ::librevenge::RVNGPropertyList &r) const
74 {
75 librevenge::RVNGPropertyList propList;
76 double oldx1 = r["svg:x"]->getDouble();
77 double oldy1 = r["svg:y"]->getDouble();
78 double oldx2 = r["svg:x"]->getDouble() + r["svg:width"]->getDouble();
79 double oldy2 = r["svg:y"]->getDouble() + r["svg:height"]->getDouble();
80
81 double newx1 = element[0][0]*oldx1 + element[1][0]*oldy1 + element[2][0];
82 double newy1 = element[0][1]*oldx1 + element[1][1]*oldy1 + element[2][1];
83 double newx2 = element[0][0]*oldx2 + element[1][0]*oldy2 + element[2][0];
84 double newy2 = element[0][1]*oldx2 + element[1][1]*oldy2 + element[2][1];
85
86 propList.insert("svg:x", (double)newx1);
87 propList.insert("svg:y", (double)newy1);
88 propList.insert("svg:width", (newx2-newx1));
89 propList.insert("svg:height", (newy2-newy1));
90 return propList;
91 }
92
94 {
95 double result[3][3];
96
97 for (int i = 0; i < 3; i++)
98 for (int j = 0; j < 3; j++)
99 {
100 result[i][j] = 0;
101 for (int k = 0; k < 3; k++)
102 result[i][j] += m.element[i][k]*element[k][j];
103 }
104
105 for (int x = 0; x < 3; x++)
106 for (int y = 0; y < 3; y++)
107 element[x][y] = result[x][y];
108
109 return *this;
110 }
111
112private:
113 static long toLong(double d)
114 {
115 if (d > double(std::numeric_limits<long>::max()))
116 return std::numeric_limits<long>::max();
117 else if (d < double(std::numeric_limits<long>::min()))
118 return std::numeric_limits<long>::min();
119 else
120 return long(d);
121 }
122};
123
134
136{
137public:
138 unsigned subIndex;
140 librevenge::RVNGPropertyListVector compoundPath;
146
150
151 bool isCompoundPolygon() const
152 {
153 return parentType == 0x1a;
154 }
155};
156
158{
159public:
160 double x1, y1, x2, y2;
161 long hres, vres;
162 WPGBitmapContext(): x1(0), y1(0), x2(0), y2(0), hres(100), vres(100) {}
163};
164
166{
167public:
168 double x1, y1, x2, y2;
170 std::vector<librevenge::RVNGString> mimeTypes;
172};
173
175{
176public:
177 double x1, y1, x2, y2;
178 unsigned short flags;
179 unsigned char vertAlign;
180 unsigned char horAlign;
182 WPGTextDataContext(): x1(0), y1(0), x2(0), y2(0), flags(), vertAlign(), horAlign(), baseLineAngle(0.0) {}
183};
184
185class WPG2Parser : public WPGXParser
186{
187public:
188 WPG2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter, bool isEmbedded = false);
189 bool parse() override;
190
191private:
192 void handleStartWPG();
193 void handleEndWPG();
194 void handleFormSettings();
195 void handleLayer();
197
200 void handleColorPalette();
202 void handlePenForeColor();
204 void handlePenBackColor();
206 void handlePenStyle();
207 void handlePenSize();
208 void handleDPPenSize();
209 void handleLineCap();
210 void handleLineJoin();
211 void handleBrushGradient();
217 void handleBrushPattern();
218
219 void handlePolyline();
220 void handlePolyspline();
221 void handlePolycurve();
222 void handleRectangle();
223 void handleArc();
224
225 void handleBitmap();
226 void handleBitmapData();
227
228 void handleTextData();
229 void handleTextLine();
230 void handleTextBlock();
231 void handleTextPath();
232
233 void handleObjectCapsule();
234 void handleObjectImage();
235
236 void resetPalette();
238 void setPenStyle();
239
240 unsigned int getRemainingRecordLength() const;
241 bool checkRLESize(unsigned bytes) const;
242
243 double toDouble(long x) const;
244 void transformXY(long &x, long &y) const;
245
246 // parsing context
250 bool m_exit;
252 unsigned int m_xres;
253 unsigned int m_yres;
254 long m_xofs;
255 long m_yofs;
259 librevenge::RVNGPropertyList m_style;
265 librevenge::RVNGPropertyListVector m_gradient;
266 std::map<unsigned int,libwpg::WPGDashArray> m_dashArrayStyles;
268#ifdef DEBUG
269 unsigned int m_layerId;
270#endif
273 librevenge::RVNGPropertyList m_gradientRef;
274 std::stack<WPGGroupContext> m_groupStack;
285
288#if DUMP_BINARY_DATA
289 unsigned m_binaryId;
290#endif
291};
292
293#endif // __WPG2PARSER_H__
294/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
Definition WPG2Parser.cpp:199
void handleDPBrushForeColor()
Definition WPG2Parser.cpp:1190
WPGTextDataContext m_textData
Definition WPG2Parser.h:283
bool m_compoundFramed
Definition WPG2Parser.h:278
WPGBitmapContext m_bitmap
Definition WPG2Parser.h:280
void handleLineCap()
Definition WPG2Parser.cpp:997
long m_width
Definition WPG2Parser.h:256
void handleRectangle()
Definition WPG2Parser.cpp:1630
void handleObjectCapsule()
Definition WPG2Parser.cpp:2191
void parseCharacterization(ObjectCharacterization *)
Definition WPG2Parser.cpp:1351
long m_xofs
Definition WPG2Parser.h:254
void handleBrushGradient()
Definition WPG2Parser.cpp:1025
void handleBrushBackColor()
Definition WPG2Parser.cpp:1286
WPG2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter, bool isEmbedded=false)
Definition WPG2Parser.cpp:258
librevenge::RVNGPropertyList m_style
Definition WPG2Parser.h:259
WPG2TransformMatrix m_matrix
Definition WPG2Parser.h:271
void handlePolyline()
Definition WPG2Parser.cpp:1437
void handleDPColorPalette()
Definition WPG2Parser.cpp:812
bool m_vFlipped
Definition WPG2Parser.h:282
std::stack< WPGGroupContext > m_groupStack
Definition WPG2Parser.h:274
void flushCompoundPolygon()
Definition WPG2Parser.cpp:727
librevenge::RVNGPropertyListVector m_gradient
Definition WPG2Parser.h:265
void handleDPPenForeColor()
Definition WPG2Parser.cpp:855
unsigned int m_xres
Definition WPG2Parser.h:252
void handleTextLine()
Definition WPG2Parser.cpp:2329
void handlePolyspline()
Definition WPG2Parser.cpp:1531
bool m_graphicsStarted
Definition WPG2Parser.h:251
void handleBitmap()
Definition WPG2Parser.cpp:1769
void handlePenSize()
Definition WPG2Parser.cpp:960
void handleBrushForeColor()
Definition WPG2Parser.cpp:1095
void handleTextData()
Definition WPG2Parser.cpp:2411
void handleEndWPG()
Definition WPG2Parser.cpp:661
int m_recordLength
Definition WPG2Parser.h:247
void handleArc()
Definition WPG2Parser.cpp:1683
void handleStartWPG()
Definition WPG2Parser.cpp:554
void handlePenStyleDefinition()
Definition WPG2Parser.cpp:760
void handlePenStyle()
Definition WPG2Parser.cpp:935
bool m_layerOpened
Definition WPG2Parser.h:267
bool m_drawTextData
Definition WPG2Parser.h:284
bool m_compoundWindingRule
Definition WPG2Parser.h:276
void handleCompoundPolygon()
Definition WPG2Parser.cpp:713
void handleDPBrushGradient()
Definition WPG2Parser.cpp:1060
void transformXY(long &x, long &y) const
Definition WPG2Parser.cpp:2477
bool m_success
Definition WPG2Parser.h:249
void handlePenForeColor()
Definition WPG2Parser.cpp:831
void handleTextPath()
Definition WPG2Parser.cpp:2403
unsigned int m_yres
Definition WPG2Parser.h:253
bool parse() override
Definition WPG2Parser.cpp:317
libwpg::WPGDashArray m_dashArray
Definition WPG2Parser.h:264
void handleLayer()
Definition WPG2Parser.cpp:696
libwpg::WPGColor m_brushBackColor
Definition WPG2Parser.h:263
long m_yofs
Definition WPG2Parser.h:255
unsigned int getRemainingRecordLength() const
Definition WPG2Parser.cpp:2458
bool m_compoundFilled
Definition WPG2Parser.h:277
libwpg::WPGColor m_brushForeColor
Definition WPG2Parser.h:262
void handleBrushPattern()
Definition WPG2Parser.cpp:1331
void handleLineJoin()
Definition WPG2Parser.cpp:1011
void handlePatternDefinition()
Definition WPG2Parser.cpp:786
void handleBitmapData()
Definition WPG2Parser.cpp:1819
void handleDPPenSize()
Definition WPG2Parser.cpp:978
long m_recordEnd
Definition WPG2Parser.h:248
bool m_compoundClosed
Definition WPG2Parser.h:279
double toDouble(long x) const
Definition WPG2Parser.cpp:2472
void resetPalette()
Definition WPG2Parser.cpp:2445
double m_gradientAngle
Definition WPG2Parser.h:272
void setPenStyle()
Definition WPG2Parser.cpp:921
void handleTextBlock()
Definition WPG2Parser.cpp:2366
void handleColorPalette()
Definition WPG2Parser.cpp:793
WPGBinaryDataContext m_binaryData
Definition WPG2Parser.h:281
bool m_doublePrecision
Definition WPG2Parser.h:258
void handlePolycurve()
Definition WPG2Parser.cpp:1544
libwpg::WPGColor m_penForeColor
Definition WPG2Parser.h:260
long m_height
Definition WPG2Parser.h:257
void handleFormSettings()
Definition WPG2Parser.cpp:674
WPG2TransformMatrix m_compoundMatrix
Definition WPG2Parser.h:275
void handleDPPenBackColor()
Definition WPG2Parser.cpp:900
void handleDPBrushBackColor()
Definition WPG2Parser.cpp:1308
bool m_hFlipped
Definition WPG2Parser.h:282
std::map< unsigned int, libwpg::WPGDashArray > m_dashArrayStyles
Definition WPG2Parser.h:266
libwpg::WPGColor m_penBackColor
Definition WPG2Parser.h:261
void handleObjectImage()
Definition WPG2Parser.cpp:2281
bool m_exit
Definition WPG2Parser.h:250
bool checkRLESize(unsigned bytes) const
Definition WPG2Parser.cpp:2465
void handlePenBackColor()
Definition WPG2Parser.cpp:880
librevenge::RVNGPropertyList m_gradientRef
Definition WPG2Parser.h:273
Definition WPG2Parser.h:43
WPG2TransformMatrix & transformBy(const WPG2TransformMatrix &m)
Definition WPG2Parser.h:93
static long toLong(double d)
Definition WPG2Parser.h:113
librevenge::RVNGPropertyList transformPoint(const ::librevenge::RVNGPropertyList &p) const
Definition WPG2Parser.h:65
void transform(long &x, long &y) const
Definition WPG2Parser.h:57
librevenge::RVNGPropertyList transformRect(const ::librevenge::RVNGPropertyList &r) const
Definition WPG2Parser.h:73
double element[3][3]
Definition WPG2Parser.h:45
WPG2TransformMatrix()
Definition WPG2Parser.h:47
Definition WPG2Parser.h:166
int numObjects
Definition WPG2Parser.h:169
double y1
Definition WPG2Parser.h:168
double x2
Definition WPG2Parser.h:168
double x1
Definition WPG2Parser.h:168
std::vector< librevenge::RVNGString > mimeTypes
Definition WPG2Parser.h:170
WPGBinaryDataContext()
Definition WPG2Parser.h:171
double y2
Definition WPG2Parser.h:168
int objectIndex
Definition WPG2Parser.h:169
Definition WPG2Parser.h:158
double y2
Definition WPG2Parser.h:160
double y1
Definition WPG2Parser.h:160
long vres
Definition WPG2Parser.h:161
double x1
Definition WPG2Parser.h:160
double x2
Definition WPG2Parser.h:160
WPGBitmapContext()
Definition WPG2Parser.h:162
long hres
Definition WPG2Parser.h:161
bool isFilled
Definition WPG2Parser.h:128
WPGCompoundPolygon()
Definition WPG2Parser.h:132
bool isClosed
Definition WPG2Parser.h:130
WPG2TransformMatrix matrix
Definition WPG2Parser.h:127
bool isFramed
Definition WPG2Parser.h:129
WPG2TransformMatrix compoundMatrix
Definition WPG2Parser.h:141
bool compoundFilled
Definition WPG2Parser.h:143
librevenge::RVNGPropertyListVector compoundPath
Definition WPG2Parser.h:140
bool isCompoundPolygon() const
Definition WPG2Parser.h:151
unsigned subIndex
Definition WPG2Parser.h:138
bool compoundWindingRule
Definition WPG2Parser.h:142
bool compoundFramed
Definition WPG2Parser.h:144
WPGGroupContext()
Definition WPG2Parser.h:147
bool compoundClosed
Definition WPG2Parser.h:145
int parentType
Definition WPG2Parser.h:139
Definition WPG2Parser.h:175
double baseLineAngle
Definition WPG2Parser.h:181
double y2
Definition WPG2Parser.h:177
double x1
Definition WPG2Parser.h:177
double y1
Definition WPG2Parser.h:177
unsigned char horAlign
Definition WPG2Parser.h:180
double x2
Definition WPG2Parser.h:177
unsigned char vertAlign
Definition WPG2Parser.h:179
WPGTextDataContext()
Definition WPG2Parser.h:182
unsigned short flags
Definition WPG2Parser.h:178
WPGXParser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter)
Definition WPGXParser.cpp:30
Definition WPGColor.h:35
Definition WPGDashArray.h:37

Generated for libwpg by doxygen 1.14.0