IWORKCollector.h Source File documentation

IWORKCollector.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libetonyek project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef IWORKCOLLECTOR_H_INCLUDED
11 #define IWORKCOLLECTOR_H_INCLUDED
12
13 #include <deque>
14 #include <memory>
15 #include <stack>
16 #include <string>
17
18 #include <boost/optional.hpp>
19
20 #include "libetonyek_utils.h"
21 #include "IWORKPath_fwd.h"
22 #include "IWORKShape.h"
23 #include "IWORKStyle.h"
24 #include "IWORKStyleStack.h"
25 #include "IWORKStylesheet.h"
26 #include "IWORKTransformation.h"
27 #include "IWORKTypes.h"
28 #include "IWORKOutputManager.h"
29
30 namespace libetonyek
31 {
32
33 class IWORKDocumentInterface;
34 class IWORKLanguageManager;
35 class IWORKPropertyMap;
36 class IWORKRecorder;
37 class IWORKTable;
38 class IWORKText;
39 struct IWORKSize;
40
41 class IWORKCollector
42 {
43 private:
44 struct Level
45 {
46 IWORKGeometryPtr_t m_geometry;
47 IWORKStylePtr_t m_graphicStyle;
48 glm::dmat3 m_trafo;
49
50 Level();
51 };
52
53 public:
54 explicit IWORKCollector(IWORKDocumentInterface *document);
55 ~IWORKCollector();
56
57 void setRecorder(const std::shared_ptr<IWORKRecorder> &recorder);
58
59 // collector functions
60
61 void collectStyle(const IWORKStylePtr_t &style);
62
63 void setGraphicStyle(const IWORKStylePtr_t &style);
64
65 void collectGeometry(const IWORKGeometryPtr_t &geometry);
66
67 void collectBezier(const IWORKPathPtr_t &path);
68 void collectImage(const IWORKImagePtr_t &image);
69 void collectLine(const IWORKLinePtr_t &line);
70 void collectShape();
71
72 void collectBezierPath();
73 void collectPolygonPath(const IWORKSize &size, unsigned edges);
74 void collectRoundedRectanglePath(const IWORKSize &size, double radius);
75 void collectArrowPath(const IWORKSize &size, double headWidth, double stemRelYPos, bool doubleSided);
76 void collectStarPath(const IWORKSize &size, unsigned points, double innerRadius);
77 void collectConnectionPath(const IWORKSize &size, double middleX, double middleY);
78 void collectCalloutPath(const IWORKSize &size, double radius, double tailSize, double tailX, double tailY, bool quoteBubble);
79
80 void collectMedia(const IWORKMediaContentPtr_t &content);
81
82 void collectStylesheet(const IWORKStylesheetPtr_t &stylesheet);
83
84 void collectMetadata(const IWORKMetadata &metadata);
85
86 void collectHeader(const std::string &name);
87 void collectFooter(const std::string &name);
88
89 void collectTable(const std::shared_ptr<IWORKTable> &table);
90 void collectText(const std::shared_ptr<IWORKText> &text);
91
92 void startDocument();
93 void endDocument();
94
95 void startGroup();
96 void endGroup();
97
98 void startLevel();
99 void endLevel();
100
101 void pushStyle();
102 void popStyle();
103
104 void pushStylesheet(const IWORKStylesheetPtr_t &stylesheet);
105 void popStylesheet();
106 IWORKStylesheetPtr_t getStylesheet() const
107 {
108 if (m_stylesheetStack.empty())
109 return IWORKStylesheetPtr_t();
110 return m_stylesheetStack.top();
111 }
112 IWORKOutputManager &getOutputManager();
113
114 public:
115 virtual std::shared_ptr<IWORKTable> createTable(const IWORKTableNameMapPtr_t &tableNameMap, const IWORKLanguageManager &langManager) const;
116 virtual std::shared_ptr<IWORKText> createText(const IWORKLanguageManager &langManager, bool discardEmptyContent = false) const;
117
118 protected:
119 void fillMetadata(librevenge::RVNGPropertyList &props);
120
121 static void writeFill(const IWORKFill &fill, librevenge::RVNGPropertyList &props);
122
123 private:
124 void pushStyle(const IWORKStylePtr_t &style);
125 void resolveStyle(IWORKStyle &style);
126
127 void collectHeaderFooter(const std::string &name, IWORKHeaderFooterMap_t &map);
128
129 void drawMedia(const IWORKMediaPtr_t &media);
130 void drawShape(const IWORKShapePtr_t &shape);
131
132 virtual void drawTable() = 0;
133 virtual void drawMedia(double x, double y, double w, double h, const std::string &mimetype, const librevenge::RVNGBinaryData &data) = 0;
134 virtual void fillShapeProperties(librevenge::RVNGPropertyList &props) = 0;
135 virtual void drawTextBox(const IWORKTextPtr_t &text, const glm::dmat3 &trafo, const IWORKGeometryPtr_t &boundingBox) = 0;
136
137 protected:
138 IWORKDocumentInterface *m_document;
139 std::shared_ptr<IWORKRecorder> m_recorder;
140
141 std::stack<Level> m_levelStack;
142 IWORKStyleStack m_styleStack;
143 std::stack<IWORKStylesheetPtr_t> m_stylesheetStack;
144 IWORKOutputManager m_outputManager;
145
146 std::deque<IWORKStylePtr_t> m_newStyles;
147
148 std::shared_ptr<IWORKTable> m_currentTable;
149 std::shared_ptr<IWORKText> m_currentText;
150
151 IWORKHeaderFooterMap_t m_headers;
152 IWORKHeaderFooterMap_t m_footers;
153
154 private:
155 IWORKPathPtr_t m_currentPath;
156 IWORKDataPtr_t m_currentData;
157 IWORKMediaContentPtr_t m_currentUnfiltered;
158 IWORKMediaContentPtr_t m_currentFiltered;
159 IWORKMediaContentPtr_t m_currentLeveled;
160 IWORKMediaContentPtr_t m_currentContent;
161
162 IWORKMetadata m_metadata;
163
164 int m_groupLevel;
165 };
166
167 } // namespace libetonyek
168
169 #endif // IWORKCOLLECTOR_H_INCLUDED
170
171 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek::IWORKCollector::createTable
virtual std::shared_ptr< IWORKTable > createTable(const IWORKTableNameMapPtr_t &tableNameMap, const IWORKLanguageManager &langManager) const
Definition: IWORKCollector.cpp:680
libetonyek::IWORKGeometryPtr_t
std::shared_ptr< IWORKGeometry > IWORKGeometryPtr_t
Definition: IWORKTypes_fwd.h:39
libetonyek
Definition: IWORKBezierElement.cpp:18
IWORKTransformation.h
libetonyek::IWORKCollector::m_stylesheetStack
std::stack< IWORKStylesheetPtr_t > m_stylesheetStack
Definition: IWORKCollector.h:143
libetonyek::IWORKCollector::m_currentFiltered
IWORKMediaContentPtr_t m_currentFiltered
Definition: IWORKCollector.h:158
libetonyek::IWORKToken::path
Definition: IWORKToken.h:228
libetonyek::IWORKCollector::collectTable
void collectTable(const std::shared_ptr< IWORKTable > &table)
Definition: IWORKCollector.cpp:614
IWORKOutputManager.h
libetonyek::IWORKCollector::IWORKCollector
IWORKCollector(IWORKDocumentInterface *document)
Definition: IWORKCollector.cpp:354
libetonyek::IWORKToken::stylesheet
Definition: IWORKToken.h:271
libetonyek::IWORKStyle
Represents a hierarchical style.
Definition: IWORKStyle.h:28
libetonyek::IWORKCollector::collectGeometry
void collectGeometry(const IWORKGeometryPtr_t &geometry)
Definition: IWORKCollector.cpp:411
libetonyek::IWORKCollector::m_currentLeveled
IWORKMediaContentPtr_t m_currentLeveled
Definition: IWORKCollector.h:159
libetonyek::IWORKToken::media
Definition: IWORKToken.h:203
y
double y
Definition: IWORKShape.cpp:43
libetonyek::IWORKCollector::createText
virtual std::shared_ptr< IWORKText > createText(const IWORKLanguageManager &langManager, bool discardEmptyContent=false) const
Definition: IWORKCollector.cpp:685
libetonyek::IWORKOutputManager
A manager for output elements.
Definition: IWORKOutputManager.h:29
libetonyek::IWORKToken::line
Definition: IWORKToken.h:187
libetonyek::IWORKCollector::Level::m_graphicStyle
IWORKStylePtr_t m_graphicStyle
Definition: IWORKCollector.h:47
libetonyek::IWORKToken::content
Definition: IWORKToken.h:93
libetonyek::IWORKStyleStack
Representation of a dynamic inheritance of styles.
Definition: IWORKStyleStack.h:34
libetonyek::IWORKCollector::m_currentContent
IWORKMediaContentPtr_t m_currentContent
Definition: IWORKCollector.h:160
libetonyek::IWORKCollector::popStylesheet
void popStylesheet()
Definition: IWORKCollector.cpp:742
libetonyek::IWORKToken::shape
Definition: IWORKToken.h:253
libetonyek::IWORKMediaPtr_t
std::shared_ptr< IWORKMedia > IWORKMediaPtr_t
Definition: IWORKTypes_fwd.h:62
libetonyek::IWORKCollector::drawTextBox
virtual void drawTextBox(const IWORKTextPtr_t &text, const glm::dmat3 &trafo, const IWORKGeometryPtr_t &boundingBox)=0
libetonyek::IWORKCollector::m_recorder
std::shared_ptr< IWORKRecorder > m_recorder
Definition: IWORKCollector.h:139
libetonyek::IWORKStylePtr_t
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
libetonyek::IWORKToken::image
Definition: IWORKToken.h:163
libetonyek::IWORKCollector::collectBezier
void collectBezier(const IWORKPathPtr_t &path)
Definition: IWORKCollector.cpp:425
libetonyek::IWORKCollector::startGroup
void startGroup()
Definition: IWORKCollector.cpp:656
libetonyek::IWORKCollector::collectStarPath
void collectStarPath(const IWORKSize &size, unsigned points, double innerRadius)
Definition: IWORKCollector.cpp:535
libetonyek::IWORKToken::h
Definition: IWORKToken.h:328
libetonyek::IWORKCollector::drawMedia
void drawMedia(const IWORKMediaPtr_t &media)
Definition: IWORKCollector.cpp:793
libetonyek::IWORKCollector::collectStyle
void collectStyle(const IWORKStylePtr_t &style)
Definition: IWORKCollector.cpp:384
libetonyek::IWORKCollector::Level
Definition: IWORKCollector.h:44
libetonyek::IWORKSize
Definition: IWORKTypes.h:37
libetonyek::IWORKCollector::resolveStyle
void resolveStyle(IWORKStyle &style)
Definition: IWORKCollector.cpp:755
libetonyek::IWORKToken::text
Definition: IWORKToken.h:284
libetonyek::IWORKCollector::popStyle
void popStyle()
Definition: IWORKCollector.cpp:726
libetonyek::IWORKCollector::collectFooter
void collectFooter(const std::string &name)
Definition: IWORKCollector.cpp:609
libetonyek::IWORKCollector::collectHeaderFooter
void collectHeaderFooter(const std::string &name, IWORKHeaderFooterMap_t &map)
Definition: IWORKCollector.cpp:761
libetonyek::IWORKDocumentInterface
Definition: IWORKDocumentInterface.h:18
x
double x
Definition: IWORKShape.cpp:42
libetonyek::IWORKCollector::drawTable
virtual void drawTable()=0
libetonyek::IWORKCollector::setGraphicStyle
void setGraphicStyle(const IWORKStylePtr_t &style)
Definition: IWORKCollector.cpp:396
libetonyek::IWORKCollector::collectMetadata
void collectMetadata(const IWORKMetadata &metadata)
Definition: IWORKCollector.cpp:599
libetonyek::IWORKCollector::m_headers
IWORKHeaderFooterMap_t m_headers
Definition: IWORKCollector.h:151
libetonyek::IWORKDataPtr_t
std::shared_ptr< IWORKData > IWORKDataPtr_t
Definition: IWORKTypes_fwd.h:47
libetonyek::IWORKCollector::collectText
void collectText(const std::shared_ptr< IWORKText > &text)
Definition: IWORKCollector.cpp:628
libetonyek::IWORKCollector::~IWORKCollector
~IWORKCollector()
Definition: IWORKCollector.cpp:369
libetonyek::IWORKCollector::collectImage
void collectImage(const IWORKImagePtr_t &image)
Definition: IWORKCollector.cpp:433
libetonyek::IWORKHeaderFooterMap_t
std::unordered_map< std::string, IWORKOutputElements > IWORKHeaderFooterMap_t
Definition: IWORKTypes.h:33
libetonyek::IWORKToken::style
Definition: IWORKToken.h:268
IWORKStyle.h
libetonyek::IWORKCollector::Level::m_geometry
IWORKGeometryPtr_t m_geometry
Definition: IWORKCollector.h:46
libetonyek::IWORKCollector::startDocument
void startDocument()
Definition: IWORKCollector.cpp:640
libetonyek::IWORKCollector::endDocument
void endDocument()
Definition: IWORKCollector.cpp:645
libetonyek::IWORKCollector::m_currentPath
IWORKPathPtr_t m_currentPath
Definition: IWORKCollector.h:155
libetonyek::IWORKCollector
Definition: IWORKCollector.h:41
libetonyek::IWORKCollector::collectHeader
void collectHeader(const std::string &name)
Definition: IWORKCollector.cpp:604
libetonyek::IWORKCollector::collectConnectionPath
void collectConnectionPath(const IWORKSize &size, double middleX, double middleY)
Definition: IWORKCollector.cpp:544
libetonyek::IWORKCollector::setRecorder
void setRecorder(const std::shared_ptr< IWORKRecorder > &recorder)
Definition: IWORKCollector.cpp:379
libetonyek::IWORKCollector::m_levelStack
std::stack< Level > m_levelStack
Definition: IWORKCollector.h:141
name
const char * name
Definition: IWORKToken.cpp:43
libetonyek::IWORKCollector::collectStylesheet
void collectStylesheet(const IWORKStylesheetPtr_t &stylesheet)
Definition: IWORKCollector.cpp:587
libetonyek::IWORKTextPtr_t
std::shared_ptr< IWORKText > IWORKTextPtr_t
Definition: IWORKText_fwd.h:18
libetonyek::IWORKToken::size
Definition: IWORKToken.h:254
libetonyek::IWORKCollector::collectBezierPath
void collectBezierPath()
Definition: IWORKCollector.cpp:499
libetonyek::IWORKCollector::m_newStyles
std::deque< IWORKStylePtr_t > m_newStyles
Definition: IWORKCollector.h:146
libetonyek::IWORKCollector::m_document
IWORKDocumentInterface * m_document
Definition: IWORKCollector.h:138
libetonyek::IWORKCollector::writeFill
static void writeFill(const IWORKFill &fill, librevenge::RVNGPropertyList &props)
Definition: IWORKCollector.cpp:858
libetonyek::IWORKFill
boost::variant< IWORKColor, IWORKGradient, IWORKFillImage > IWORKFill
Definition: IWORKTypes.h:243
libetonyek::IWORKCollector::collectMedia
void collectMedia(const IWORKMediaContentPtr_t &content)
Definition: IWORKCollector.cpp:566
libetonyek::IWORKCollector::Level::Level
Level()
Definition: IWORKCollector.cpp:347
libetonyek::IWORKCollector::fillShapeProperties
virtual void fillShapeProperties(librevenge::RVNGPropertyList &props)=0
IWORKPath_fwd.h
libetonyek::IWORKCollector::getOutputManager
IWORKOutputManager & getOutputManager()
Definition: IWORKCollector.cpp:788
libetonyek::IWORKCollector::m_currentText
std::shared_ptr< IWORKText > m_currentText
Definition: IWORKCollector.h:149
libetonyek::IWORKToken::w
Definition: IWORKToken.h:373
libetonyek::IWORKCollector::getStylesheet
IWORKStylesheetPtr_t getStylesheet() const
Definition: IWORKCollector.h:106
libetonyek::IWORKCollector::drawShape
void drawShape(const IWORKShapePtr_t &shape)
Definition: IWORKCollector.cpp:829
IWORKStylesheet.h
libetonyek::IWORKCollector::m_currentUnfiltered
IWORKMediaContentPtr_t m_currentUnfiltered
Definition: IWORKCollector.h:157
libetonyek::IWORKToken::geometry
Definition: IWORKToken.h:148
IWORKShape.h
libetonyek::IWORKCollector::startLevel
void startLevel()
Definition: IWORKCollector.cpp:690
libetonyek::IWORKCollector::Level::m_trafo
glm::dmat3 m_trafo
Definition: IWORKCollector.h:48
libetonyek::IWORKTableNameMapPtr_t
std::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition: IWORKTypes_fwd.h:32
libetonyek::IWORKCollector::collectArrowPath
void collectArrowPath(const IWORKSize &size, double headWidth, double stemRelYPos, bool doubleSided)
Definition: IWORKCollector.cpp:522
libetonyek::IWORKLinePtr_t
std::shared_ptr< IWORKLine > IWORKLinePtr_t
Definition: IWORKTypes_fwd.h:43
libetonyek::IWORKCollector::endLevel
void endLevel()
Definition: IWORKCollector.cpp:707
IWORKStyleStack.h
libetonyek::KEY1Token::radius
Definition: KEY1Token.h:156
libetonyek::IWORKToken::data
Definition: IWORKToken.h:101
libetonyek::IWORKCollector::endGroup
void endGroup()
Definition: IWORKCollector.cpp:667
libetonyek::IWORKLanguageManager
Definition: IWORKLanguageManager.h:23
libetonyek::IWORKCollector::m_outputManager
IWORKOutputManager m_outputManager
Definition: IWORKCollector.h:144
libetonyek::NUM1Token::document
Definition: NUM1Token.h:34
libetonyek::IWORKImagePtr_t
std::shared_ptr< IWORKImage > IWORKImagePtr_t
Definition: IWORKTypes_fwd.h:57
libetonyek::IWORKCollector::m_footers
IWORKHeaderFooterMap_t m_footers
Definition: IWORKCollector.h:152
libetonyek::IWORKToken::string
Definition: IWORKToken.h:266
libetonyek::IWORKCollector::collectCalloutPath
void collectCalloutPath(const IWORKSize &size, double radius, double tailSize, double tailX, double tailY, bool quoteBubble)
Definition: IWORKCollector.cpp:553
libetonyek::IWORKCollector::m_metadata
IWORKMetadata m_metadata
Definition: IWORKCollector.h:162
libetonyek::IWORKCollector::fillMetadata
void fillMetadata(librevenge::RVNGPropertyList &props)
Definition: IWORKCollector.cpp:776
libetonyek::IWORKCollector::collectLine
void collectLine(const IWORKLinePtr_t &line)
Definition: IWORKCollector.cpp:449
libetonyek::IWORKCollector::collectShape
void collectShape()
Definition: IWORKCollector.cpp:465
libetonyek::IWORKPathPtr_t
std::shared_ptr< IWORKPath > IWORKPathPtr_t
Definition: IWORKPath_fwd.h:20
IWORKTypes.h
libetonyek::IWORKCollector::m_styleStack
IWORKStyleStack m_styleStack
Definition: IWORKCollector.h:142
libetonyek::IWORKShapePtr_t
std::shared_ptr< IWORKShape > IWORKShapePtr_t
Definition: IWORKShape.h:36
libetonyek::IWORKCollector::pushStyle
void pushStyle()
Definition: IWORKCollector.cpp:721
libetonyek::IWORKCollector::m_groupLevel
int m_groupLevel
Definition: IWORKCollector.h:164
libetonyek::IWORKCollector::collectPolygonPath
void collectPolygonPath(const IWORKSize &size, unsigned edges)
Definition: IWORKCollector.cpp:504
libetonyek::IWORKCollector::pushStylesheet
void pushStylesheet(const IWORKStylesheetPtr_t &stylesheet)
Definition: IWORKCollector.cpp:731
libetonyek_utils.h
libetonyek::IWORKToken::metadata
Definition: IWORKToken.h:205
libetonyek::IWORKCollector::m_currentTable
std::shared_ptr< IWORKTable > m_currentTable
Definition: IWORKCollector.h:148
libetonyek::IWORKToken::tailSize
Definition: IWORKToken.h:366
libetonyek::IWORKCollector::collectRoundedRectanglePath
void collectRoundedRectanglePath(const IWORKSize &size, double radius)
Definition: IWORKCollector.cpp:513
libetonyek::IWORKMediaContentPtr_t
std::shared_ptr< IWORKMediaContent > IWORKMediaContentPtr_t
Definition: IWORKTypes_fwd.h:52
libetonyek::IWORKMetadata
Definition: IWORKTypes.h:255
libetonyek::IWORKToken::fill
Definition: IWORKToken.h:114
libetonyek::IWORKCollector::m_currentData
IWORKDataPtr_t m_currentData
Definition: IWORKCollector.h:156
libetonyek::IWORKStylesheetPtr_t
std::shared_ptr< IWORKStylesheet > IWORKStylesheetPtr_t
Definition: IWORKStylesheet.h:19