IWORKCollector.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 libetonyek 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 IWORKCOLLECTOR_H_INCLUDED
00011 #define IWORKCOLLECTOR_H_INCLUDED
00012 
00013 #include <deque>
00014 #include <stack>
00015 #include <string>
00016 
00017 #include <boost/optional.hpp>
00018 #include <boost/shared_ptr.hpp>
00019 
00020 #include "libetonyek_utils.h"
00021 #include "IWORKPath_fwd.h"
00022 #include "IWORKShape.h"
00023 #include "IWORKStyle.h"
00024 #include "IWORKStyleStack.h"
00025 #include "IWORKStylesheet.h"
00026 #include "IWORKTransformation.h"
00027 #include "IWORKTypes.h"
00028 #include "IWORKOutputManager.h"
00029 
00030 namespace libetonyek
00031 {
00032 
00033 class IWORKDocumentInterface;
00034 class IWORKLanguageManager;
00035 class IWORKPropertyMap;
00036 class IWORKRecorder;
00037 class IWORKTable;
00038 class IWORKText;
00039 struct IWORKSize;
00040 
00041 class IWORKCollector
00042 {
00043 private:
00044   struct Level
00045   {
00046     IWORKGeometryPtr_t m_geometry;
00047     IWORKStylePtr_t m_graphicStyle;
00048     glm::dmat3 m_trafo;
00049 
00050     Level();
00051   };
00052 
00053 public:
00054   explicit IWORKCollector(IWORKDocumentInterface *document);
00055   ~IWORKCollector();
00056 
00057   void setRecorder(const boost::shared_ptr<IWORKRecorder> &recorder);
00058 
00059   // collector functions
00060 
00061   void collectStyle(const IWORKStylePtr_t &style);
00062 
00063   void setGraphicStyle(const IWORKStylePtr_t &style);
00064 
00065   void collectGeometry(const IWORKGeometryPtr_t &geometry);
00066 
00067   void collectBezier(const IWORKPathPtr_t &path);
00068   void collectImage(const IWORKImagePtr_t &image);
00069   void collectLine(const IWORKLinePtr_t &line);
00070   void collectShape();
00071 
00072   void collectBezierPath();
00073   void collectPolygonPath(const IWORKSize &size, unsigned edges);
00074   void collectRoundedRectanglePath(const IWORKSize &size, double radius);
00075   void collectArrowPath(const IWORKSize &size, double headWidth, double stemRelYPos, bool doubleSided);
00076   void collectStarPath(const IWORKSize &size, unsigned points, double innerRadius);
00077   void collectConnectionPath(const IWORKSize &size, double middleX, double middleY);
00078   void collectCalloutPath(const IWORKSize &size, double radius, double tailSize, double tailX, double tailY, bool quoteBubble);
00079 
00080   void collectMedia(const IWORKMediaContentPtr_t &content);
00081 
00082   void collectStylesheet(const IWORKStylesheetPtr_t &stylesheet);
00083 
00084   void collectMetadata(const IWORKMetadata &metadata);
00085 
00086   void collectHeader(const std::string &name);
00087   void collectFooter(const std::string &name);
00088 
00089   void collectTable(const boost::shared_ptr<IWORKTable> &table);
00090   void collectText(const boost::shared_ptr<IWORKText> &text);
00091 
00092   void startDocument();
00093   void endDocument();
00094 
00095   void startGroup();
00096   void endGroup();
00097 
00098   void startLevel();
00099   void endLevel();
00100 
00101   void pushStyle();
00102   void popStyle();
00103 
00104   void pushStylesheet(const IWORKStylesheetPtr_t &stylesheet);
00105   void popStylesheet();
00106 
00107   IWORKOutputManager &getOutputManager();
00108 
00109 public:
00110   virtual boost::shared_ptr<IWORKTable> createTable(const IWORKTableNameMapPtr_t &tableNameMap) const;
00111   virtual boost::shared_ptr<IWORKText> createText(const IWORKLanguageManager &langManager, bool discardEmptyContent = false) const;
00112 
00113 protected:
00114   void fillMetadata(librevenge::RVNGPropertyList &props);
00115 
00116   static void writeFill(const IWORKFill &fill, librevenge::RVNGPropertyList &props);
00117 
00118 private:
00119   void pushStyle(const IWORKStylePtr_t &style);
00120   void resolveStyle(IWORKStyle &style);
00121 
00122   void collectHeaderFooter(const std::string &name, IWORKHeaderFooterMap_t &map);
00123 
00124   void drawMedia(const IWORKMediaPtr_t &media);
00125   void drawShape(const IWORKShapePtr_t &shape);
00126 
00127   virtual void drawTable() = 0;
00128   virtual void drawMedia(double x, double y, double w, double h, const std::string &mimetype, const librevenge::RVNGBinaryData &data) = 0;
00129   virtual void fillShapeProperties(librevenge::RVNGPropertyList &props) = 0;
00130   virtual void drawTextBox(const IWORKTextPtr_t &text, const glm::dmat3 &trafo, const IWORKGeometryPtr_t &boundingBox) = 0;
00131 
00132 protected:
00133   IWORKDocumentInterface *m_document;
00134   boost::shared_ptr<IWORKRecorder> m_recorder;
00135 
00136   std::stack<Level> m_levelStack;
00137   IWORKStyleStack m_styleStack;
00138   std::stack<IWORKStylesheetPtr_t> m_stylesheetStack;
00139   IWORKOutputManager m_outputManager;
00140 
00141   std::deque<IWORKStylePtr_t> m_newStyles;
00142 
00143   boost::shared_ptr<IWORKTable> m_currentTable;
00144   boost::shared_ptr<IWORKText> m_currentText;
00145 
00146   IWORKHeaderFooterMap_t m_headers;
00147   IWORKHeaderFooterMap_t m_footers;
00148 
00149 private:
00150   IWORKPathPtr_t m_currentPath;
00151   IWORKDataPtr_t m_currentData;
00152   IWORKMediaContentPtr_t m_currentUnfiltered;
00153   IWORKMediaContentPtr_t m_currentFiltered;
00154   IWORKMediaContentPtr_t m_currentLeveled;
00155   IWORKMediaContentPtr_t m_currentContent;
00156 
00157   IWORKMetadata m_metadata;
00158 
00159   int m_groupLevel;
00160 };
00161 
00162 } // namespace libetonyek
00163 
00164 #endif // IWORKCOLLECTOR_H_INCLUDED
00165 
00166 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */