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

Generated for libwpg by doxygen 1.8.12