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