LRFCollector.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libe-book project.
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 
00010 #ifndef LRFCOLLECTOR_H_INCLUDED
00011 #define LRFCOLLECTOR_H_INCLUDED
00012 
00013 #include <string>
00014 #include <stack>
00015 
00016 #include "LRFTypes.h"
00017 
00018 
00019 namespace libebook
00020 {
00021 
00022 class LRFCollector
00023 {
00024   // -Weffc++
00025   LRFCollector(const LRFCollector &other);
00026   LRFCollector &operator=(const LRFCollector &other);
00027 
00028   struct ImageStreamData
00029   {
00030     librevenge::RVNGInputStream *image;
00031     LRFImageType type;
00032   };
00033   typedef std::map<unsigned, ImageStreamData> ImageDataMap_t;
00034 
00035   struct ImageData
00036   {
00037     unsigned dataId;
00038     unsigned width;
00039     unsigned height;
00040   };
00041   typedef std::map<unsigned, ImageData> ImageMap_t;
00042 
00043 public:
00044   explicit LRFCollector(librevenge::RVNGTextInterface *document);
00045   ~LRFCollector();
00046 
00047   void startDocument();
00048   void endDocument();
00049 
00050   void openPage(unsigned pageAtrID, const LRFAttributes &attributes);
00051   void closePage();
00052 
00053   void openBlock(unsigned atrID, const LRFAttributes &attributes);
00054   void closeBlock();
00055 
00056   void openTextBlock(unsigned atrID, const LRFAttributes &attributes);
00057   void closeTextBlock();
00058 
00059   void openParagraph(unsigned atrID, const LRFAttributes &attributes);
00060   void closeParagraph();
00061 
00062   void collectText(const std::string &text, const LRFAttributes &attributes);
00063   void insertLineBreak();
00064 
00065   void insertImage(unsigned id);
00066 
00067   void collectMetadata(const LRFMetadata &metadata);
00068 
00069   void collectBookAttributes(const LRFAttributes &attributes);
00070   void collectTextAttributes(unsigned id, const LRFAttributes &attributes);
00071   void collectBlockAttributes(unsigned id, const LRFAttributes &attributes);
00072   void collectPageAttributes(unsigned id, const LRFAttributes &attributes);
00073   void collectParagraphAttributes(unsigned id, const LRFAttributes &attributes);
00074 
00075   void collectImage(unsigned id, unsigned dataId, unsigned width, unsigned height);
00076   void collectImageData(unsigned id, LRFImageType type, librevenge::RVNGInputStream *image);
00077 
00078   void setDPI(double dpi);
00079 
00080 private:
00081   void collectAttributes(unsigned id, const LRFAttributes &attributes, LRFAttributeMap_t &attributeMap);
00082   void openBlock(unsigned atrID, const LRFAttributes &attributes, const LRFAttributeMap_t *attributeMap);
00083 
00084 private:
00085   LRFAttributes m_bookAttributes;
00086   LRFAttributeMap_t m_textAttributeMap;
00087   LRFAttributeMap_t m_blockAttributeMap;
00088   LRFAttributeMap_t m_pageAttributeMap;
00089   LRFAttributeMap_t m_paragraphAttributeMap;
00090   librevenge::RVNGTextInterface *const m_document;
00091   std::stack<LRFAttributes> m_currentAttributes;
00092   ImageDataMap_t m_imageDataMap;
00093   ImageMap_t m_imageMap;
00094   double m_dpi;
00095   bool m_firstParaInBlock;
00096 };
00097 
00098 }
00099 
00100 #endif // LRFCOLLECTOR_H_INCLUDED
00101 
00102 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */