ZMF4Parser.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 a part of the libzmf 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 ZMF4PARSER_H_INCLUDED
00011 #define ZMF4PARSER_H_INCLUDED
00012 
00013 #include <librevenge/librevenge.h>
00014 #include "libzmf_utils.h"
00015 #include "ZMF4Header.h"
00016 #include "ZMFCollector.h"
00017 #include "ZMFTypes.h"
00018 #include <functional>
00019 #include <vector>
00020 #include <map>
00021 #include <boost/optional.hpp>
00022 
00023 namespace libzmf
00024 {
00025 
00026 class ZMF4Parser
00027 {
00028   // disable copying
00029   ZMF4Parser(const ZMF4Parser &other);
00030   ZMF4Parser &operator=(const ZMF4Parser &other);
00031 
00032 public:
00033   ZMF4Parser(const RVNGInputStreamPtr &input, librevenge::RVNGDrawingInterface *painter);
00034   bool parse();
00035 
00036 private:
00037   enum class ObjectType
00038   {
00039     UNKNOWN,
00040     FILL,
00041     TRANSPARENCY,
00042     PEN,
00043     SHADOW,
00044     ARROW,
00045     FONT,
00046     PARAGRAPH,
00047     TEXT,
00048     BITMAP,
00049     PAGE_START,
00050     GUIDELINES,
00051     PAGE_END,
00052     LAYER_START,
00053     LAYER_END,
00054     DOCUMENT_SETTINGS,
00055     COLOR_PALETTE,
00056     RECTANGLE,
00057     ELLIPSE,
00058     POLYGON,
00059     CURVE,
00060     IMAGE,
00061     TEXT_FRAME,
00062     TABLE,
00063     GROUP_START,
00064     GROUP_END
00065   };
00066 
00067   struct ObjectHeader
00068   {
00069     ObjectType type;
00070     uint32_t size;
00071     uint32_t nextObjectOffset;
00072     boost::optional<uint32_t> id;
00073     uint32_t refObjCount;
00074     uint32_t refListStartOffset;
00075 
00076     ObjectHeader()
00077       : type()
00078       , size(0)
00079       , nextObjectOffset(0)
00080       , id()
00081       , refObjCount(0)
00082       , refListStartOffset(0)
00083     { }
00084   };
00085 
00086   struct ObjectRef
00087   {
00088     uint32_t id;
00089     uint32_t tag;
00090   };
00091 
00092   static ObjectType parseObjectType(uint8_t type);
00093 
00094   ObjectHeader readObjectHeader();
00095 
00096   std::vector<ObjectRef> readObjectRefs();
00097 
00098   boost::optional<Fill> getFillByRefId(uint32_t id);
00099   boost::optional<Pen> getPenByRefId(uint32_t id);
00100   boost::optional<Shadow> getShadowByRefId(uint32_t id);
00101   boost::optional<Transparency> getTransparencyByRefId(uint32_t id);
00102   boost::optional<Font> getFontByRefId(uint32_t id);
00103   boost::optional<ParagraphStyle> getParagraphStyleByRefId(uint32_t id);
00104   boost::optional<Text> getTextByRefId(uint32_t id);
00105   boost::optional<Image> getImageByRefId(uint32_t id);
00106   ArrowPtr getArrowByRefId(uint32_t id);
00107 
00108   Style readStyle();
00109 
00110   Point readPoint();
00111   Point readUnscaledPoint();
00112 
00113   BoundingBox readBoundingBox();
00114 
00115   void readCurveSectionTypes(std::vector<CurveType> &sectionTypes);
00116   std::vector<Curve> readCurveComponents(std::function<Point()> readPointFunc);
00117 
00118   Color readColor();
00119   Gradient readGradient(uint32_t type);
00120 
00121   void readPreviewBitmap();
00122 
00123   void readDocumentSettings();
00124   void readPage();
00125   void readLayer(const ObjectHeader &layerStartObjHeader);
00126 
00127   void readPen();
00128   void readFill();
00129   void readTransparency();
00130   void readShadow();
00131 
00132   void readArrow();
00133 
00134   void readBitmap();
00135 
00136   void readImage();
00137 
00138   void readFont();
00139   void readParagraphStyle();
00140   void readText();
00141 
00142   void readTextFrame();
00143 
00144   void readCurve();
00145   void readRectangle();
00146   void readEllipse();
00147   void readPolygon();
00148 
00149   void readTable();
00150 
00151   const RVNGInputStreamPtr m_input;
00152   uint32_t m_inputLength;
00153 
00154   ZMFCollector m_collector;
00155 
00156   ZMF4Header m_header;
00157 
00158   ZMFPageSettings m_pageSettings;
00159 
00160   int m_pageNumber;
00161 
00162   ObjectHeader m_currentObjectHeader;
00163 
00164   std::map<uint32_t, Pen> m_pens;
00165   std::map<uint32_t, Fill> m_fills;
00166   std::map<uint32_t, Transparency> m_transparencies;
00167   std::map<uint32_t, Shadow> m_shadows;
00168   std::map<uint32_t, ArrowPtr> m_arrows;
00169 
00170   std::map<uint32_t, Image> m_images;
00171 
00172   std::map<uint32_t, Font> m_fonts;
00173   std::map<uint32_t, ParagraphStyle> m_paragraphStyles;
00174   std::map<uint32_t, Text> m_texts;
00175 };
00176 
00177 }
00178 
00179 #endif // ZMF4PARSER_H_INCLUDED
00180 
00181 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */