LRFParser.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libe-book
00003  * Version: MPL 2.0 / LGPLv2.1+
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Alternatively, the contents of this file may be used under the terms
00010  * of the GNU Lesser General Public License Version 2.1 or later
00011  * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
00012  * applicable instead of those above.
00013  *
00014  * For further information visit http://libebook.sourceforge.net
00015  */
00016 
00017 #ifndef LRFPARSER_H_INCLUDED
00018 #define LRFPARSER_H_INCLUDED
00019 
00020 #include <map>
00021 
00022 #include "LRFCollector.h"
00023 
00024 class WPXDocumentInterface;
00025 class WPXInputStream;
00026 
00027 namespace libebook
00028 {
00029 
00030 struct LRFHeader;
00031 
00032 class LRFParser
00033 {
00034   // disable copying
00035   LRFParser(const LRFParser &other);
00036   LRFParser &operator=(const LRFParser &other);
00037 
00038   enum ObjectType
00039   {
00040     OBJECT_TYPE_UNSPECIFIED = 0x0,
00041     OBJECT_TYPE_PAGE_TREE = 0x1,
00042     OBJECT_TYPE_PAGE = 0x2,
00043     OBJECT_TYPE_HEADER = 0x3,
00044     OBJECT_TYPE_FOOTER = 0x4,
00045     OBJECT_TYPE_PAGE_ATR = 0x5,
00046     OBJECT_TYPE_BLOCK = 0x6,
00047     OBJECT_TYPE_BLOCK_ATR = 0x7,
00048     OBJECT_TYPE_MINI_PAGE = 0x8,
00049     OBJECT_TYPE_BLOCK_LIST = 0x9,
00050     OBJECT_TYPE_TEXT = 0xa,
00051     OBJECT_TYPE_TEXT_ATR = 0xb,
00052     OBJECT_TYPE_IMAGE = 0xc,
00053     OBJECT_TYPE_CANVAS = 0xd,
00054     OBJECT_TYPE_PARAGRAPH_ATR = 0xe,
00055     OBJECT_TYPE_IMAGE_STREAM = 0x11,
00056     OBJECT_TYPE_IMPORT = 0x12,
00057     OBJECT_TYPE_BUTTON = 0x13,
00058     OBJECT_TYPE_WINDOW = 0x14,
00059     OBJECT_TYPE_POP_UP_WIN = 0x15,
00060     OBJECT_TYPE_SOUND = 0x16,
00061     OBJECT_TYPE_PLANE_STREAM = 0x17,
00062     OBJECT_TYPE_FONT = 0x19,
00063     OBJECT_TYPE_OBJECT_INFO = 0x1a,
00064     OBJECT_TYPE_BOOK_ATR = 0x1c,
00065     OBJECT_TYPE_SIMPLE_TEXT = 0x1d,
00066     OBJECT_TYPE_TOC = 0x1e
00067   };
00068 
00069   struct LRFIndexEntry
00070   {
00071     unsigned offset;
00072     unsigned size;
00073     bool reading;
00074     bool read;
00075   };
00076 
00077   typedef std::map<unsigned, LRFIndexEntry> ObjectIndex_t;
00078 
00079 public:
00080   LRFParser(WPXInputStream *input, WPXDocumentInterface *document);
00081   ~LRFParser();
00082 
00083   bool parse();
00084 
00085   static bool isSupported(WPXInputStream *input);
00086 
00087 private:
00088   void readHeader();
00089   void readMetadata();
00090   void readThumbnail();
00091   void readObjectIndex();
00092 
00093   void readObject(unsigned id, unsigned type = OBJECT_TYPE_UNSPECIFIED);
00094 
00095   void readPageTreeObject(WPXInputStream *object);
00096   void readPageObject(WPXInputStream *object);
00097   void readFooterObject(WPXInputStream *object);
00098   void readHeaderObject(WPXInputStream *object);
00099   void readPageAtrObject(WPXInputStream *object, unsigned id);
00100   void readBlockObject(WPXInputStream *object);
00101   void readBlockAtrObject(WPXInputStream *object, unsigned id);
00102   void readMiniPageObject(WPXInputStream *object);
00103   void readBlockListObject(WPXInputStream *object);
00104   void readTextObject(WPXInputStream *object);
00105   void readTextAtrObject(WPXInputStream *object, unsigned id);
00106   void readImageObject(WPXInputStream *object);
00107   void readCanvasObject(WPXInputStream *object);
00108   void readParagraphAtrObject(WPXInputStream *object, unsigned id);
00109   void readImageStreamObject(WPXInputStream *object, unsigned id);
00110   void readImportObject(WPXInputStream *object);
00111   void readButtonObject(WPXInputStream *object);
00112   void readWindowObject(WPXInputStream *object);
00113   void readPopUpWinObject(WPXInputStream *object);
00114   void readSoundObject(WPXInputStream *object);
00115   void readPlaneStreamObject(WPXInputStream *object);
00116   void readFontObject(WPXInputStream *object);
00117   void readObjectInfoObject(WPXInputStream *object);
00118   void readBookAtrObject(WPXInputStream *object);
00119   void readSimpleTextObject(WPXInputStream *object);
00120   void readTOCObject(WPXInputStream *object);
00121 
00122   bool readAttribute(unsigned tag, WPXInputStream *input, LRFAttributes &attributes);
00123 
00124   void skipUnhandledTag(unsigned tag, WPXInputStream *input, const char *objectType);
00125 
00126   bool isObjectRead(unsigned id) const;
00127 
00128 private:
00129   LRFCollector m_collector;
00130   WPXInputStream *m_input;
00131   LRFHeader *m_header;
00132   ObjectIndex_t m_objectIndex;
00133   unsigned m_pageTree;
00134 };
00135 
00136 } // namespace libebook
00137 
00138 #endif // LRFPARSER_H_INCLUDED
00139 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */