VSDXMLParserBase.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) 2012 Fridrich Strba <fridrich.strba@bluewin.ch>
00017  *
00018  *
00019  * All Rights Reserved.
00020  *
00021  * For minor contributions see the git repository.
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00025  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00026  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00027  * instead of those above.
00028  */
00029 
00030 #ifndef __VSDXMLPARSERBASE_H__
00031 #define __VSDXMLPARSERBASE_H__
00032 
00033 #include <map>
00034 #include <stack>
00035 #include <string>
00036 #include <boost/optional.hpp>
00037 #include "VSDXMLHelper.h"
00038 #include "VSDCharacterList.h"
00039 #include "VSDParagraphList.h"
00040 #include "VSDShapeList.h"
00041 #include "VSDStencils.h"
00042 
00043 namespace libvisio
00044 {
00045 
00046 class VSDCollector;
00047 
00048 class VSDXMLParserBase
00049 {
00050 public:
00051   explicit VSDXMLParserBase();
00052   virtual ~VSDXMLParserBase();
00053   virtual bool parseMain() = 0;
00054   virtual bool extractStencils() = 0;
00055 
00056 protected:
00057   // Protected data
00058   VSDCollector *m_collector;
00059   VSDStencils m_stencils;
00060   VSDStencil *m_currentStencil;
00061   VSDShape m_shape;
00062   bool m_isStencilStarted;
00063   unsigned m_currentStencilID;
00064 
00065   bool m_extractStencils;
00066   bool m_isInStyles;
00067   unsigned m_currentLevel;
00068   unsigned m_currentShapeLevel;
00069   std::map<unsigned, Colour> m_colours;
00070   VSDFieldList m_fieldList;
00071   VSDShapeList m_shapeList;
00072   WPXBinaryData m_currentBinaryData;
00073   std::stack<VSDShape> m_shapeStack;
00074   std::stack<unsigned> m_shapeLevelStack;
00075   bool m_isShapeStarted;
00076   bool m_isPageStarted;
00077   VSDGeometryList *m_currentGeometryList;
00078   unsigned m_currentGeometryListIndex;
00079 
00080   std::map<unsigned, VSDName> m_fonts;
00081 
00082   // Helper functions
00083 
00084   int readByteData(unsigned char &value, xmlTextReaderPtr reader);
00085   int readByteData(boost::optional<unsigned char> &value, xmlTextReaderPtr reader);
00086   int readUnsignedData(boost::optional<unsigned> &value, xmlTextReaderPtr reader);
00087   int readLongData(boost::optional<long> &value, xmlTextReaderPtr reader);
00088   int readLongData(long &value, xmlTextReaderPtr reader);
00089   int readDoubleData(boost::optional<double> &value, xmlTextReaderPtr reader);
00090   int readDoubleData(double &value, xmlTextReaderPtr reader);
00091   int readBoolData(boost::optional<bool> &value, xmlTextReaderPtr reader);
00092   int readBoolData(bool &value, xmlTextReaderPtr reader);
00093   int readColourData(Colour &value, xmlTextReaderPtr reader);
00094   int readExtendedColourData(Colour &value, long &idx, xmlTextReaderPtr reader);
00095   int readExtendedColourData(Colour &value, xmlTextReaderPtr reader);
00096   int readExtendedColourData(boost::optional<Colour> &value, xmlTextReaderPtr reader);
00097   int readNURBSData(boost::optional<NURBSData> &data, xmlTextReaderPtr reader);
00098   int readPolylineData(boost::optional<PolylineData> &data, xmlTextReaderPtr reader);
00099 
00100   virtual xmlChar *readStringData(xmlTextReaderPtr reader) = 0;
00101   unsigned getIX(xmlTextReaderPtr reader);
00102   virtual void _handleLevelChange(unsigned level);
00103   void _flushShape();
00104 
00105   virtual int getElementToken(xmlTextReaderPtr reader) = 0;
00106   virtual int getElementDepth(xmlTextReaderPtr reader) = 0;
00107 
00108   // Functions reading the DiagramML document content
00109 
00110   void readEllipticalArcTo(xmlTextReaderPtr reader);
00111   void readEllipse(xmlTextReaderPtr reader);
00112   void readGeometry(xmlTextReaderPtr reader);
00113   void readMoveTo(xmlTextReaderPtr reader);
00114   void readLineTo(xmlTextReaderPtr reader);
00115   void readArcTo(xmlTextReaderPtr reader);
00116   void readNURBSTo(xmlTextReaderPtr reader);
00117   void readPolylineTo(xmlTextReaderPtr reader);
00118   void readInfiniteLine(xmlTextReaderPtr reader);
00119   void readRelCubBezTo(xmlTextReaderPtr reader);
00120   void readRelEllipticalArcTo(xmlTextReaderPtr reader);
00121   void readRelLineTo(xmlTextReaderPtr reader);
00122   void readRelMoveTo(xmlTextReaderPtr reader);
00123   void readRelQuadBezTo(xmlTextReaderPtr reader);
00124   void readForeignData(xmlTextReaderPtr reader);
00125   virtual void getBinaryData(xmlTextReaderPtr reader) = 0;
00126   void readShape(xmlTextReaderPtr reader);
00127   void readColours(xmlTextReaderPtr reader);
00128   void readPage(xmlTextReaderPtr reader);
00129   void readText(xmlTextReaderPtr reader);
00130   void readCharIX(xmlTextReaderPtr reader);
00131   void readParaIX(xmlTextReaderPtr reader);
00132 
00133   void readStyleSheet(xmlTextReaderPtr reader);
00134   void readPageSheet(xmlTextReaderPtr reader);
00135 
00136   void readSplineStart(xmlTextReaderPtr reader);
00137   void readSplineKnot(xmlTextReaderPtr reader);
00138 
00139   void readStencil(xmlTextReaderPtr reader);
00140 
00141   void handlePagesStart(xmlTextReaderPtr reader);
00142   void handlePagesEnd(xmlTextReaderPtr reader);
00143   void handlePageStart(xmlTextReaderPtr reader);
00144   void handlePageEnd(xmlTextReaderPtr reader);
00145   void handleMastersStart(xmlTextReaderPtr reader);
00146   void handleMastersEnd(xmlTextReaderPtr reader);
00147   void handleMasterStart(xmlTextReaderPtr reader);
00148   void handleMasterEnd(xmlTextReaderPtr reader);
00149   void skipPages(xmlTextReaderPtr reader);
00150   void skipMasters(xmlTextReaderPtr reader);
00151 
00152 private:
00153   VSDXMLParserBase(const VSDXMLParserBase &);
00154   VSDXMLParserBase &operator=(const VSDXMLParserBase &);
00155 
00156   void initColours();
00157 };
00158 
00159 } // namespace libvisio
00160 
00161 #endif // __VSDXMLPARSERBASE_H__
00162 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */