VSDStylesCollector.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 VSDSTYLESCOLLECTOR_H
00032 #define VSDSTYLESCOLLECTOR_H
00033 
00034 #include <map>
00035 #include <vector>
00036 #include <list>
00037 #include "VSDCollector.h"
00038 #include "VSDParser.h"
00039 #include "libvisio_utils.h"
00040 #include "VSDStyles.h"
00041 
00042 namespace libvisio
00043 {
00044 
00045 class VSDStylesCollector : public VSDCollector
00046 {
00047 public:
00048   VSDStylesCollector(
00049     std::vector<std::map<unsigned, XForm> > &groupXFormsSequence,
00050     std::vector<std::map<unsigned, unsigned> > &groupMembershipsSequence,
00051     std::vector<std::list<unsigned> > &documentPageShapeOrders
00052   );
00053   virtual ~VSDStylesCollector() {}
00054 
00055   void collectEllipticalArcTo(unsigned id, unsigned level, double x3, double y3, double x2, double y2, double angle, double ecc);
00056   void collectForeignData(unsigned level, const WPXBinaryData &binaryData);
00057   void collectOLEList(unsigned id, unsigned level)
00058   {
00059     collectUnhandledChunk(id, level);
00060   }
00061   void collectOLEData(unsigned id, unsigned level, const WPXBinaryData &oleData);
00062   void collectEllipse(unsigned id, unsigned level, double cx, double cy, double xleft, double yleft, double xtop, double ytop);
00063   void collectLine(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
00064                    const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
00065                    const boost::optional<unsigned char> &lineCap);
00066   void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00067                             const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00068                             const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00069                             const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
00070   void collectFillAndShadow(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00071                             const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00072                             const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00073                             const boost::optional<Colour> &shfgc);
00074   void collectGeometry(unsigned id, unsigned level, bool noFill, bool noLine, bool noShow);
00075   void collectMoveTo(unsigned id, unsigned level, double x, double y);
00076   void collectLineTo(unsigned id, unsigned level, double x, double y);
00077   void collectArcTo(unsigned id, unsigned level, double x2, double y2, double bow);
00078   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType,
00079                       unsigned degree, std::vector<std::pair<double, double> > controlPoints,
00080                       std::vector<double> knotVector, std::vector<double> weights);
00081   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
00082   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, const NURBSData &data);
00083   void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned char xType, unsigned char yType, const std::vector<std::pair<double, double> > &points);
00084   void collectPolylineTo(unsigned id, unsigned level, double x, double y, unsigned dataID);
00085   void collectPolylineTo(unsigned id, unsigned level, double x, double y, const PolylineData &data);
00086   void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, unsigned degree, double lastKnot,
00087                         std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
00088   void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > points);
00089   void collectXFormData(unsigned level, const XForm &xform);
00090   void collectTxtXForm(unsigned level, const XForm &txtxform);
00091   void collectShapesOrder(unsigned id, unsigned level, const std::vector<unsigned> &shapeIds);
00092   void collectForeignDataType(unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height);
00093   void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale);
00094   void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, bool isBackgroundPage);
00095   void collectShape(unsigned id, unsigned level, unsigned parent, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle);
00096   void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree);
00097   void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot);
00098   void collectSplineEnd();
00099   void collectInfiniteLine(unsigned id, unsigned level, double x1, double y1, double x2, double y2);
00100   void collectRelCubBezTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
00101   void collectRelEllipticalArcTo(unsigned id, unsigned level, double x, double y, double a, double b, double c, double d);
00102   void collectRelLineTo(unsigned id, unsigned level, double x, double y);
00103   void collectRelMoveTo(unsigned id, unsigned level, double x, double y);
00104   void collectRelQuadBezTo(unsigned id, unsigned level, double x, double y, double a, double b);
00105   void collectUnhandledChunk(unsigned id, unsigned level);
00106 
00107   void collectText(unsigned level, const ::WPXBinaryData &textStream, TextFormat format);
00108   void collectCharIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
00109                      const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
00110                      const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
00111                      const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
00112                      const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
00113                      const boost::optional<bool> &subscript);
00114   void collectDefaultCharStyle(unsigned charCount, const boost::optional<VSDName> &font, const boost::optional<Colour> &fontColour,
00115                                const boost::optional<double> &fontSize, const boost::optional<bool> &bold, const boost::optional<bool> &italic,
00116                                const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline, const boost::optional<bool> &strikeout,
00117                                const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps, const boost::optional<bool> &initcaps,
00118                                const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript, const boost::optional<bool> &subscript);
00119   void collectParaIX(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
00120                      const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
00121                      const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
00122                      const boost::optional<unsigned> &flags);
00123   void collectDefaultParaStyle(unsigned charCount, const boost::optional<double> &indFirst, const boost::optional<double> &indLeft,
00124                                const boost::optional<double> &indRight, const boost::optional<double> &spLine, const boost::optional<double> &spBefore,
00125                                const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align, const boost::optional<unsigned> &flags);
00126   void collectTextBlock(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
00127                         const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
00128                         const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
00129                         const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
00130                         const boost::optional<unsigned char> &textDirection);
00131   void collectNameList(unsigned id, unsigned level)
00132   {
00133     collectUnhandledChunk(id, level);
00134   }
00135   void collectName(unsigned id, unsigned level, const ::WPXBinaryData &name, TextFormat format);
00136   void collectPageSheet(unsigned id, unsigned level);
00137 
00138   // Style collectors
00139   void collectStyleSheet(unsigned id, unsigned level,unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
00140   void collectLineStyle(unsigned level, const boost::optional<double> &strokeWidth, const boost::optional<Colour> &c, const boost::optional<unsigned char> &linePattern,
00141                         const boost::optional<unsigned char> &startMarker, const boost::optional<unsigned char> &endMarker,
00142                         const boost::optional<unsigned char> &lineCap);
00143   void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00144                         const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00145                         const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00146                         const boost::optional<Colour> &shfgc, const boost::optional<double> &shadowOffsetX, const boost::optional<double> &shadowOffsetY);
00147   void collectFillStyle(unsigned level, const boost::optional<Colour> &colourFG, const boost::optional<Colour> &colourBG,
00148                         const boost::optional<unsigned char> &fillPattern, const boost::optional<double> &fillFGTransparency,
00149                         const boost::optional<double> &fillBGTransparency, const boost::optional<unsigned char> &shadowPattern,
00150                         const boost::optional<Colour> &shfgc);
00151   void collectCharIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<VSDName> &font,
00152                           const boost::optional<Colour> &fontColour, const boost::optional<double> &fontSize, const boost::optional<bool> &bold,
00153                           const boost::optional<bool> &italic, const boost::optional<bool> &underline, const boost::optional<bool> &doubleunderline,
00154                           const boost::optional<bool> &strikeout, const boost::optional<bool> &doublestrikeout, const boost::optional<bool> &allcaps,
00155                           const boost::optional<bool> &initcaps, const boost::optional<bool> &smallcaps, const boost::optional<bool> &superscript,
00156                           const boost::optional<bool> &subscript);
00157   void collectParaIXStyle(unsigned id, unsigned level, unsigned charCount, const boost::optional<double> &indFirst,
00158                           const boost::optional<double> &indLeft, const boost::optional<double> &indRight, const boost::optional<double> &spLine,
00159                           const boost::optional<double> &spBefore, const boost::optional<double> &spAfter, const boost::optional<unsigned char> &align,
00160                           const boost::optional<unsigned> &flags);
00161   void collectTextBlockStyle(unsigned level, const boost::optional<double> &leftMargin, const boost::optional<double> &rightMargin,
00162                              const boost::optional<double> &topMargin, const boost::optional<double> &bottomMargin,
00163                              const boost::optional<unsigned char> &verticalAlign, const boost::optional<bool> &isBgFilled,
00164                              const boost::optional<Colour> &bgColour, const boost::optional<double> &defaultTabStop,
00165                              const boost::optional<unsigned char> &textDirection);
00166 
00167   // Field list
00168   void collectFieldList(unsigned id, unsigned level);
00169   void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId);
00170   void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
00171 
00172   // Temporary hack
00173   void startPage(unsigned pageID);
00174   void endPage();
00175   void endPages() {}
00176 
00177   const VSDStyles &getStyleSheets() const
00178   {
00179     return m_styles;
00180   }
00181 
00182 
00183 private:
00184   VSDStylesCollector(const VSDStylesCollector &);
00185   VSDStylesCollector &operator=(const VSDStylesCollector &);
00186 
00187   void _handleLevelChange(unsigned level);
00188   void _flushShapeList();
00189 
00190   unsigned m_currentLevel;
00191   bool m_isShapeStarted;
00192 
00193   double m_shadowOffsetX;
00194   double m_shadowOffsetY;
00195 
00196   unsigned m_currentShapeId;
00197   std::map<unsigned, XForm> m_groupXForms;
00198   std::map<unsigned, unsigned> m_groupMemberships;
00199   std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
00200   std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
00201   std::list<unsigned> m_pageShapeOrder;
00202   std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
00203   std::map<unsigned, std::list<unsigned> > m_groupShapeOrder;
00204   std::list<unsigned> m_shapeList;
00205 
00206   unsigned m_currentStyleSheet;
00207   VSDStyles m_styles;
00208 
00209   unsigned m_currentShapeLevel;
00210 };
00211 
00212 }
00213 
00214 #endif /* VSDSTYLESCOLLECTOR_H */
00215 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */