VSDXContentCollector.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 VSDXCONTENTCOLLECTOR_H
32 #define VSDXCONTENTCOLLECTOR_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 "VSDXCollector.h"
44 #include "VSDXParser.h"
45 #include "VSDXOutputElementList.h"
46 #include "VSDXStyles.h"
47 #include "VSDXPages.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  VSDXStyles &styles, VSDXStencils &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 id, 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 id, unsigned level, double strokeWidth, Colour c, unsigned linePattern, unsigned char startMarker, unsigned char endMarker, unsigned lineCap);
73  void collectFillAndShadow(unsigned id, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
74  unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc,
75  double shadowOffsetX, double shadowOffsetY);
76  void collectFillAndShadow(unsigned id, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
77  unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc);
78  void collectGeometry(unsigned id, unsigned level, unsigned char geomFlags);
79  void collectMoveTo(unsigned id, unsigned level, double x, double y);
80  void collectLineTo(unsigned id, unsigned level, double x, double y);
81  void collectArcTo(unsigned id, unsigned level, double x2, double y2, double bow);
82  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
83  std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
84  void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
85  void collectPolylineTo(unsigned id , unsigned level, double x, double y, unsigned char xType, unsigned char yType,
86  std::vector<std::pair<double, double> > &points);
87  void collectPolylineTo(unsigned id , unsigned level, double x, double y, unsigned dataID);
88  void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, unsigned degree, double lastKnot,
89  std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
90  void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > points);
91  void collectXFormData(unsigned id, unsigned level, const XForm &xform);
92  void collectTxtXForm(unsigned id, unsigned level, const XForm &txtxform);
93  void collectShapeId(unsigned id, unsigned level, unsigned shapeId);
94  void collectForeignDataType(unsigned id, unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height);
95  void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale);
96  void collectPage(unsigned id, unsigned level, unsigned backgroundPageID);
97  void collectShape(unsigned id, unsigned level, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle);
98  void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree);
99  void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot);
100  void collectSplineEnd();
101  void collectInfiniteLine(unsigned id, unsigned level, double x1, double y1, double x2, double y2);
102 
103  void collectUnhandledChunk(unsigned id, unsigned level);
104 
105  void collectColours(const std::vector<Colour> &colours);
106  void collectFont(unsigned short fontID, const WPXBinaryData &textStream, TextFormat format);
107  void collectText(unsigned id, unsigned level, const WPXBinaryData &textStream, TextFormat format);
108  void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
109  bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
110  bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace);
111  void collectVSDXParaStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
112  double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
113  void collectTextBlock(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
114  unsigned char bgClrId, const Colour &bgColour, double defaultTabStop, unsigned char textDirection);
115  void collectNameList(unsigned id, unsigned level);
116  void collectName(unsigned id, unsigned level, const WPXBinaryData &name, TextFormat format);
117 
118 
119  // Style collectors
120  void collectStyleSheet(unsigned id, unsigned level, unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
121  void collectLineStyle(unsigned id, unsigned level, double strokeWidth, Colour c, unsigned char linePattern, unsigned char startMarker, unsigned char endMarker, unsigned char lineCap);
122  void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
123  unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc,
124  double shadowOffsetX, double shadowOffsetY);
125  void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
126  unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc);
127  void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, double fontSize,
128  bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
129  bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, VSDXFont fontFace);
130  void collectParaIXStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
131  double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
132  void collectTextBlockStyle(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
133  unsigned char bgClrId, const Colour &bgColour, double defaultTabStop, unsigned char textDirection);
134 
135  // Field list
136  void collectFieldList(unsigned id, unsigned level);
137  void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId);
138  void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
139 
140  void startPage(unsigned pageId);
141  void endPage();
142  void endPages();
143 
144 
145 private:
148  libwpg::WPGPaintInterface *m_painter;
149 
150  void applyXForm(double &x, double &y, const XForm &xform);
151 
152  void transformPoint(double &x, double &y, XForm *txtxform = 0);
153  void transformAngle(double &angle, XForm *txtxform = 0);
154  void transformFlips(bool &flipX, bool &flipY);
155 
156  double _NURBSBasis(unsigned knot, unsigned degree, double point, const std::vector<double> &knotVector);
157 
158  void _flushCurrentPath();
159  void _flushText();
161  void _flushCurrentPage();
162 
163  void _handleLevelChange(unsigned level);
164 
165  void _handleForeignData(const WPXBinaryData &data);
166 
167  void lineStyleFromStyleSheet(unsigned styleId);
168  void fillStyleFromStyleSheet(unsigned styleId);
169  void lineStyleFromStyleSheet(const VSDXLineStyle *style);
170  void fillStyleFromStyleSheet(const VSDXFillStyle *style);
171 
172  void _applyLinePattern();
173  void _lineProperties(double strokeWidth, Colour c, unsigned linePattern, unsigned startMarker, unsigned endMarker, unsigned lineCap);
174  const char *_linePropertiesMarkerViewbox(unsigned marker);
175  const char *_linePropertiesMarkerPath(unsigned marker);
176  double _linePropertiesMarkerScale(unsigned marker);
177  void _fillAndShadowProperties(unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
178  unsigned fillFGTransparency, unsigned fillBGTransparency,
179  unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY);
180 
181  void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters, TextFormat format);
182  void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters);
183  void _convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format);
184  bool parseFormatId( const char *formatString, unsigned short &result );
185 
187  double m_pageWidth;
188  double m_pageHeight;
191  double m_scale;
192  double m_x;
193  double m_y;
194  double m_originalX;
195  double m_originalY;
198  std::vector<WPXPropertyList> m_currentFillGeometry;
199  std::vector<WPXPropertyList> m_currentLineGeometry;
200  std::map<unsigned, XForm> &m_groupXForms;
201  WPXBinaryData m_currentForeignData;
202  WPXBinaryData m_currentOLEData;
203  WPXPropertyList m_currentForeignProps;
205  unsigned m_foreignType;
206  unsigned m_foreignFormat;
211  WPXPropertyList m_styleProps;
212  ::WPXString m_lineColour;
213  ::WPXString m_fillType;
214  unsigned m_linePattern;
215  unsigned m_fillPattern;
218  bool m_noLine;
219  bool m_noFill;
220  bool m_noShow;
221  std::vector<Colour> m_colours;
222  std::map<unsigned short, VSDXFont> m_fonts;
223  unsigned m_currentLevel;
225  std::map<unsigned, unsigned> &m_groupMemberships;
226  std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
227  std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
230  std::map<unsigned, VSDXOutputElementList> m_pageOutputDrawing;
231  std::map<unsigned, VSDXOutputElementList> m_pageOutputText;
232  std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
233  std::list<unsigned> &m_pageShapeOrder;
235 
236  std::map<unsigned, NURBSData> m_NURBSData;
237  std::map<unsigned, PolylineData> m_polylineData;
238  WPXBinaryData m_textStream;
239  std::map<unsigned, WPXString> m_names, m_stencilNames;
240  std::vector<WPXString> m_fields;
242  unsigned m_fieldIndex;
244  std::vector<VSDXCharStyle> m_charFormats;
245  std::vector<VSDXParaStyle> m_paraFormats;
246 
248 
251 
253 
257 
259 
261  unsigned m_currentPageID;
264 
265  std::vector<std::pair<double, double> > m_splineControlPoints;
266  std::vector<double> m_splineKnotVector;
269  unsigned m_splineDegree;
270  unsigned m_splineLevel;
272 };
273 
274 } // namespace libvisio
275 
276 #endif /* VSDXCONTENTCOLLECTOR_H */
277 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */

Generated for libvisio by doxygen 1.8.1.2