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 {
44 public:
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 
112 private:
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 
125 {
126 public:
128  bool isFilled;
129  bool isFramed;
130  bool isClosed;
131 
132  WPGCompoundPolygon(): matrix(), isFilled(true), isFramed(true), isClosed(true) {}
133 };
134 
136 {
137 public:
138  unsigned subIndex;
140  librevenge::RVNGPropertyListVector compoundPath;
146 
149  compoundFilled(false), compoundFramed(true), compoundClosed(false) {}
150 
151  bool isCompoundPolygon() const
152  {
153  return parentType == 0x1a;
154  }
155 };
156 
158 {
159 public:
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 {
167 public:
168  double x1, y1, x2, y2;
170  std::vector<librevenge::RVNGString> mimeTypes;
171  WPGBinaryDataContext(): x1(0), y1(0), x2(0), y2(0), numObjects(0), objectIndex(0), mimeTypes() {}
172 };
173 
175 {
176 public:
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 
185 class WPG2Parser : public WPGXParser
186 {
187 public:
188  WPG2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter, bool isEmbedded = false);
189  bool parse() override;
190 
191 private:
192  void handleStartWPG();
193  void handleEndWPG();
194  void handleFormSettings();
195  void handleLayer();
196  void handleCompoundPolygon();
197 
199 // void handlePatternDefinition();
200  void handleColorPalette();
201  void handleDPColorPalette();
202  void handlePenForeColor();
203  void handleDPPenForeColor();
204  void handlePenBackColor();
205  void handleDPPenBackColor();
206  void handlePenStyle();
207  void handlePenSize();
208  void handleDPPenSize();
209  void handleLineCap();
210  void handleLineJoin();
211  void handleBrushGradient();
212  void handleDPBrushGradient();
213  void handleBrushForeColor();
214  void handleDPBrushForeColor();
215  void handleBrushBackColor();
216  void handleDPBrushBackColor();
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();
237  void flushCompoundPolygon();
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
249  bool m_success;
250  bool m_exit;
252  unsigned int m_xres;
253  unsigned int m_yres;
254  long m_xofs;
255  long m_yofs;
256  long m_width;
257  long m_height;
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: */
libwpg::WPGColor m_brushForeColor
Definition: WPG2Parser.h:262
libwpg::WPGDashArray m_dashArray
Definition: WPG2Parser.h:264
Definition: WPG2Parser.cpp:198
libwpg::WPGColor m_brushBackColor
Definition: WPG2Parser.h:263
void parseCharacterization(ObjectCharacterization *)
Definition: WPG2Parser.cpp:1351
long vres
Definition: WPG2Parser.h:161
WPG2Parser(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *painter, bool isEmbedded=false)
Definition: WPG2Parser.cpp:258
void handleFormSettings()
Definition: WPG2Parser.cpp:674
void handleBrushGradient()
Definition: WPG2Parser.cpp:1023
libwpg::WPGColor m_penForeColor
Definition: WPG2Parser.h:260
int objectIndex
Definition: WPG2Parser.h:169
void handlePolyline()
Definition: WPG2Parser.cpp:1437
void handleBitmap()
Definition: WPG2Parser.cpp:1769
Definition: WPG2Parser.h:165
void resetPalette()
Definition: WPG2Parser.cpp:2445
void handlePenStyle()
Definition: WPG2Parser.cpp:933
Definition: WPG2Parser.h:174
double y1
Definition: WPG2Parser.h:168
double x2
Definition: WPG2Parser.h:160
int m_recordLength
Definition: WPG2Parser.h:247
void handleBitmapData()
Definition: WPG2Parser.cpp:1819
Definition: WPGDashArray.h:36
std::map< unsigned int, libwpg::WPGDashArray > m_dashArrayStyles
Definition: WPG2Parser.h:266
WPG2TransformMatrix()
Definition: WPG2Parser.h:47
double element[3][3]
Definition: WPG2Parser.h:45
librevenge::RVNGPropertyList transformRect(const ::librevenge::RVNGPropertyList &r) const
Definition: WPG2Parser.h:73
unsigned int m_yres
Definition: WPG2Parser.h:253
unsigned char horAlign
Definition: WPG2Parser.h:180
Definition: WPGColor.h:34
void handleCompoundPolygon()
Definition: WPG2Parser.cpp:713
librevenge::RVNGPropertyList m_gradientRef
Definition: WPG2Parser.h:273
WPGBinaryDataContext()
Definition: WPG2Parser.h:171
bool compoundClosed
Definition: WPG2Parser.h:145
bool m_compoundFilled
Definition: WPG2Parser.h:277
std::stack< WPGGroupContext > m_groupStack
Definition: WPG2Parser.h:274
bool isFilled
Definition: WPG2Parser.h:128
bool isFramed
Definition: WPG2Parser.h:129
double x2
Definition: WPG2Parser.h:168
bool m_doublePrecision
Definition: WPG2Parser.h:258
WPGBitmapContext()
Definition: WPG2Parser.h:162
bool m_drawTextData
Definition: WPG2Parser.h:284
bool m_exit
Definition: WPG2Parser.h:250
void handleDPPenForeColor()
Definition: WPG2Parser.cpp:854
void handleBrushBackColor()
Definition: WPG2Parser.cpp:1284
void setPenStyle()
Definition: WPG2Parser.cpp:919
void handlePolycurve()
Definition: WPG2Parser.cpp:1544
unsigned short flags
Definition: WPG2Parser.h:178
void handleEndWPG()
Definition: WPG2Parser.cpp:661
bool m_layerOpened
Definition: WPG2Parser.h:267
double x2
Definition: WPG2Parser.h:177
void handlePenStyleDefinition()
Definition: WPG2Parser.cpp:760
WPG2TransformMatrix m_matrix
Definition: WPG2Parser.h:271
double y2
Definition: WPG2Parser.h:168
Definition: WPG2Parser.h:135
long m_yofs
Definition: WPG2Parser.h:255
bool m_success
Definition: WPG2Parser.h:249
WPG2TransformMatrix & transformBy(const WPG2TransformMatrix &m)
Definition: WPG2Parser.h:93
void transformXY(long &x, long &y) const
Definition: WPG2Parser.cpp:2477
void handleColorPalette()
Definition: WPG2Parser.cpp:795
WPGTextDataContext m_textData
Definition: WPG2Parser.h:283
WPG2TransformMatrix m_compoundMatrix
Definition: WPG2Parser.h:275
bool m_compoundClosed
Definition: WPG2Parser.h:279
libwpg::WPGColor m_penBackColor
Definition: WPG2Parser.h:261
bool isCompoundPolygon() const
Definition: WPG2Parser.h:151
double y1
Definition: WPG2Parser.h:160
void handleStartWPG()
Definition: WPG2Parser.cpp:554
WPG2TransformMatrix compoundMatrix
Definition: WPG2Parser.h:141
unsigned int getRemainingRecordLength() const
Definition: WPG2Parser.cpp:2458
void handleTextData()
Definition: WPG2Parser.cpp:2411
void handleDPBrushBackColor()
Definition: WPG2Parser.cpp:1306
bool checkRLESize(unsigned bytes) const
Definition: WPG2Parser.cpp:2465
long m_width
Definition: WPG2Parser.h:256
void transform(long &x, long &y) const
Definition: WPG2Parser.h:57
WPG2TransformMatrix matrix
Definition: WPG2Parser.h:127
double y2
Definition: WPG2Parser.h:160
double x1
Definition: WPG2Parser.h:168
bool compoundWindingRule
Definition: WPG2Parser.h:142
bool parse() override
Definition: WPG2Parser.cpp:317
double m_gradientAngle
Definition: WPG2Parser.h:272
Definition: WPG2Parser.h:185
double x1
Definition: WPG2Parser.h:177
Definition: WPG2Parser.h:124
void handleRectangle()
Definition: WPG2Parser.cpp:1630
std::vector< librevenge::RVNGString > mimeTypes
Definition: WPG2Parser.h:170
unsigned subIndex
Definition: WPG2Parser.h:138
double y2
Definition: WPG2Parser.h:177
void handleDPBrushForeColor()
Definition: WPG2Parser.cpp:1188
void handleTextBlock()
Definition: WPG2Parser.cpp:2366
double x1
Definition: WPG2Parser.h:160
librevenge::RVNGPropertyListVector m_gradient
Definition: WPG2Parser.h:265
void handlePenBackColor()
Definition: WPG2Parser.cpp:878
bool m_graphicsStarted
Definition: WPG2Parser.h:251
bool m_compoundWindingRule
Definition: WPG2Parser.h:276
long m_recordEnd
Definition: WPG2Parser.h:248
bool isClosed
Definition: WPG2Parser.h:130
void handleBrushPattern()
Definition: WPG2Parser.cpp:1331
double y1
Definition: WPG2Parser.h:177
void handleDPPenSize()
Definition: WPG2Parser.cpp:976
librevenge::RVNGPropertyList m_style
Definition: WPG2Parser.h:259
long hres
Definition: WPG2Parser.h:161
unsigned int m_xres
Definition: WPG2Parser.h:252
void handleLayer()
Definition: WPG2Parser.cpp:696
librevenge::RVNGPropertyList transformPoint(const ::librevenge::RVNGPropertyList &p) const
Definition: WPG2Parser.h:65
static long toLong(double d)
Definition: WPG2Parser.h:113
void handleLineCap()
Definition: WPG2Parser.cpp:995
WPGCompoundPolygon()
Definition: WPG2Parser.h:132
void handleArc()
Definition: WPG2Parser.cpp:1683
bool m_compoundFramed
Definition: WPG2Parser.h:278
int parentType
Definition: WPG2Parser.h:139
Definition: WPGXParser.h:39
void handleTextPath()
Definition: WPG2Parser.cpp:2403
bool compoundFramed
Definition: WPG2Parser.h:144
long m_xofs
Definition: WPG2Parser.h:254
void handleBrushForeColor()
Definition: WPG2Parser.cpp:1093
void flushCompoundPolygon()
Definition: WPG2Parser.cpp:727
void handleDPColorPalette()
Definition: WPG2Parser.cpp:814
WPGTextDataContext()
Definition: WPG2Parser.h:182
double toDouble(long x) const
Definition: WPG2Parser.cpp:2472
void handlePenForeColor()
Definition: WPG2Parser.cpp:833
double baseLineAngle
Definition: WPG2Parser.h:181
void handlePolyspline()
Definition: WPG2Parser.cpp:1531
long m_height
Definition: WPG2Parser.h:257
void handleObjectImage()
Definition: WPG2Parser.cpp:2281
void handlePenSize()
Definition: WPG2Parser.cpp:958
librevenge::RVNGPropertyListVector compoundPath
Definition: WPG2Parser.h:140
int numObjects
Definition: WPG2Parser.h:169
Definition: WPG2Parser.h:42
Definition: WPG2Parser.h:157
void handleDPPenBackColor()
Definition: WPG2Parser.cpp:898
WPGBinaryDataContext m_binaryData
Definition: WPG2Parser.h:281
unsigned char vertAlign
Definition: WPG2Parser.h:179
void handleLineJoin()
Definition: WPG2Parser.cpp:1009
bool compoundFilled
Definition: WPG2Parser.h:143
void handleTextLine()
Definition: WPG2Parser.cpp:2329
void handleDPBrushGradient()
Definition: WPG2Parser.cpp:1058
bool m_hFlipped
Definition: WPG2Parser.h:282
WPGBitmapContext m_bitmap
Definition: WPG2Parser.h:280
bool m_vFlipped
Definition: WPG2Parser.h:282
WPGGroupContext()
Definition: WPG2Parser.h:147
void handleObjectCapsule()
Definition: WPG2Parser.cpp:2191

Generated for libwpg by doxygen 1.8.6