VSDContentCollector.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* libvisio
3  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License or as specified alternatively below. You may obtain a copy of
8  * the License at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * Major Contributor(s):
16  * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
17  * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
18  *
19  *
20  * All Rights Reserved.
21  *
22  * For minor contributions see the git repository.
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
26  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
27  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
28  * instead of those above.
29  */
30 
31 #ifndef VSDCONTENTCOLLECTOR_H
32 #define VSDCONTENTCOLLECTOR_H
33 
34 #include <locale.h>
35 #include <sstream>
36 #include <string>
37 #include <cmath>
38 #include <map>
39 #include <list>
40 #include <vector>
41 #include <libwpg/libwpg.h>
42 #include "libvisio_utils.h"
43 #include "VSDCollector.h"
44 #include "VSDParser.h"
45 #include "VSDOutputElementList.h"
46 #include "VSDStyles.h"
47 #include "VSDPages.h"
48 
49 namespace libvisio
50 {
51 
53 {
54 public:
56  libwpg::WPGPaintInterface *painter,
57  std::vector<std::map<unsigned, XForm> > &groupXFormsSequence,
58  std::vector<std::map<unsigned, unsigned> > &groupMembershipsSequence,
59  std::vector<std::list<unsigned> > &documentPageShapeOrders,
60  VSDStyles &styles, VSDStencils &stencils
61  );
63  {
64  if (m_txtxform) delete(m_txtxform);
65  };
66 
67  void collectEllipticalArcTo(unsigned id, unsigned level, double x3, double y3, double x2, double y2, double angle, double ecc);
68  void collectForeignData(unsigned level, const WPXBinaryData &binaryData);
69  void collectOLEList(unsigned id, unsigned level);
70  void collectOLEData(unsigned id, unsigned level, const WPXBinaryData &oleData);
71  void collectEllipse(unsigned id, unsigned level, double cx, double cy, double xleft, double yleft, double xtop, double ytop);
72  void collectLine(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
73  const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
74  const boost::optional<unsigned char> &lineCap);
75  void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
76  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
77  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
78  const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
79  void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
80  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
81  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
82  const boost::optional<Colour> &shfgc);
83  void collectGeometry(unsigned id, unsigned level, bool noFill, bool noLine, bool noShow);
84  void collectMoveTo(unsigned id, unsigned level, double x, double y);
85  void collectLineTo(unsigned id, unsigned level, double x, double y);
86  void collectArcTo(unsigned id, unsigned level, double x2, double y2, double bow);
87  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
88  std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
89  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
90  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, const NURBSData &data);
91  void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned char xType, unsigned char yType,
92  const std::vector<std::pair<double, double> > &points);
93  void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned dataID);
94  void collectPolylineTo(unsigned id, unsigned level, double x, double y, const PolylineData &data);
95  void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, unsigned degree, double lastKnot,
96  std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
97  void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > points);
98  void collectXFormData(unsigned level, const XForm &xform);
99  void collectTxtXForm(unsigned level, const XForm &txtxform);
100  void collectShapesOrder(unsigned id, unsigned level, const std::vector<unsigned> &shapeIds);
101  void collectForeignDataType(unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height);
102  void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale);
103  void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const VSDName &pageName);
104  void collectShape(unsigned id, unsigned level, unsigned parent, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle);
105  void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree);
106  void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot);
107  void collectSplineEnd();
108  void collectInfiniteLine(unsigned id, unsigned level, double x1, double y1, double x2, double y2);
109  void collectRelCubBezTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
110  void collectRelEllipticalArcTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
111  void collectRelLineTo(unsigned id, unsigned level, double x, double y);
112  void collectRelMoveTo(unsigned id, unsigned level, double x, double y);
113  void collectRelQuadBezTo(unsigned id, unsigned level, double x, double y, double a, double b);
114 
115  void collectUnhandledChunk(unsigned id, unsigned level);
116 
117  void collectText(unsigned level, const WPXBinaryData &textStream, TextFormat format);
118  void collectCharIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
119  const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
120  const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
121  const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
122  const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
123  const boost::optional<bool> &subscript);
124  void collectDefaultCharStyle(unsigned charCount, const boost::optional<VSDName> &font, const boost::optional<Colour> &fontColour,
125  const boost::optional<double> &fontSize, const boost::optional<bool> &bold, const boost::optional<bool> &italic,
126  const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline, const boost::optional<bool> &strikeout,
127  const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps, const boost::optional<bool> &initcaps,
128  const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript, const boost::optional<bool> &subscript);
129  void collectParaIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
130  const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
131  const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
132  const boost::optional<unsigned> &flags);
133  void collectDefaultParaStyle(unsigned charCount, const boost::optional<double> &indFirst, const boost::optional<double> &indLeft,
134  const boost::optional<double> &indRight, const boost::optional<double> &spLine, const boost::optional<double> &spBefore,
135  const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align, const boost::optional<unsigned> &flags);
136  void collectTextBlock(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
137  const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
138  const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
139  const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
140  const boost::optional<unsigned char> &textDirection);
141  void collectNameList(unsigned id, unsigned level);
142  void collectName(unsigned id, unsigned level, const WPXBinaryData &name, TextFormat format);
143  void collectPageSheet(unsigned id, unsigned level);
144 
145 
146  // Style collectors
147  void collectStyleSheet(unsigned id, unsigned level, unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
148  void collectLineStyle(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
149  const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
150  const boost::optional<unsigned char> &lineCap);
151  void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
152  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
153  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
154  const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
155  void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
156  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
157  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
158  const boost::optional<Colour> &shfgc);
159  void collectCharIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
160  const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
161  const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
162  const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
163  const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
164  const boost::optional<bool> &subscript);
165  void collectParaIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
166  const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
167  const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
168  const boost::optional<unsigned> &flags);
169  void collectTextBlockStyle(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
170  const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
171  const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
172  const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
173  const boost::optional<unsigned char> &textDirection);
174 
175  // Field list
176  void collectFieldList(unsigned id, unsigned level);
177  void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId);
178  void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
179 
180  void startPage(unsigned pageId);
181  void endPage();
182  void endPages();
183 
184 
185 private:
188  libwpg::WPGPaintInterface *m_painter;
189 
190  void applyXForm(double &x, double &y, const XForm &xform);
191 
192  void transformPoint(double &x, double &y, XForm *txtxform = 0);
193  void transformAngle(double &angle, XForm *txtxform = 0);
194  void transformFlips(bool &flipX, bool &flipY);
195 
196  double _NURBSBasis(unsigned knot, unsigned degree, double point, const std::vector<double> &knotVector);
197 
198  void _flushCurrentPath();
199  void _flushText();
201  void _flushCurrentPage();
202 
203  void _handleLevelChange(unsigned level);
204 
205  void _handleForeignData(const WPXBinaryData &data);
206 
207  void _lineProperties(const VSDLineStyle &style, WPXPropertyList &styleProps);
208  void _fillAndShadowProperties(const VSDFillStyle &style, WPXPropertyList &styleProps);
209 
210  void _applyLinePattern();
211  const char *_linePropertiesMarkerViewbox(unsigned marker);
212  const char *_linePropertiesMarkerPath(unsigned marker);
213  double _linePropertiesMarkerScale(unsigned marker);
214 
215  void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters, TextFormat format);
216  void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters);
217  void _convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format);
218  bool parseFormatId( const char *formatString, unsigned short &result );
219 
221  double m_pageWidth;
222  double m_pageHeight;
225  double m_scale;
226  double m_x;
227  double m_y;
228  double m_originalX;
229  double m_originalY;
232  std::vector<WPXPropertyList> m_currentFillGeometry;
233  std::vector<WPXPropertyList> m_currentLineGeometry;
234  std::map<unsigned, XForm> *m_groupXForms;
235  WPXBinaryData m_currentForeignData;
236  WPXBinaryData m_currentOLEData;
237  WPXPropertyList m_currentForeignProps;
239  unsigned m_foreignType;
240  unsigned m_foreignFormat;
245  bool m_noLine;
246  bool m_noFill;
247  bool m_noShow;
248  std::map<unsigned short, VSDFont> m_fonts;
249  unsigned m_currentLevel;
251  std::map<unsigned, unsigned> &m_groupMemberships;
252  std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
253  std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
256  std::map<unsigned, VSDOutputElementList> m_pageOutputDrawing;
257  std::map<unsigned, VSDOutputElementList> m_pageOutputText;
258  std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
259  std::list<unsigned> &m_pageShapeOrder;
261 
262  std::map<unsigned, NURBSData> m_NURBSData;
263  std::map<unsigned, PolylineData> m_polylineData;
264  WPXBinaryData m_textStream;
265  std::map<unsigned, WPXString> m_names, m_stencilNames;
266  std::vector<WPXString> m_fields;
268  unsigned m_fieldIndex;
270  std::vector<VSDCharStyle> m_charFormats;
271  std::vector<VSDParaStyle> m_paraFormats;
272 
276 
279 
282 
286 
288 
290  unsigned m_currentPageID;
293 
294  std::vector<std::pair<double, double> > m_splineControlPoints;
295  std::vector<double> m_splineKnotVector;
298  unsigned m_splineDegree;
299  unsigned m_splineLevel;
302 };
303 
304 } // namespace libvisio
305 
306 #endif /* VSDCONTENTCOLLECTOR_H */
307 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libvisio by doxygen 1.8.3.1