VSDContentCollector.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3  * This file is part of the libvisio project.
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 
10 #ifndef VSDCONTENTCOLLECTOR_H
11 #define VSDCONTENTCOLLECTOR_H
12 
13 #include <locale.h>
14 #include <sstream>
15 #include <string>
16 #include <cmath>
17 #include <map>
18 #include <list>
19 #include <vector>
20 #include "libvisio_utils.h"
21 #include "VSDCollector.h"
22 #include "VSDParser.h"
23 #include "VSDOutputElementList.h"
24 #include "VSDStyles.h"
25 #include "VSDPages.h"
26 
27 namespace libvisio
28 {
29 
31 {
32 public:
34  librevenge::RVNGDrawingInterface *painter,
35  std::vector<std::map<unsigned, XForm> > &groupXFormsSequence,
36  std::vector<std::map<unsigned, unsigned> > &groupMembershipsSequence,
37  std::vector<std::list<unsigned> > &documentPageShapeOrders,
38  VSDStyles &styles, VSDStencils &stencils
39  );
41  {
42  if (m_txtxform) delete(m_txtxform);
43  };
44 
45  void collectEllipticalArcTo(unsigned id, unsigned level, double x3, double y3, double x2, double y2, double angle, double ecc);
46  void collectForeignData(unsigned level, const librevenge::RVNGBinaryData &binaryData);
47  void collectOLEList(unsigned id, unsigned level);
48  void collectOLEData(unsigned id, unsigned level, const librevenge::RVNGBinaryData &oleData);
49  void collectEllipse(unsigned id, unsigned level, double cx, double cy, double xleft, double yleft, double xtop, double ytop);
50  void collectLine(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
51  const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
52  const boost::optional<unsigned char> &lineCap);
53  void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
54  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
55  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
56  const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
57  void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
58  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
59  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
60  const boost::optional<Colour> &shfgc);
61  void collectThemeReference(unsigned level, const boost::optional<long> &lineColour, const boost::optional<long> &fillColour,
62  const boost::optional<long> &shadowColour, const boost::optional<long> &fontColour);
63  void collectGeometry(unsigned id, unsigned level, bool noFill, bool noLine, bool noShow);
64  void collectMoveTo(unsigned id, unsigned level, double x, double y);
65  void collectLineTo(unsigned id, unsigned level, double x, double y);
66  void collectArcTo(unsigned id, unsigned level, double x2, double y2, double bow);
67  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
68  const std::vector<std::pair<double, double> > &ctrlPnts, const std::vector<double> &kntVec, const std::vector<double> &weights);
69  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
70  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, const NURBSData &data);
71  void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned char xType, unsigned char yType,
72  const std::vector<std::pair<double, double> > &points);
73  void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned dataID);
74  void collectPolylineTo(unsigned id, unsigned level, double x, double y, const PolylineData &data);
75  void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, unsigned degree, double lastKnot,
76  std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
77  void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > points);
78  void collectXFormData(unsigned level, const XForm &xform);
79  void collectTxtXForm(unsigned level, const XForm &txtxform);
80  void collectShapesOrder(unsigned id, unsigned level, const std::vector<unsigned> &shapeIds);
81  void collectForeignDataType(unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height);
82  void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale);
83  void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const VSDName &pageName);
84  void collectShape(unsigned id, unsigned level, unsigned parent, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle);
85  void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree);
86  void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot);
87  void collectSplineEnd();
88  void collectInfiniteLine(unsigned id, unsigned level, double x1, double y1, double x2, double y2);
89  void collectRelCubBezTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
90  void collectRelEllipticalArcTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
91  void collectRelLineTo(unsigned id, unsigned level, double x, double y);
92  void collectRelMoveTo(unsigned id, unsigned level, double x, double y);
93  void collectRelQuadBezTo(unsigned id, unsigned level, double x, double y, double a, double b);
94 
95  void collectUnhandledChunk(unsigned id, unsigned level);
96 
97  void collectText(unsigned level, const librevenge::RVNGBinaryData &textStream, TextFormat format);
98  void collectCharIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
99  const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
100  const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
101  const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
102  const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
103  const boost::optional<bool> &subscript);
104  void collectDefaultCharStyle(unsigned charCount, const boost::optional<VSDName> &font, const boost::optional<Colour> &fontColour,
105  const boost::optional<double> &fontSize, const boost::optional<bool> &bold, const boost::optional<bool> &italic,
106  const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline, const boost::optional<bool> &strikeout,
107  const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps, const boost::optional<bool> &initcaps,
108  const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript, const boost::optional<bool> &subscript);
109  void collectParaIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
110  const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
111  const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
112  const boost::optional<unsigned> &flags);
113  void collectDefaultParaStyle(unsigned charCount, const boost::optional<double> &indFirst, const boost::optional<double> &indLeft,
114  const boost::optional<double> &indRight, const boost::optional<double> &spLine, const boost::optional<double> &spBefore,
115  const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align, const boost::optional<unsigned> &flags);
116  void collectTextBlock(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
117  const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
118  const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
119  const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
120  const boost::optional<unsigned char> &textDirection);
121  void collectNameList(unsigned id, unsigned level);
122  void collectName(unsigned id, unsigned level, const librevenge::RVNGBinaryData &name, TextFormat format);
123  void collectPageSheet(unsigned id, unsigned level);
124  void collectMisc(unsigned level, const VSDMisc &misc);
125 
126 
127  // Style collectors
128  void collectStyleSheet(unsigned id, unsigned level, unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
129  void collectLineStyle(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
130  const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
131  const boost::optional<unsigned char> &lineCap);
132  void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
133  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
134  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
135  const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
136  void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
137  const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
138  const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
139  const boost::optional<Colour> &shfgc);
140  void collectCharIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
141  const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
142  const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
143  const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
144  const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
145  const boost::optional<bool> &subscript);
146  void collectParaIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
147  const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
148  const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
149  const boost::optional<unsigned> &flags);
150  void collectTextBlockStyle(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
151  const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
152  const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
153  const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
154  const boost::optional<unsigned char> &textDirection);
155  void collectStyleThemeReference(unsigned level, const boost::optional<long> &lineColour, const boost::optional<long> &fillColour,
156  const boost::optional<long> &shadowColour, const boost::optional<long> &fontColour);
157 
158 
159  // Field list
160  void collectFieldList(unsigned id, unsigned level);
161  void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId);
162  void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
163 
164  void startPage(unsigned pageId);
165  void endPage();
166  void endPages();
167 
168 
169 private:
172  librevenge::RVNGDrawingInterface *m_painter;
173 
174  void applyXForm(double &x, double &y, const XForm &xform);
175 
176  void transformPoint(double &x, double &y, XForm *txtxform = 0);
177  void transformAngle(double &angle, XForm *txtxform = 0);
178  void transformFlips(bool &flipX, bool &flipY);
179 
180  double _NURBSBasis(unsigned knot, unsigned degree, double point, const std::vector<double> &knotVector);
181 
182  void _flushShape();
183  void _flushCurrentPath();
184  void _flushText();
186  void _flushCurrentPage();
187 
188  void _handleLevelChange(unsigned level);
189 
190  void _handleForeignData(const librevenge::RVNGBinaryData &data);
191 
192  void _lineProperties(const VSDLineStyle &style, librevenge::RVNGPropertyList &styleProps);
193  void _fillAndShadowProperties(const VSDFillStyle &style, librevenge::RVNGPropertyList &styleProps);
194 
195  void _applyLinePattern();
196  const char *_linePropertiesMarkerViewbox(unsigned marker);
197  const char *_linePropertiesMarkerPath(unsigned marker);
198  double _linePropertiesMarkerScale(unsigned marker);
199 
200  void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned char> &characters, TextFormat format);
201  void appendCharacters(librevenge::RVNGString &text, const std::vector<unsigned char> &characters);
202  void _convertDataToString(librevenge::RVNGString &result, const librevenge::RVNGBinaryData &data, TextFormat format);
203  bool parseFormatId(const char *formatString, unsigned short &result);
204  void _appendField(librevenge::RVNGString &text);
205 
206  // NURBS processing functions
207  bool _isUniform(const std::vector<double> &weights) const;
208  void _generatePolylineFromNURBS(unsigned degree, const std::vector<std::pair<double, double> > &controlPoints,
209  const std::vector<double> &knotVector, const std::vector<double> &weights);
210  void _generateBezierSegmentsFromNURBS(unsigned degree, const std::vector<std::pair<double, double> > &controlPoints,
211  const std::vector<double> &knotVector);
212  void _outputCubicBezierSegment(const std::vector<std::pair<double, double> > &points);
213  void _outputQuadraticBezierSegment(const std::vector<std::pair<double, double> > &points);
214  void _outputLinearBezierSegment(const std::vector<std::pair<double, double> > &points);
215 
217  double m_pageWidth;
218  double m_pageHeight;
221  double m_scale;
222  double m_x;
223  double m_y;
224  double m_originalX;
225  double m_originalY;
229  std::vector<librevenge::RVNGPropertyList> m_currentFillGeometry;
230  std::vector<librevenge::RVNGPropertyList> m_currentLineGeometry;
231  std::map<unsigned, XForm> *m_groupXForms;
232  librevenge::RVNGBinaryData m_currentForeignData;
233  librevenge::RVNGBinaryData m_currentOLEData;
234  librevenge::RVNGPropertyList m_currentForeignProps;
236  unsigned m_foreignType;
237  unsigned m_foreignFormat;
242  bool m_noLine;
243  bool m_noFill;
244  bool m_noShow;
245  std::map<unsigned short, VSDFont> m_fonts;
246  unsigned m_currentLevel;
248  std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
249  std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
250  std::vector<std::map<unsigned, unsigned> >::iterator m_groupMemberships;
253  std::map<unsigned, VSDOutputElementList> m_pageOutputDrawing;
254  std::map<unsigned, VSDOutputElementList> m_pageOutputText;
255  std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
256  std::vector<std::list<unsigned> >::iterator m_pageShapeOrder;
258 
259  std::map<unsigned, NURBSData> m_NURBSData;
260  std::map<unsigned, PolylineData> m_polylineData;
261  librevenge::RVNGBinaryData m_textStream;
262  std::map<unsigned, librevenge::RVNGString> m_names, m_stencilNames;
263  std::vector<librevenge::RVNGString> m_fields;
265  unsigned m_fieldIndex;
267  std::vector<VSDCharStyle> m_charFormats;
268  std::vector<VSDParaStyle> m_paraFormats;
269 
273 
275 
278 
281 
285 
287 
289  unsigned m_currentPageID;
292 
293  std::vector<std::pair<double, double> > m_splineControlPoints;
294  std::vector<double> m_splineKnotVector;
297  unsigned m_splineDegree;
298  unsigned m_splineLevel;
301 };
302 
303 } // namespace libvisio
304 
305 #endif /* VSDCONTENTCOLLECTOR_H */
306 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libvisio by doxygen 1.8.4