LRFCollector.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 LRFCOLLECTOR_H_INCLUDED
00018 #define LRFCOLLECTOR_H_INCLUDED
00019 
00020 #include <string>
00021 #include <stack>
00022 
00023 #include "LRFTypes.h"
00024 
00025 class WPXDocumentInterface;
00026 
00027 namespace libebook
00028 {
00029 
00030 class LRFCollector
00031 {
00032   // -Weffc++
00033   LRFCollector(const LRFCollector &other);
00034   LRFCollector &operator=(const LRFCollector &other);
00035 
00036   struct ImageData
00037   {
00038     WPXInputStream *image;
00039     ImageType type;
00040   };
00041 
00042   typedef std::map<unsigned, ImageData> ImageMap_t;
00043 
00044 public:
00045   explicit LRFCollector(WPXDocumentInterface *document);
00046   ~LRFCollector();
00047 
00048   void startDocument();
00049   void endDocument();
00050 
00051   void openPage(unsigned pageAtrID, const LRFAttributes &attributes);
00052   void closePage();
00053 
00054   void openBlock(unsigned atrID, const LRFAttributes &attributes);
00055   void closeBlock();
00056 
00057   void openTextBlock(unsigned atrID, const LRFAttributes &attributes);
00058   void closeTextBlock();
00059 
00060   void openParagraph(unsigned atrID, const LRFAttributes &attributes);
00061   void closeParagraph();
00062 
00063   void collectText(const std::string &text, const LRFAttributes &attributes);
00064   void insertLineBreak();
00065 
00066   void collectMetadata(const LRFMetadata &metadata);
00067 
00068   void collectBookAttributes(const LRFAttributes &attributes);
00069   void collectTextAttributes(unsigned id, const LRFAttributes &attributes);
00070   void collectBlockAttributes(unsigned id, const LRFAttributes &attributes);
00071   void collectPageAttributes(unsigned id, const LRFAttributes &attributes);
00072   void collectParagraphAttributes(unsigned id, const LRFAttributes &attributes);
00073 
00074   void collectImage(unsigned id);
00075   void collectImageData(unsigned id, ImageType type, WPXInputStream *image);
00076 
00077 private:
00078   void collectAttributes(unsigned id, const LRFAttributes &attributes, LRFAttributeMap_t &attributeMap);
00079   void openBlock(unsigned atrID, const LRFAttributes &attributes, const LRFAttributeMap_t *attributeMap);
00080 
00081 private:
00082   LRFAttributes m_bookAttributes;
00083   LRFAttributeMap_t m_textAttributeMap;
00084   LRFAttributeMap_t m_blockAttributeMap;
00085   LRFAttributeMap_t m_pageAttributeMap;
00086   LRFAttributeMap_t m_paragraphAttributeMap;
00087   WPXDocumentInterface *const m_document;
00088   std::stack<LRFAttributes> m_currentAttributes;
00089   ImageMap_t m_imageMap;
00090 };
00091 
00092 }
00093 
00094 #endif // LRFCOLLECTOR_H_INCLUDED
00095 
00096 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */