VSDParser.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 __VSDPARSER_H__
00032 #define __VSDPARSER_H__
00033 
00034 #include <stdio.h>
00035 #include <iostream>
00036 #include <vector>
00037 #include <stack>
00038 #include <map>
00039 #include <libwpd/libwpd.h>
00040 #include <libwpd-stream/libwpd-stream.h>
00041 #include <libwpg/libwpg.h>
00042 #include "VSDTypes.h"
00043 #include "VSDGeometryList.h"
00044 #include "VSDFieldList.h"
00045 #include "VSDCharacterList.h"
00046 #include "VSDParagraphList.h"
00047 #include "VSDShapeList.h"
00048 #include "VSDStencils.h"
00049 
00050 namespace libvisio
00051 {
00052 
00053 class VSDCollector;
00054 
00055 struct Pointer
00056 {
00057   Pointer()
00058     : Type(0), Offset(0), Length(0), Format(0), ListSize(0) {}
00059   Pointer(const Pointer &ptr)
00060     : Type(ptr.Type), Offset(ptr.Offset), Length(ptr.Length), Format(ptr.Format), ListSize(ptr.ListSize) {}
00061   unsigned Type;
00062   unsigned Offset;
00063   unsigned Length;
00064   unsigned short Format;
00065   unsigned ListSize;
00066 };
00067 
00068 class VSDParser
00069 {
00070 public:
00071   explicit VSDParser(WPXInputStream *input, libwpg::WPGPaintInterface *painter);
00072   virtual ~VSDParser();
00073   bool parseMain();
00074   bool extractStencils();
00075 
00076 protected:
00077   // reader functions
00078   void readEllipticalArcTo(WPXInputStream *input);
00079   void readForeignData(WPXInputStream *input);
00080   void readEllipse(WPXInputStream *input);
00081   virtual void readLine(WPXInputStream *input);
00082   virtual void readFillAndShadow(WPXInputStream *input);
00083   virtual void readGeomList(WPXInputStream *input);
00084   void readGeometry(WPXInputStream *input);
00085   void readMoveTo(WPXInputStream *input);
00086   void readLineTo(WPXInputStream *input);
00087   void readArcTo(WPXInputStream *input);
00088   void readNURBSTo(WPXInputStream *input);
00089   void readPolylineTo(WPXInputStream *input);
00090   void readInfiniteLine(WPXInputStream *input);
00091   void readShapeData(WPXInputStream *input);
00092   void readXFormData(WPXInputStream *input);
00093   void readTxtXForm(WPXInputStream *input);
00094   void readShapeId(WPXInputStream *input);
00095   virtual void readShapeList(WPXInputStream *input);
00096   void readForeignDataType(WPXInputStream *input);
00097   void readPageProps(WPXInputStream *input);
00098   virtual void readShape(WPXInputStream *input);
00099   void readColours(WPXInputStream *input);
00100   void readFont(WPXInputStream *input);
00101   void readFontIX(WPXInputStream *input);
00102   virtual void readCharList(WPXInputStream *input);
00103   virtual void readParaList(WPXInputStream *input);
00104   virtual void readPropList(WPXInputStream *input);
00105   virtual void readPage(WPXInputStream *input);
00106   virtual void readText(WPXInputStream *input);
00107   virtual void readCharIX(WPXInputStream *input);
00108   virtual void readParaIX(WPXInputStream *input);
00109   virtual void readTextBlock(WPXInputStream *input);
00110 
00111   void readNameList(WPXInputStream *input);
00112   virtual void readName(WPXInputStream *input);
00113 
00114   virtual void readNameList2(WPXInputStream *input);
00115   virtual void readName2(WPXInputStream *input);
00116 
00117   virtual void readFieldList(WPXInputStream *input);
00118   virtual void readTextField(WPXInputStream *input);
00119 
00120   virtual void readStyleSheet(WPXInputStream *input);
00121   void readPageSheet(WPXInputStream *input);
00122 
00123   void readSplineStart(WPXInputStream *input);
00124   void readSplineKnot(WPXInputStream *input);
00125 
00126   void readStencilShape(WPXInputStream *input);
00127 
00128   void readOLEList(WPXInputStream *input);
00129   void readOLEData(WPXInputStream *input);
00130 
00131   virtual void readNameIDX(WPXInputStream *input);
00132   virtual void readNameIDX123(WPXInputStream *input);
00133 
00134   void readMisc(WPXInputStream *input);
00135 
00136   // parser of one pass
00137   bool parseDocument(WPXInputStream *input, unsigned shift);
00138 
00139   // Stream handlers
00140   void handleStreams(WPXInputStream *input, unsigned ptrType, unsigned shift, unsigned level);
00141   void handleStream(const Pointer &ptr, unsigned idx, unsigned level);
00142   void handleChunks(WPXInputStream *input, unsigned level);
00143   void handleChunk(WPXInputStream *input);
00144   void handleBlob(WPXInputStream *input, unsigned shift, unsigned level);
00145 
00146   virtual void readPointer(WPXInputStream *input, Pointer &ptr);
00147   virtual void readPointerInfo(WPXInputStream *input, unsigned ptrType, unsigned shift, unsigned &listSize, int &pointerCount);
00148   virtual bool getChunkHeader(WPXInputStream *input);
00149   void _handleLevelChange(unsigned level);
00150   Colour _colourFromIndex(unsigned idx);
00151   void _flushShape();
00152   void _nameFromId(VSDName &name, unsigned id, unsigned level);
00153 
00154   virtual unsigned getUInt(WPXInputStream *input);
00155   virtual int getInt(WPXInputStream *input);
00156 
00157   WPXInputStream *m_input;
00158   libwpg::WPGPaintInterface *m_painter;
00159   ChunkHeader m_header;
00160   VSDCollector *m_collector;
00161   VSDShapeList m_shapeList;
00162   unsigned m_currentLevel;
00163 
00164   VSDStencils m_stencils;
00165   VSDStencil *m_currentStencil;
00166   VSDShape m_shape;
00167   bool m_isStencilStarted;
00168   bool m_isInStyles;
00169   unsigned m_currentShapeLevel;
00170   unsigned m_currentShapeID;
00171 
00172   bool m_extractStencils;
00173   std::vector<Colour> m_colours;
00174 
00175   bool m_isBackgroundPage;
00176   bool m_isShapeStarted;
00177 
00178   double m_shadowOffsetX;
00179   double m_shadowOffsetY;
00180 
00181   VSDGeometryList *m_currentGeometryList;
00182   unsigned m_currentGeomListCount;
00183 
00184   std::map<unsigned, VSDName> m_fonts;
00185   std::map<unsigned, VSDName> m_names;
00186   std::map<unsigned, std::map<unsigned, VSDName> > m_namesMapMap;
00187   VSDName m_currentPageName;
00188 
00189 private:
00190   VSDParser();
00191   VSDParser(const VSDParser &);
00192   VSDParser &operator=(const VSDParser &);
00193 
00194 };
00195 
00196 } // namespace libvisio
00197 
00198 #endif // __VSDPARSER_H__
00199 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */