00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef VSDXCONTENTCOLLECTOR_H
00032 #define VSDXCONTENTCOLLECTOR_H
00033
00034 #include <locale.h>
00035 #include <sstream>
00036 #include <string>
00037 #include <cmath>
00038 #include <map>
00039 #include <list>
00040 #include <vector>
00041 #include <libwpg/libwpg.h>
00042 #include "libvisio_utils.h"
00043 #include "VSDXCollector.h"
00044 #include "VSDXParser.h"
00045 #include "VSDXOutputElementList.h"
00046 #include "VSDXStyles.h"
00047 #include "VSDXPages.h"
00048
00049 namespace libvisio
00050 {
00051
00052 class VSDXContentCollector : public VSDXCollector
00053 {
00054 public:
00055 VSDXContentCollector(
00056 libwpg::WPGPaintInterface *painter,
00057 std::vector<std::map<unsigned, XForm> > &groupXFormsSequence,
00058 std::vector<std::map<unsigned, unsigned> > &groupMembershipsSequence,
00059 std::vector<std::list<unsigned> > &documentPageShapeOrders,
00060 VSDXStyles &styles, VSDXStencils &stencils
00061 );
00062 virtual ~VSDXContentCollector()
00063 {
00064 if (m_txtxform) delete(m_txtxform);
00065 };
00066
00067 void collectEllipticalArcTo(unsigned id, unsigned level, double x3, double y3, double x2, double y2, double angle, double ecc);
00068 void collectForeignData(unsigned id, unsigned level, const WPXBinaryData &binaryData);
00069 void collectOLEList(unsigned id, unsigned level);
00070 void collectOLEData(unsigned id, unsigned level, const WPXBinaryData &oleData);
00071 void collectEllipse(unsigned id, unsigned level, double cx, double cy, double xleft, double yleft, double xtop, double ytop);
00072 void collectLine(unsigned id, unsigned level, double strokeWidth, Colour c, unsigned linePattern, unsigned char startMarker, unsigned char endMarker, unsigned lineCap);
00073 void collectFillAndShadow(unsigned id, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
00074 unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc,
00075 double shadowOffsetX, double shadowOffsetY);
00076 void collectFillAndShadow(unsigned id, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
00077 unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc);
00078 void collectGeometry(unsigned id, unsigned level, unsigned char geomFlags);
00079 void collectMoveTo(unsigned id, unsigned level, double x, double y);
00080 void collectLineTo(unsigned id, unsigned level, double x, double y);
00081 void collectArcTo(unsigned id, unsigned level, double x2, double y2, double bow);
00082 void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
00083 std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
00084 void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
00085 void collectPolylineTo(unsigned id , unsigned level, double x, double y, unsigned char xType, unsigned char yType,
00086 std::vector<std::pair<double, double> > &points);
00087 void collectPolylineTo(unsigned id , unsigned level, double x, double y, unsigned dataID);
00088 void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, unsigned degree, double lastKnot,
00089 std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
00090 void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > points);
00091 void collectXFormData(unsigned id, unsigned level, const XForm &xform);
00092 void collectTxtXForm(unsigned id, unsigned level, const XForm &txtxform);
00093 void collectShapeId(unsigned id, unsigned level, unsigned shapeId);
00094 void collectForeignDataType(unsigned id, unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height);
00095 void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale);
00096 void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, unsigned currentPageID);
00097 void collectShape(unsigned id, unsigned level, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle);
00098 void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree);
00099 void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot);
00100 void collectSplineEnd();
00101 void collectInfiniteLine(unsigned id, unsigned level, double x1, double y1, double x2, double y2);
00102
00103 void collectUnhandledChunk(unsigned id, unsigned level);
00104
00105 void collectColours(const std::vector<Colour> &colours);
00106 void collectFont(unsigned short fontID, const WPXBinaryData &textStream, TextFormat format);
00107 void collectText(unsigned id, unsigned level, const WPXBinaryData &textStream, TextFormat format);
00108 void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
00109 double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
00110 bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
00111 void collectVSDXParaStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
00112 double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
00113 void collectTextBlock(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
00114 unsigned char bgClrId, const Colour &bgColour, double defaultTabStop, unsigned char textDirection);
00115 void collectNameList(unsigned id, unsigned level);
00116 void collectName(unsigned id, unsigned level, const WPXBinaryData &name, TextFormat format);
00117
00118
00119
00120 void collectStyleSheet(unsigned id, unsigned level, unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
00121 void collectLineStyle(unsigned id, unsigned level, double strokeWidth, Colour c, unsigned char linePattern, unsigned char startMarker, unsigned char endMarker, unsigned char lineCap);
00122 void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
00123 unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc,
00124 double shadowOffsetX, double shadowOffsetY);
00125 void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
00126 unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc);
00127 void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
00128 double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
00129 bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
00130 void collectParaIXStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
00131 double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
00132 void collectTextBlockStyle(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
00133 unsigned char bgClrId, const Colour &bgColour, double defaultTabStop, unsigned char textDirection);
00134
00135
00136 void collectFieldList(unsigned id, unsigned level);
00137 void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId);
00138 void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
00139
00140 void startPage();
00141 void endPage();
00142 void endPages(const std::vector<unsigned> &pageOrder);
00143
00144
00145 private:
00146 VSDXContentCollector(const VSDXContentCollector &);
00147 VSDXContentCollector &operator=(const VSDXContentCollector &);
00148 libwpg::WPGPaintInterface *m_painter;
00149
00150 void applyXForm(double &x, double &y, const XForm &xform);
00151
00152 void transformPoint(double &x, double &y, XForm *txtxform = 0);
00153 void transformAngle(double &angle, XForm *txtxform = 0);
00154 void transformFlips(bool &flipX, bool &flipY);
00155
00156 double _NURBSBasis(unsigned knot, unsigned degree, double point, const std::vector<double> &knotVector);
00157
00158 void _flushCurrentPath();
00159 void _flushText();
00160 void _flushCurrentForeignData();
00161 void _flushCurrentPage();
00162
00163 void _handleLevelChange(unsigned level);
00164 void _appendUTF16LE(WPXString &text, WPXInputStream *input);
00165 void _appendUCS4(WPXString &text, unsigned ucs4Character);
00166
00167 void _handleForeignData(const WPXBinaryData &data);
00168
00169 void lineStyleFromStyleSheet(unsigned styleId);
00170 void fillStyleFromStyleSheet(unsigned styleId);
00171 void lineStyleFromStyleSheet(const VSDXLineStyle *style);
00172 void fillStyleFromStyleSheet(const VSDXFillStyle *style);
00173
00174 void _applyLinePattern();
00175 void _lineProperties(double strokeWidth, Colour c, unsigned linePattern, unsigned startMarker, unsigned endMarker, unsigned lineCap);
00176 const char *_linePropertiesMarkerViewbox(unsigned marker);
00177 const char *_linePropertiesMarkerPath(unsigned marker);
00178 double _linePropertiesMarkerScale(unsigned marker);
00179 void _fillAndShadowProperties(unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
00180 unsigned fillFGTransparency, unsigned fillBGTransparency,
00181 unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY);
00182
00183 void _convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format);
00184 bool parseFormatId( const char *formatString, unsigned short &result );
00185
00186 bool m_isPageStarted;
00187 double m_pageWidth;
00188 double m_pageHeight;
00189 double m_shadowOffsetX;
00190 double m_shadowOffsetY;
00191 double m_scale;
00192 double m_x;
00193 double m_y;
00194 double m_originalX;
00195 double m_originalY;
00196 XForm m_xform;
00197 XForm *m_txtxform;
00198 std::vector<WPXPropertyList> m_currentFillGeometry;
00199 std::vector<WPXPropertyList> m_currentLineGeometry;
00200 std::map<unsigned, XForm> &m_groupXForms;
00201 WPXBinaryData m_currentForeignData;
00202 WPXBinaryData m_currentOLEData;
00203 WPXPropertyList m_currentForeignProps;
00204 unsigned m_currentShapeId;
00205 unsigned m_foreignType;
00206 unsigned m_foreignFormat;
00207 double m_foreignOffsetX;
00208 double m_foreignOffsetY;
00209 double m_foreignWidth;
00210 double m_foreignHeight;
00211 WPXPropertyList m_styleProps;
00212 ::WPXString m_lineColour;
00213 ::WPXString m_fillType;
00214 unsigned m_linePattern;
00215 unsigned m_fillPattern;
00216 unsigned m_fillFGTransparency;
00217 unsigned m_fillBGTransparency;
00218 bool m_noLine;
00219 bool m_noFill;
00220 bool m_noShow;
00221 std::vector<Colour> m_colours;
00222 std::map<unsigned short, WPXString> m_fonts;
00223 unsigned m_currentLevel;
00224 bool m_isShapeStarted;
00225 std::map<unsigned, unsigned> &m_groupMemberships;
00226 std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
00227 std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
00228 unsigned m_currentPageNumber;
00229 VSDXOutputElementList *m_shapeOutputDrawing, *m_shapeOutputText;
00230 std::map<unsigned, VSDXOutputElementList> m_pageOutputDrawing;
00231 std::map<unsigned, VSDXOutputElementList> m_pageOutputText;
00232 std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
00233 std::list<unsigned> &m_pageShapeOrder;
00234 bool m_isFirstGeometry;
00235
00236 std::map<unsigned, NURBSData> m_NURBSData;
00237 std::map<unsigned, PolylineData> m_polylineData;
00238 WPXBinaryData m_textStream;
00239 std::map<unsigned, WPXString> m_names, m_stencilNames;
00240 std::vector<WPXString> m_fields;
00241 VSDXFieldList m_stencilFields;
00242 unsigned m_fieldIndex;
00243 TextFormat m_textFormat;
00244 std::vector<VSDXCharStyle> m_charFormats;
00245 std::vector<VSDXParaStyle> m_paraFormats;
00246
00247 VSDXTextBlockStyle m_textBlockStyle;
00248
00249 VSDXCharStyle m_defaultCharStyle;
00250 VSDXParaStyle m_defaultParaStyle;
00251
00252 VSDXStyles m_styles;
00253
00254 VSDXStencils m_stencils;
00255 const VSDXStencilShape *m_stencilShape;
00256 bool m_isStencilStarted;
00257
00258 unsigned m_currentGeometryCount;
00259
00260 unsigned m_backgroundPageID;
00261 unsigned m_currentPageID;
00262 VSDXPage m_currentPage;
00263 VSDXPages m_pages;
00264
00265 std::vector<std::pair<double, double> > m_splineControlPoints;
00266 std::vector<double> m_splineKnotVector;
00267 double m_splineX, m_splineY;
00268 double m_splineLastKnot;
00269 unsigned m_splineDegree;
00270 unsigned m_splineLevel;
00271 };
00272
00273 }
00274
00275 #endif
00276