VSDXStylesCollector.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 VSDXSTYLESCOLLECTOR_H
00032 #define VSDXSTYLESCOLLECTOR_H
00033 
00034 #include <map>
00035 #include <vector>
00036 #include <list>
00037 #include "VSDXCollector.h"
00038 #include "VSDXParser.h"
00039 #include "libvisio_utils.h"
00040 #include "VSDXStyles.h"
00041 
00042 namespace libvisio
00043 {
00044 
00045 class VSDXStylesCollector : public VSDXCollector
00046 {
00047 public:
00048   VSDXStylesCollector(
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 ~VSDXStylesCollector() {};
00054 
00055   void collectEllipticalArcTo(unsigned id, unsigned level, double x3, double y3, double x2, double y2, double angle, double ecc);
00056   void collectForeignData(unsigned id, 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 id, unsigned level, double strokeWidth, Colour c, unsigned linePattern, unsigned char startMarker, unsigned char endMarker, unsigned lineCap);
00064   void collectFillAndShadow(unsigned id, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
00065                             unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc,
00066                             double shadowOffsetX, double shadowOffsetY);
00067   void collectFillAndShadow(unsigned id, unsigned level, unsigned colourIndexFG, unsigned colourIndexBG, unsigned fillPattern,
00068                             unsigned fillFGTransparency, unsigned fillBGTransparency, unsigned shadowPattern, Colour shfgc);
00069   void collectGeometry(unsigned id, unsigned level, unsigned char geomFlags);
00070   void collectMoveTo(unsigned id, unsigned level, double x, double y);
00071   void collectLineTo(unsigned id, unsigned level, double x, double y);
00072   void collectArcTo(unsigned id, unsigned level, double x2, double y2, double bow);
00073   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType,
00074                       unsigned degree, std::vector<std::pair<double, double> > controlPoints,
00075                       std::vector<double> knotVector, std::vector<double> weights);
00076   void collectNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
00077   void collectPolylineTo(unsigned id , unsigned level, double x, double y, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > &points);
00078   void collectPolylineTo(unsigned id , unsigned level, double x, double y, unsigned dataID);
00079   void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, unsigned degree, double lastKnot,
00080                         std::vector<std::pair<double, double> > controlPoints, std::vector<double> knotVector, std::vector<double> weights);
00081   void collectShapeData(unsigned id, unsigned level, unsigned char xType, unsigned char yType, std::vector<std::pair<double, double> > points);
00082   void collectXFormData(unsigned id, unsigned level, const XForm &xform);
00083   void collectTxtXForm(unsigned id, unsigned level, const XForm &txtxform);
00084   void collectShapeId(unsigned id, unsigned level, unsigned shapeId);
00085   void collectForeignDataType(unsigned id, unsigned level, unsigned foreignType, unsigned foreignFormat, double offsetX, double offsetY, double width, double height);
00086   void collectPageProps(unsigned id, unsigned level, double pageWidth, double pageHeight, double shadowOffsetX, double shadowOffsetY, double scale);
00087   void collectPage(unsigned id, unsigned level, unsigned backgroundPageID, unsigned currentPageID);
00088   void collectShape(unsigned id, unsigned level, unsigned masterPage, unsigned masterShape, unsigned lineStyle, unsigned fillStyle, unsigned textStyle);
00089   void collectSplineStart(unsigned id, unsigned level, double x, double y, double secondKnot, double firstKnot, double lastKnot, unsigned degree);
00090   void collectSplineKnot(unsigned id, unsigned level, double x, double y, double knot);
00091   void collectSplineEnd();
00092   void collectInfiniteLine(unsigned id, unsigned level, double x1, double y1, double x2, double y2);
00093   void collectUnhandledChunk(unsigned id, unsigned level);
00094 
00095   void collectColours(const std::vector<Colour> &colours);
00096   void collectFont(unsigned short fontID, const ::WPXBinaryData &textStream, TextFormat format);
00097 
00098   void collectText(unsigned id, unsigned level, const ::WPXBinaryData &textStream, TextFormat format);
00099   void collectVSDXCharStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
00100                             double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
00101                             bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
00102   void collectVSDXParaStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
00103                             double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
00104   void collectTextBlock(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
00105                         unsigned char bgClrId, const Colour &bgColour, double defaultTabStop, unsigned char textDirection);
00106   void collectNameList(unsigned id, unsigned level)
00107   {
00108     collectUnhandledChunk(id, level);
00109   }
00110   void collectName(unsigned id, unsigned level,  const ::WPXBinaryData &name, TextFormat format);
00111 
00112   // Style collectors
00113   void collectStyleSheet(unsigned id, unsigned level, unsigned parentLineStyle, unsigned parentFillStyle, unsigned parentTextStyle);
00114   void collectLineStyle(unsigned id, unsigned level, double strokeWidth, Colour c, unsigned char linePattern, unsigned char startMarker, unsigned char endMarker, unsigned char lineCap);
00115   void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
00116                         unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc,
00117                         double shadowOffsetX, double shadowOffsetY);
00118   void collectFillStyle(unsigned id, unsigned level, unsigned char colourIndexFG, unsigned char colourIndexBG, unsigned char fillPattern,
00119                         unsigned char fillFGTransparency, unsigned char fillBGTransparency, unsigned char shadowPattern, Colour shfgc);
00120   void collectCharIXStyle(unsigned id , unsigned level, unsigned charCount, unsigned short fontID, Colour fontColour, unsigned langId,
00121                           double fontSize, bool bold, bool italic, bool underline, bool doubleunderline, bool strikeout, bool doublestrikeout,
00122                           bool allcaps, bool initcaps, bool smallcaps, bool superscript, bool subscript, WPXString fontFace);
00123   void collectParaIXStyle(unsigned id , unsigned level, unsigned charCount, double indFirst, double indLeft, double indRight,
00124                           double spLine, double spBefore, double spAfter, unsigned char align, unsigned flags);
00125   void collectTextBlockStyle(unsigned id, unsigned level, double leftMargin, double rightMargin, double topMargin, double bottomMargin, unsigned char verticalAlign,
00126                              unsigned char bgClrId, const Colour &bgColour, double defaultTabStop, unsigned char textDirection);
00127 
00128   // Field list
00129   void collectFieldList(unsigned id, unsigned level);
00130   void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId);
00131   void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId);
00132 
00133   // Temporary hack
00134   void startPage();
00135   void endPage();
00136   void endPages() {}
00137 
00138   VSDXStyles getStyleSheets() const
00139   {
00140     return m_styles;
00141   }
00142 
00143 
00144 private:
00145   VSDXStylesCollector(const VSDXStylesCollector &);
00146   VSDXStylesCollector &operator=(const VSDXStylesCollector &);
00147 
00148   void _handleLevelChange(unsigned level);
00149   void _flushShapeList();
00150 
00151   unsigned m_currentLevel;
00152   bool m_isShapeStarted;
00153 
00154   double m_shadowOffsetX;
00155   double m_shadowOffsetY;
00156 
00157   unsigned m_currentShapeId;
00158   std::map<unsigned, XForm> m_groupXForms;
00159   std::map<unsigned, unsigned> m_groupMemberships;
00160   std::vector<std::map<unsigned, XForm> > &m_groupXFormsSequence;
00161   std::vector<std::map<unsigned, unsigned> > &m_groupMembershipsSequence;
00162   std::list<unsigned> m_pageShapeOrder;
00163   std::vector<std::list<unsigned> > &m_documentPageShapeOrders;
00164   std::map<unsigned, std::list<unsigned> > m_groupShapeOrder;
00165   std::list<unsigned> m_shapeList;
00166 
00167   unsigned m_currentStyleSheet;
00168   VSDXStyles m_styles;
00169   VSDXLineStyle *m_lineStyle;
00170   VSDXFillStyle *m_fillStyle;
00171   VSDXTextBlockStyle *m_textBlockStyle;
00172   VSDXCharStyle *m_charStyle;
00173   VSDXParaStyle *m_paraStyle;
00174 
00175   unsigned m_lineStyleMaster;
00176   unsigned m_fillStyleMaster;
00177   unsigned m_textStyleMaster;
00178   bool m_isStyleStarted;
00179 };
00180 
00181 }
00182 
00183 #endif /* VSDXSTYLESCOLLECTOR_H */
00184 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */