1 /************************************************************************* 2 ** BasicDVIReader.h ** 3 ** ** 4 ** This file is part of dvisvgm -- the DVI to SVG converter ** 5 ** Copyright (C) 2005-2015 Martin Gieseking <martin.gieseking@uos.de> ** 6 ** ** 7 ** This program is free software; you can redistribute it and/or ** 8 ** modify it under the terms of the GNU General Public License as ** 9 ** published by the Free Software Foundation; either version 3 of ** 10 ** the License, or (at your option) any later version. ** 11 ** ** 12 ** This program is distributed in the hope that it will be useful, but ** 13 ** WITHOUT ANY WARRANTY; without even the implied warranty of ** 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 15 ** GNU General Public License for more details. ** 16 ** ** 17 ** You should have received a copy of the GNU General Public License ** 18 ** along with this program; if not, see <http://www.gnu.org/licenses/>. ** 19 *************************************************************************/ 20 21 #ifndef DVISVGM_BASICDVIREADER_H 22 #define DVISVGM_BASICDVIREADER_H 23 24 #include "MessageException.h" 25 #include "StreamReader.h" 26 27 struct DVIException : public MessageException 28 { DVIExceptionDVIException29 DVIException (const std::string &msg) : MessageException(msg) {} 30 }; 31 32 33 struct InvalidDVIFileException : public DVIException 34 { InvalidDVIFileExceptionInvalidDVIFileException35 InvalidDVIFileException(const std::string &msg) : DVIException(msg) {} 36 }; 37 38 class Matrix; 39 40 class BasicDVIReader : public StreamReader 41 { 42 protected: 43 typedef void (BasicDVIReader::*CommandHandler)(int); 44 enum DVIFormat {DVI_NONE=0, DVI_STANDARD=2, DVI_PTEX=3, DVI_XDV=5}; 45 46 public: 47 BasicDVIReader (std::istream &is); ~BasicDVIReader()48 virtual ~BasicDVIReader () {} 49 virtual void executeAllPages (); getXPos()50 virtual double getXPos () const {return 0;} getYPos()51 virtual double getYPos () const {return 0;} finishLine()52 virtual void finishLine () {} translateToX(double x)53 virtual void translateToX (double x) {} translateToY(double y)54 virtual void translateToY (double y) {} getStackDepth()55 virtual int getStackDepth () const {return 0;} getPageTransformation(Matrix & matrix)56 virtual void getPageTransformation (Matrix &matrix) const {} getCurrentPageNumber()57 virtual unsigned getCurrentPageNumber () const {return 0;} 58 59 protected: 60 void setDVIFormat (DVIFormat format); getDVIFormat()61 DVIFormat getDVIFormat () const {return _dviFormat;} 62 virtual int evalCommand (CommandHandler &handler, int ¶m); 63 virtual int executeCommand (); 64 void executePostPost (); 65 66 // the following methods represent the DVI commands 67 // they are called by executeCommand and should not be used directly 68 virtual void cmdSetChar0 (int c); 69 virtual void cmdSetChar (int len); 70 virtual void cmdPutChar (int len); 71 virtual void cmdSetRule (int len); 72 virtual void cmdPutRule (int len); 73 virtual void cmdNop (int len); 74 virtual void cmdBop (int len); 75 virtual void cmdEop (int len); 76 virtual void cmdPush (int len); 77 virtual void cmdPop (int len); 78 virtual void cmdDir (int len); 79 virtual void cmdRight (int len); 80 virtual void cmdDown (int len); 81 virtual void cmdX0 (int len); 82 virtual void cmdY0 (int len); 83 virtual void cmdW0 (int len); 84 virtual void cmdZ0 (int len); 85 virtual void cmdX (int len); 86 virtual void cmdY (int len); 87 virtual void cmdW (int len); 88 virtual void cmdZ (int len); 89 virtual void cmdFontDef (int len); 90 virtual void cmdFontNum0 (int n); 91 virtual void cmdFontNum (int len); 92 virtual void cmdXXX (int len); 93 virtual void cmdPre (int len); 94 virtual void cmdPost (int len); 95 virtual void cmdPostPost (int len); 96 virtual void cmdXPic (int len); 97 virtual void cmdXFontDef (int len); 98 virtual void cmdXGlyphA (int len); 99 virtual void cmdXGlyphS (int len); 100 101 private: 102 DVIFormat _dviFormat; ///< format of DVI file being processed 103 }; 104 105 #endif 106