IWAParser.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 IWAPARSER_H_INCLUDED
11#define IWAPARSER_H_INCLUDED
12
13#include <deque>
14#include <functional>
15#include <map>
16#include <memory>
17#include <string>
18#include <unordered_map>
19
20#include <boost/optional.hpp>
21#include <boost/variant.hpp>
22
23#if defined(__GNUC__) && !defined(__clang__)
24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Weffc++"
26#endif
27#include <mdds/flat_segment_tree.hpp>
28#if defined(__GNUC__) && !defined(__clang__)
29#pragma GCC diagnostic pop
30#endif
31
32#include "libetonyek_utils.h"
33#include "IWAMessage.h"
34#include "IWAObjectIndex.h"
36#include "IWORKOutputElements.h"
37#include "IWORKStyle_fwd.h"
38#include "IWORKTypes.h"
39
40namespace libetonyek
41{
42
43class IWORKCollector;
44class IWAObjectIndex;
45class IWORKPropertyMap;
46class IWORKTable;
47class IWORKText;
48
50{
51 friend class IWAObjectIndex; // for readColor
52
53 // disable copying
56public:
57 IWAParser(const RVNGInputStreamPtr_t &fragments, const RVNGInputStreamPtr_t &package, IWORKCollector &collector);
58 virtual ~IWAParser()
59 {
60 }
61
62 bool parse();
63
64protected:
66 {
67 public:
68 ObjectMessage(IWAParser &parser, unsigned id, unsigned type = 0);
70
71 operator bool() const;
72 const IWAMessage &get() const;
73
74 unsigned getType() const;
75
76 friend const IWAMessage &get(const ObjectMessage &msg)
77 {
78 return msg.get();
79 }
80
81 private:
83 boost::optional<IWAMessage> m_message;
84 const unsigned m_id;
85 unsigned m_type;
86 };
87 friend class ObjectMessage;
88
89 typedef std::map<unsigned, IWORKStylePtr_t> StyleMap_t;
90 typedef std::function<void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t;
91
92protected:
93 static boost::optional<unsigned> readRef(const IWAMessage &msg, unsigned field);
94 static std::deque<unsigned> readRefs(const IWAMessage &msg, unsigned field);
95 static boost::optional<IWORKPosition> readPosition(const IWAMessage &msg, unsigned field);
96 static boost::optional<IWORKSize> readSize(const IWAMessage &msg, unsigned field);
97 static boost::optional<IWORKColor> readColor(const IWAMessage &msg, unsigned field);
98 static boost::optional<std::string> readUUID(const IWAMessage &msg, unsigned field);
99 static boost::optional<uint64_t> readUID(const IWAMessage &msg, unsigned field);
100 static std::deque<uint64_t> readUIDs(const IWAMessage &msg, unsigned field);
101 static void readStroke(const IWAMessage &msg, IWORKStroke &stroke);
102 bool readFill(const IWAMessage &msg, IWORKFill &fill);
103 static void readGradient(const IWAMessage &msg, IWORKGradient &gradient);
104 static void readShadow(const IWAMessage &msg, IWORKShadow &shadow);
105 static void readPadding(const IWAMessage &msg, IWORKPadding &padding);
106 static void readDropCap(const IWAMessage &msg, IWORKDropCap &cap);
107
108 bool dispatchShape(unsigned id);
109 bool dispatchShapeWithMessage(const IWAMessage &msg, unsigned type);
110 bool parseText(unsigned id, bool createNoteAsFootnote=true, const std::function<void(unsigned, IWORKStylePtr_t)> &openPageSpan=nullptr);
111 void parseComment(unsigned id);
112 void parseAuthorInComment(unsigned id);
113 void parseCustomFormat(unsigned id);
114
115 virtual bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry, boost::optional<unsigned> &flags);
117 void updateGeometryUsingTextRef(unsigned id, IWORKGeometry &geometry, unsigned flags);
118
119 const IWORKStylePtr_t queryCharacterStyle(unsigned id) const;
120 const IWORKStylePtr_t queryDropCapStyle(unsigned id) const;
121 const IWORKStylePtr_t queryParagraphStyle(unsigned id) const;
122 const IWORKStylePtr_t querySectionStyle(unsigned id) const;
123
124 const IWORKStylePtr_t queryGraphicStyle(unsigned id) const;
125 const IWORKStylePtr_t queryMediaStyle(unsigned id) const;
126 const IWORKStylePtr_t queryCellStyle(unsigned id) const;
127 const IWORKStylePtr_t queryTableStyle(unsigned id) const;
128 const IWORKStylePtr_t queryListStyle(unsigned id) const;
129
130 const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const;
131 boost::optional<unsigned> getObjectType(unsigned id) const;
132
133protected:
137 std::shared_ptr<IWORKText> m_currentText;
138
139private:
140 struct Format
141 {
142 Format();
143 boost::optional<IWORKCellType> m_type;
144 boost::variant<IWORKNumberFormat,IWORKDateTimeFormat,IWORKDurationFormat> m_format;
145 };
146
153
155 {
156 TableHeader(unsigned count, float defValue=0);
157
158 mdds::flat_segment_tree<unsigned, float> m_sizes;
159 mdds::flat_segment_tree<unsigned, bool> m_hidden;
160 };
161
162 typedef std::map<unsigned, boost::variant<std::string, unsigned, IWORKFormulaPtr_t, Format> > DataList_t;
163
165 {
167
169 boost::optional<unsigned> m_cellStyleRef;
170 boost::optional<unsigned> m_paragraphStyleRef;
171 };
172
173 typedef std::deque<ConditionRule> ConditionRule_t;
174 typedef std::map<unsigned, ConditionRule_t> ConditionRuleList_t;
175
199
200private:
201 virtual bool parseDocument() = 0;
202
203private:
204 void queryObject(unsigned id, unsigned &type, boost::optional<IWAMessage> &msg) const;
205 const RVNGInputStreamPtr_t queryFile(unsigned id) const;
206
207 void parseObjectIndex();
208
209 void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style);
210 void parseDropCapStyle(unsigned id, IWORKStylePtr_t &style);
211 void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style);
212 void parseSectionStyle(unsigned id, IWORKStylePtr_t &style);
213
214 void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style);
215 void parseMediaStyle(unsigned id, IWORKStylePtr_t &style);
216 void parseCellStyle(unsigned id, IWORKStylePtr_t &style);
217 void parseTableStyle(unsigned id, IWORKStylePtr_t &style);
218 void parseListStyle(unsigned id, IWORKStylePtr_t &style);
219
220 void parseHeaderAndFooter(unsigned id, IWORKPageMaster &hf);
221 void parsePageMaster(unsigned id, PageMaster &pageMaster);
222
223 void parseTabularModel(unsigned id);
224 void parseDataList(unsigned id, DataList_t &dataList);
225 void parseTile(unsigned id, unsigned decalY);
226 void parseTileDefinition(unsigned row, unsigned col, RVNGInputStreamPtr_t &input, unsigned endPos, bool oldFormat);
227 void parseTableHeaders(unsigned id, TableHeader &header);
228 void parseTableGridLines(unsigned id, IWORKGridLineMap_t (&gridLines)[4]);
229 void parseTableGridLine(unsigned id, IWORKGridLineMap_t &gridLines);
230 void parseLink(unsigned id, std::string &url);
231
232 bool parseAttachment(unsigned id);
233 bool parseConditionRules(unsigned id, ConditionRule_t &rules);
234 bool parseDrawableShape(const IWAMessage &msg, bool isConnectionLine=false);
235 bool parseGroup(const IWAMessage &msg);
236 bool parseShapePlacement(const IWAMessage &msg);
237 bool parseImage(const IWAMessage &msg);
238 bool parseTabularInfo(const IWAMessage &msg);
239 bool parsePath(const IWAMessage &msg, IWORKPathPtr_t &path);
241 bool parseFormat(const IWAMessage &msg, Format &format);
242 virtual bool parseStickyNote(const IWAMessage &msg);
243
244 bool parseArrowProperties(const IWAMessage &msg, IWORKPropertyMap &props, bool headArrow);
246 void parseColumnsProperties(const IWAMessage &msg, IWORKPropertyMap &props);
247
248private:
250
252
253 std::deque<unsigned> m_visited;
254
259
265
266 std::shared_ptr<TableInfo> m_currentTable;
267 std::map<uint64_t,Format> m_uidFormatMap;
268};
269
270}
271
272#endif
273
274/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition IWAMessage.h:22
Definition IWAObjectIndex.h:27
Definition IWAParser.h:66
boost::optional< IWAMessage > m_message
Definition IWAParser.h:83
friend const IWAMessage & get(const ObjectMessage &msg)
Definition IWAParser.h:76
const unsigned m_id
Definition IWAParser.h:84
unsigned getType() const
Definition IWAParser.cpp:244
unsigned m_type
Definition IWAParser.h:85
~ObjectMessage()
Definition IWAParser.cpp:224
IWAParser & m_parser
Definition IWAParser.h:82
const IWAMessage & get() const
Definition IWAParser.cpp:239
Definition IWAParser.h:50
const IWORKStylePtr_t querySectionStyle(unsigned id) const
Definition IWAParser.cpp:1033
StyleMap_t m_cellStyles
Definition IWAParser.h:262
void parseTabularModel(unsigned id)
Definition IWAParser.cpp:2518
void parseTableGridLine(unsigned id, IWORKGridLineMap_t &gridLines)
Definition IWAParser.cpp:3297
void parseDataList(unsigned id, DataList_t &dataList)
Definition IWAParser.cpp:2724
void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition IWAParser.cpp:2236
void queryObject(unsigned id, unsigned &type, boost::optional< IWAMessage > &msg) const
Definition IWAParser.cpp:249
std::shared_ptr< TableInfo > m_currentTable
Definition IWAParser.h:266
void parseTableStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:2035
std::deque< ConditionRule > ConditionRule_t
Definition IWAParser.h:173
bool parseFormula(const IWAMessage &msg, IWORKFormulaPtr_t &formula)
Definition IWAParser.cpp:3511
const IWORKStylePtr_t queryMediaStyle(unsigned id) const
Definition IWAParser.cpp:1043
bool parseConditionRules(unsigned id, ConditionRule_t &rules)
Definition IWAParser.cpp:3487
std::shared_ptr< IWORKText > m_currentText
Definition IWAParser.h:137
void parseColumnsProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition IWAParser.cpp:2276
void parseAuthorInComment(unsigned id)
Definition IWAParser.cpp:2448
bool parseGroup(const IWAMessage &msg)
Definition IWAParser.cpp:1560
void parseTile(unsigned id, unsigned decalY)
Definition IWAParser.cpp:3177
IWORKLanguageManager m_langManager
Definition IWAParser.h:135
std::map< unsigned, ConditionRule_t > ConditionRuleList_t
Definition IWAParser.h:174
bool parseImage(const IWAMessage &msg)
Definition IWAParser.cpp:2394
void updateGeometryUsingTextRef(unsigned id, IWORKGeometry &geometry, unsigned flags)
Definition IWAParser.cpp:620
StyleMap_t m_graphicStyles
Definition IWAParser.h:260
const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const
Definition IWAParser.cpp:1005
void parseSectionStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1796
static boost::optional< unsigned > readRef(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:264
const IWORKStylePtr_t queryGraphicStyle(unsigned id) const
Definition IWAParser.cpp:1038
virtual bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry, boost::optional< unsigned > &flags)
Definition IWAParser.cpp:1579
std::map< unsigned, IWORKStylePtr_t > StyleMap_t
Definition IWAParser.h:89
bool parse()
Definition IWAParser.cpp:188
StyleMap_t m_tableStyles
Definition IWAParser.h:263
const IWORKStylePtr_t queryTableStyle(unsigned id) const
Definition IWAParser.cpp:1053
bool parseText(unsigned id, bool createNoteAsFootnote=true, const std::function< void(unsigned, IWORKStylePtr_t)> &openPageSpan=nullptr)
Definition IWAParser.cpp:674
void parseTileDefinition(unsigned row, unsigned col, RVNGInputStreamPtr_t &input, unsigned endPos, bool oldFormat)
Definition IWAParser.cpp:2817
void parseTableGridLines(unsigned id, IWORKGridLineMap_t(&gridLines)[4])
Definition IWAParser.cpp:3275
std::map< unsigned, boost::variant< std::string, unsigned, IWORKFormulaPtr_t, Format > > DataList_t
Definition IWAParser.h:162
virtual ~IWAParser()
Definition IWAParser.h:58
StyleMap_t m_mediaStyles
Definition IWAParser.h:261
void parseHeaderAndFooter(unsigned id, IWORKPageMaster &hf)
Definition IWAParser.cpp:2357
void parseCellStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1952
const IWORKStylePtr_t queryCharacterStyle(unsigned id) const
Definition IWAParser.cpp:1018
static boost::optional< IWORKColor > readColor(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:308
bool readFill(const IWAMessage &msg, IWORKFill &fill)
Definition IWAParser.cpp:443
StyleMap_t m_paraStyles
Definition IWAParser.h:257
static void readPadding(const IWAMessage &msg, IWORKPadding &padding)
Definition IWAParser.cpp:555
StyleMap_t m_sectionStyles
Definition IWAParser.h:258
void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1696
const RVNGInputStreamPtr_t queryFile(unsigned id) const
Definition IWAParser.cpp:259
static void readStroke(const IWAMessage &msg, IWORKStroke &stroke)
Definition IWAParser.cpp:376
bool dispatchShapeWithMessage(const IWAMessage &msg, unsigned type)
Definition IWAParser.cpp:591
boost::optional< unsigned > getObjectType(unsigned id) const
Definition IWAParser.cpp:254
const IWORKStylePtr_t queryParagraphStyle(unsigned id) const
Definition IWAParser.cpp:1028
bool parseTabularInfo(const IWAMessage &msg)
Definition IWAParser.cpp:2506
static boost::optional< std::string > readUUID(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:341
void parseLink(unsigned id, std::string &url)
Definition IWAParser.cpp:3812
const IWORKStylePtr_t queryListStyle(unsigned id) const
Definition IWAParser.cpp:1058
static void readDropCap(const IWAMessage &msg, IWORKDropCap &cap)
Definition IWAParser.cpp:563
StyleMap_t m_dropCapStyles
Definition IWAParser.h:256
static std::deque< unsigned > readRefs(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:271
bool parseDrawableShape(const IWAMessage &msg, bool isConnectionLine=false)
Definition IWAParser.cpp:1289
static boost::optional< uint64_t > readUID(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:319
IWAObjectIndex m_index
Definition IWAParser.h:251
static boost::optional< IWORKPosition > readPosition(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:286
void parseDropCapStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1664
friend class ObjectMessage
Definition IWAParser.h:87
void parsePageMaster(unsigned id, PageMaster &pageMaster)
Definition IWAParser.cpp:2319
const IWORKStylePtr_t queryCellStyle(unsigned id) const
Definition IWAParser.cpp:1048
void parseMediaStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1912
bool dispatchShape(unsigned id)
Definition IWAParser.cpp:583
IWAParser & operator=(const IWAParser &)
std::deque< unsigned > m_visited
Definition IWAParser.h:253
bool parseFormat(const IWAMessage &msg, Format &format)
Definition IWAParser.cpp:3333
void parseTableHeaders(unsigned id, TableHeader &header)
Definition IWAParser.cpp:3251
static std::deque< uint64_t > readUIDs(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:329
bool parseAttachment(unsigned id)
Definition IWAParser.cpp:1063
bool parseArrowProperties(const IWAMessage &msg, IWORKPropertyMap &props, bool headArrow)
Definition IWAParser.cpp:1160
void parseCustomFormat(unsigned id)
Definition IWAParser.cpp:3461
IWORKFormatNameMap m_formatNameMap
Definition IWAParser.h:134
void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1820
static void readShadow(const IWAMessage &msg, IWORKShadow &shadow)
Definition IWAParser.cpp:537
void parseMask(unsigned id, IWORKGeometryPtr_t &geometry, IWORKPathPtr_t &path)
Definition IWAParser.cpp:1622
bool parsePath(const IWAMessage &msg, IWORKPathPtr_t &path)
Definition IWAParser.cpp:1193
void parseListStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:2079
void parseObjectIndex()
Definition IWAParser.cpp:1635
const IWORKStylePtr_t queryDropCapStyle(unsigned id) const
Definition IWAParser.cpp:1023
void parseComment(unsigned id)
Definition IWAParser.cpp:2473
virtual bool parseStickyNote(const IWAMessage &msg)
Definition IWAParser.cpp:1283
static void readGradient(const IWAMessage &msg, IWORKGradient &gradient)
Definition IWAParser.cpp:504
static boost::optional< IWORKSize > readSize(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:297
IWORKTableNameMapPtr_t m_tableNameMap
Definition IWAParser.h:136
IWAParser(const IWAParser &)
StyleMap_t m_charStyles
Definition IWAParser.h:255
StyleMap_t m_listStyles
Definition IWAParser.h:264
void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1640
virtual bool parseDocument()=0
std::map< uint64_t, Format > m_uidFormatMap
Definition IWAParser.h:267
IWORKCollector & m_collector
Definition IWAParser.h:249
std::function< void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t
Definition IWAParser.h:90
Definition IWORKCollector.h:42
Definition IWORKLanguageManager.h:24
Represents a (hierarchical) property map.
Definition IWORKPropertyMap.h:25
@ fill
Definition IWORKToken.h:204
@ padding
Definition IWORKToken.h:349
@ row
Definition IWORKToken.h:390
@ format
Definition IWORKToken.h:537
@ col
Definition IWORKToken.h:154
@ rows
Definition IWORKToken.h:392
@ type
Definition IWORKToken.h:493
@ cap
Definition IWORKToken.h:517
@ path
Definition IWORKToken.h:365
@ header
Definition IWORKToken.h:256
@ flags
Definition IWORKToken.h:534
@ style
Definition IWORKToken.h:421
@ stroke
Definition IWORKToken.h:419
@ count
Definition IWORKToken.h:522
@ geometry
Definition IWORKToken.h:236
@ formula
Definition IWORKToken.h:228
@ columns
Definition IWORKToken.h:158
@ table
Definition KEY1Token.h:198
@ gradient
Definition KEY1Token.h:58
Definition IWORKBezierElement.cpp:21
boost::variant< IWORKColor, IWORKGradient, IWORKMediaContent > IWORKFill
Definition IWORKTypes.h:309
std::unordered_map< std::string, std::string > IWORKFormatNameMap
Definition IWORKTypes_fwd.h:32
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition libetonyek_utils.h:82
std::map< unsigned, IWORKGridLine_t > IWORKGridLineMap_t
Definition IWORKTypes.h:122
std::shared_ptr< IWORKPath > IWORKPathPtr_t
Definition IWORKPath_fwd.h:22
std::shared_ptr< IWORKFormula > IWORKFormulaPtr_t
Definition IWORKTypes.h:123
std::shared_ptr< IWORKGeometry > IWORKGeometryPtr_t
Definition IWORKTypes_fwd.h:45
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition IWORKStyle_fwd.h:23
std::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition IWORKTypes_fwd.h:36
Definition IWAParser.h:165
ConditionRule()
Definition IWAParser.cpp:141
boost::optional< unsigned > m_cellStyleRef
Definition IWAParser.h:169
IWORKFormulaPtr_t m_formula
Definition IWAParser.h:168
boost::optional< unsigned > m_paragraphStyleRef
Definition IWAParser.h:170
Definition IWAParser.h:141
Format()
Definition IWAParser.cpp:123
boost::optional< IWORKCellType > m_type
Definition IWAParser.h:143
boost::variant< IWORKNumberFormat, IWORKDateTimeFormat, IWORKDurationFormat > m_format
Definition IWAParser.h:144
Definition IWAParser.h:148
PageMaster()
Definition IWAParser.cpp:129
bool m_headerFootersSameAsPrevious
Definition IWAParser.h:151
IWORKStylePtr_t m_style
Definition IWAParser.h:150
Definition IWAParser.h:155
mdds::flat_segment_tree< unsigned, bool > m_hidden
Definition IWAParser.h:159
mdds::flat_segment_tree< unsigned, float > m_sizes
Definition IWAParser.h:158
TableHeader(unsigned count, float defValue=0)
Definition IWAParser.cpp:135
Definition IWAParser.h:177
TableInfo(const std::shared_ptr< IWORKTable > &table, unsigned columns, unsigned rows)
Definition IWAParser.cpp:148
DataList_t m_formatList
Definition IWAParser.h:195
DataList_t m_simpleTextList
Definition IWAParser.h:190
DataList_t m_newFormatList
Definition IWAParser.h:196
TableHeader m_columnHeader
Definition IWAParser.h:187
DataList_t m_formattedTextList
Definition IWAParser.h:193
DataList_t m_formulaList
Definition IWAParser.h:194
DataList_t m_commentList
Definition IWAParser.h:197
DataList_t m_cellStyleList
Definition IWAParser.h:191
TableHeader m_rowHeader
Definition IWAParser.h:188
ConditionRuleList_t m_conditionStyleList
Definition IWAParser.h:192
IWORKStylePtr_t m_style
Definition IWAParser.h:185
const unsigned m_rows
Definition IWAParser.h:183
const unsigned m_columns
Definition IWAParser.h:182
std::shared_ptr< IWORKTable > m_table
Definition IWAParser.h:180
Definition IWORKTypes.h:313
Definition IWORKTypes.h:62
Definition IWORKTypes.h:300
Definition IWORKTypes.h:100
Definition IWORKTypes.h:376
Definition IWORKTypes.h:331
Definition IWORKTypes.h:278

Generated for libetonyek by doxygen 1.12.0