VSDXContentCollector.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libvisio
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
00017  * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
00018  *
00019  *
00020  * All Rights Reserved.
00021  *
00022  * For minor contributions see the git repository.
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00026  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00027  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00028  * instead of those above.
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   // Style collectors
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   // Field list
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   void _fillAndShadowProperties(unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
00177                                 unsigned fillFGTransparency, unsigned fillBGTransparency,
00178                                 unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY);
00179 
00180   void _convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format);
00181   bool parseFormatId( const char *formatString, unsigned short &result );
00182 
00183   bool m_isPageStarted;
00184   double m_pageWidth;
00185   double m_pageHeight;
00186   double m_shadowOffsetX;
00187   double m_shadowOffsetY;
00188   double m_scale;
00189   double m_x;
00190   double m_y;
00191   double m_originalX;
00192   double m_originalY;
00193   XForm m_xform;
00194   XForm *m_txtxform;
00195   std::vector<WPXPropertyList> m_currentGeometry;
00196   std::map<unsigned, XForm> &m_groupXForms;
00197   WPXBinaryData m_currentForeignData;
00198   WPXBinaryData m_currentOLEData;
00199   WPXPropertyList m_currentForeignProps;
00200   unsigned m_currentShapeId;
00201   unsigned m_foreignType;
00202   unsigned m_foreignFormat;
00203   double m_foreignOffsetX;
00204   double m_foreignOffsetY;
00205   double m_foreignWidth;
00206   double m_foreignHeight;
00207   WPXPropertyList m_styleProps;
00208   ::WPXString m_lineColour;
00209   ::WPXString m_fillType;
00210   unsigned m_linePattern;
00211   unsigned m_fillPattern;
00212   unsigned m_fillFGTransparency;
00213   unsigned m_fillBGTransparency;
00214   bool m_noLine;
00215   bool m_noFill;
00216   bool m_noShow;
00217   std::vector<Colour> m_colours;
00218   std::map<unsigned short, WPXString> m_fonts;
00219   unsigned m_currentLevel;
00220   bool m_isShapeStarted;
00221   std::map<unsigned, unsigned> &m_groupMemberships;
00222   std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
00223   std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
00224   unsigned m_currentPageNumber;
00225   VSDXOutputElementList *m_shapeOutputDrawing, *m_shapeOutputText;
00226   std::map<unsigned, VSDXOutputElementList> m_pageOutputDrawing;
00227   std::map<unsigned, VSDXOutputElementList> m_pageOutputText;
00228   std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
00229   std::list<unsigned> &m_pageShapeOrder;
00230   bool m_isFirstGeometry;
00231 
00232   std::map<unsigned, NURBSData> m_NURBSData;
00233   std::map<unsigned, PolylineData> m_polylineData;
00234   WPXBinaryData m_textStream;
00235   std::map<unsigned, WPXString> m_names, m_stencilNames;
00236   std::vector<WPXString> m_fields;
00237   VSDXFieldList m_stencilFields;
00238   unsigned m_fieldIndex;
00239   TextFormat m_textFormat;
00240   std::vector<VSDXCharStyle> m_charFormats;
00241   std::vector<VSDXParaStyle> m_paraFormats;
00242 
00243   VSDXTextBlockStyle m_textBlockStyle;
00244 
00245   VSDXCharStyle m_defaultCharStyle;
00246   VSDXParaStyle m_defaultParaStyle;
00247 
00248   VSDXStyles m_styles;
00249 
00250   VSDXStencils m_stencils;
00251   const VSDXStencilShape *m_stencilShape;
00252   bool m_isStencilStarted;
00253 
00254   unsigned m_currentGeometryCount;
00255 
00256   unsigned m_backgroundPageID;
00257   unsigned m_currentPageID;
00258   VSDXPage m_currentPage;
00259   VSDXPages m_pages;
00260 
00261   std::vector<std::pair<double, double> > m_splineControlPoints;
00262   std::vector<double> m_splineKnotVector;
00263   double m_splineX, m_splineY;
00264   double m_splineLastKnot;
00265   unsigned m_splineDegree;
00266   unsigned m_splineLevel;
00267 };
00268 
00269 } // namespace libvisio
00270 
00271 #endif /* VSDXCONTENTCOLLECTOR_H */
00272 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */