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();
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_currentGeometry;
00199 std::map<unsigned, XForm> &m_groupXForms;
00200 WPXBinaryData m_currentForeignData;
00201 WPXBinaryData m_currentOLEData;
00202 WPXPropertyList m_currentForeignProps;
00203 unsigned m_currentShapeId;
00204 unsigned m_foreignType;
00205 unsigned m_foreignFormat;
00206 double m_foreignOffsetX;
00207 double m_foreignOffsetY;
00208 double m_foreignWidth;
00209 double m_foreignHeight;
00210 WPXPropertyList m_styleProps;
00211 ::WPXString m_lineColour;
00212 ::WPXString m_fillType;
00213 unsigned m_linePattern;
00214 unsigned m_fillPattern;
00215 unsigned m_fillFGTransparency;
00216 unsigned m_fillBGTransparency;
00217 bool m_noLine;
00218 bool m_noFill;
00219 bool m_noShow;
00220 std::vector<Colour> m_colours;
00221 std::map<unsigned short, WPXString> m_fonts;
00222 unsigned m_currentLevel;
00223 bool m_isShapeStarted;
00224 std::map<unsigned, unsigned> &m_groupMemberships;
00225 std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
00226 std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
00227 unsigned m_currentPageNumber;
00228 VSDXOutputElementList *m_shapeOutputDrawing, *m_shapeOutputText;
00229 std::map<unsigned, VSDXOutputElementList> m_pageOutputDrawing;
00230 std::map<unsigned, VSDXOutputElementList> m_pageOutputText;
00231 std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
00232 std::list<unsigned> &m_pageShapeOrder;
00233 bool m_isFirstGeometry;
00234
00235 std::map<unsigned, NURBSData> m_NURBSData;
00236 std::map<unsigned, PolylineData> m_polylineData;
00237 WPXBinaryData m_textStream;
00238 std::map<unsigned, WPXString> m_names, m_stencilNames;
00239 std::vector<WPXString> m_fields;
00240 VSDXFieldList m_stencilFields;
00241 unsigned m_fieldIndex;
00242 TextFormat m_textFormat;
00243 std::vector<VSDXCharStyle> m_charFormats;
00244 std::vector<VSDXParaStyle> m_paraFormats;
00245
00246 VSDXTextBlockStyle m_textBlockStyle;
00247
00248 VSDXCharStyle m_defaultCharStyle;
00249 VSDXParaStyle m_defaultParaStyle;
00250
00251 VSDXStyles m_styles;
00252
00253 VSDXStencils m_stencils;
00254 const VSDXStencilShape *m_stencilShape;
00255 bool m_isStencilStarted;
00256
00257 unsigned m_currentGeometryCount;
00258
00259 unsigned m_backgroundPageID;
00260 unsigned m_currentPageID;
00261 VSDXPage m_currentPage;
00262 VSDXPages m_pages;
00263
00264 std::vector<std::pair<double, double> > m_splineControlPoints;
00265 std::vector<double> m_splineKnotVector;
00266 double m_splineX, m_splineY;
00267 double m_splineLastKnot;
00268 unsigned m_splineDegree;
00269 unsigned m_splineLevel;
00270 };
00271
00272 }
00273
00274 #endif
00275