VSDStylesCollector.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libvisio project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef VSDSTYLESCOLLECTOR_H
00011 #define VSDSTYLESCOLLECTOR_H
00012 
00013 #include <map>
00014 #include <vector>
00015 #include <list>
00016 #include "VSDCollector.h"
00017 #include "VSDParser.h"
00018 #include "libvisio_utils.h"
00019 #include "VSDStyles.h"
00020 
00021 namespace libvisio
00022 {
00023 
00024 class VSDStylesCollector : public VSDCollector
00025 {
00026 public:
00027   VSDStylesCollector(
00028     std::vector<std::map<unsigned, XForm> > &groupXFormsSequence,
00029     std::vector<std::map<unsigned, unsigned> > &groupMembershipsSequence,
00030     std::vector<std::list<unsigned> > &documentPageShapeOrders
00031   );
00032   virtual ~VSDStylesCollector() {}
00033 
00034   void collectEllipticalArcTo(unsigned id, unsigned level, double x3, double y3, double x2, double y2, double angle, double ecc);
00035   void collectForeignData(unsigned level, const librevenge::RVNGBinaryData &binaryData);
00036   void collectOLEList(unsigned id, unsigned level)
00037   {
00038     collectUnhandledChunk(id, level);
00039   }
00040   void collectOLEData(unsigned id, unsigned level, const librevenge::RVNGBinaryData &oleData);
00041   void collectEllipse(unsigned id, unsigned level, double cx, double cy, double xleft, double yleft, double xtop, double ytop);
00042   void collectLine(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
00043                    const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
00044                    const boost::optional<unsigned char> &lineCap);
00045   void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00046                             const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00047                             const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00048                             const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
00049   void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00050                             const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00051                             const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00052                             const boost::optional<Colour> &shfgc);
00053   void collectThemeReference(unsigned level, const boost::optional<long> &lineColour, const boost::optional<long> &fillColour,
00054                              const boost::optional<long> &shadowColour, const boost::optional<long> &fontColour);
00055   void collectGeometry(unsigned id, unsigned level, bool noFill, bool noLine, bool noShow);
00056   void collectMoveTo(unsigned id, unsigned level, double x, double y);
00057   void collectLineTo(unsigned id, unsigned level, double x, double y);
00058   void collectArcTo(unsigned id, unsigned level, double x2, double y2, double bow);
00059   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
00060                       const std::vector<std::pair<double, double> > &ctrlPnts, const std::vector<double> &kntVec, const std::vector<double> &weights);
00061   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
00062   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, const NURBSData &data);
00063   void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned char xType, unsigned char yType, const std::vector<std::pair<double, double> > &points);
00064   void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned dataID);
00065   void collectPolylineTo(unsigned id, unsigned level, double x, double y, const PolylineData &data);
00066   void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, unsigned degree, double lastKnot,
00067                         std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
00068   void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > points);
00069   void collectXFormData(unsigned level, const XForm &xform);
00070   void collectTxtXForm(unsigned level, const XForm &txtxform);
00071   void collectShapesOrder(unsigned id, unsigned level, const std::vector<unsigned> &shapeIds);
00072   void collectForeignDataType(unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height);
00073   void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale);
00074   void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage, const VSDName &pageName);
00075   void collectShape(unsigned id, unsigned level, unsigned parent, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle);
00076   void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree);
00077   void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot);
00078   void collectSplineEnd();
00079   void collectInfiniteLine(unsigned id, unsigned level, double x1, double y1, double x2, double y2);
00080   void collectRelCubBezTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
00081   void collectRelEllipticalArcTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
00082   void collectRelLineTo(unsigned id, unsigned level, double x, double y);
00083   void collectRelMoveTo(unsigned id, unsigned level, double x, double y);
00084   void collectRelQuadBezTo(unsigned id, unsigned level, double x, double y, double a, double b);
00085   void collectUnhandledChunk(unsigned id, unsigned level);
00086 
00087   void collectText(unsigned level, const librevenge::RVNGBinaryData &textStream, TextFormat format);
00088   void collectCharIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
00089                      const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
00090                      const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
00091                      const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
00092                      const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
00093                      const boost::optional<bool> &subscript);
00094   void collectDefaultCharStyle(unsigned charCount, const boost::optional<VSDName> &font, const boost::optional<Colour> &fontColour,
00095                                const boost::optional<double> &fontSize, const boost::optional<bool> &bold, const boost::optional<bool> &italic,
00096                                const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline, const boost::optional<bool> &strikeout,
00097                                const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps, const boost::optional<bool> &initcaps,
00098                                const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript, const boost::optional<bool> &subscript);
00099   void collectParaIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
00100                      const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
00101                      const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
00102                      const boost::optional<unsigned> &flags);
00103   void collectDefaultParaStyle(unsigned charCount, const boost::optional<double> &indFirst, const boost::optional<double> &indLeft,
00104                                const boost::optional<double> &indRight, const boost::optional<double> &spLine, const boost::optional<double> &spBefore,
00105                                const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align, const boost::optional<unsigned> &flags);
00106   void collectTextBlock(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
00107                         const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
00108                         const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
00109                         const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
00110                         const boost::optional<unsigned char> &textDirection);
00111   void collectNameList(unsigned id, unsigned level)
00112   {
00113     collectUnhandledChunk(id, level);
00114   }
00115   void collectName(unsigned id, unsigned level, const librevenge::RVNGBinaryData &name, TextFormat format);
00116   void collectPageSheet(unsigned id, unsigned level);
00117   void collectMisc(unsigned level, const VSDMisc &misc);
00118 
00119   // Style collectors
00120   void collectStyleSheet(unsigned id, unsigned level,unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
00121   void collectLineStyle(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
00122                         const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
00123                         const boost::optional<unsigned char> &lineCap);
00124   void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00125                         const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00126                         const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00127                         const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
00128   void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00129                         const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00130                         const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00131                         const boost::optional<Colour> &shfgc);
00132   void collectCharIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
00133                           const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
00134                           const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
00135                           const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
00136                           const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
00137                           const boost::optional<bool> &subscript);
00138   void collectParaIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
00139                           const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
00140                           const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
00141                           const boost::optional<unsigned> &flags);
00142   void collectTextBlockStyle(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
00143                              const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
00144                              const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
00145                              const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
00146                              const boost::optional<unsigned char> &textDirection);
00147   void collectStyleThemeReference(unsigned level, const boost::optional<long> &lineColour, const boost::optional<long> &fillColour,
00148                                   const boost::optional<long> &shadowColour, const boost::optional<long> &fontColour);
00149 
00150   // Field list
00151   void collectFieldList(unsigned id, unsigned level);
00152   void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId);
00153   void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
00154 
00155   virtual void collectMetaData(const librevenge::RVNGPropertyList &) { }
00156 
00157   // Temporary hack
00158   void startPage(unsigned pageID);
00159   void endPage();
00160   void endPages() {}
00161 
00162   const VSDStyles &getStyleSheets() const
00163   {
00164     return m_styles;
00165   }
00166 
00167 
00168 private:
00169   VSDStylesCollector(const VSDStylesCollector &);
00170   VSDStylesCollector &operator=(const VSDStylesCollector &);
00171 
00172   void _handleLevelChange(unsigned level);
00173   void _flushShapeList();
00174 
00175   unsigned m_currentLevel;
00176   bool m_isShapeStarted;
00177 
00178   double m_shadowOffsetX;
00179   double m_shadowOffsetY;
00180 
00181   unsigned m_currentShapeId;
00182   std::map<unsigned, XForm> m_groupXForms;
00183   std::map<unsigned, unsigned> m_groupMemberships;
00184   std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
00185   std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
00186   std::list<unsigned> m_pageShapeOrder;
00187   std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
00188   std::map<unsigned, std::list<unsigned> > m_groupShapeOrder;
00189   std::list<unsigned> m_shapeList;
00190 
00191   unsigned m_currentStyleSheet;
00192   VSDStyles m_styles;
00193 
00194   unsigned m_currentShapeLevel;
00195 };
00196 
00197 }
00198 
00199 #endif /* VSDSTYLESCOLLECTOR_H */
00200 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */