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;
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
107 bool dispatchShape(unsigned id);
108 bool dispatchShapeWithMessage(const IWAMessage &msg, unsigned type);
109 bool parseText(unsigned id, bool createNoteAsFootnote=true, const std::function<void(unsigned, IWORKStylePtr_t)> &openPageSpan=nullptr);
110 void parseComment(unsigned id);
111 void parseAuthorInComment(unsigned id);
112 void parseCustomFormat(unsigned id);
113
114 virtual bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry, boost::optional<unsigned> &flags);
116 void updateGeometryUsingTextRef(unsigned id, IWORKGeometry &geometry, unsigned flags);
117
118 const IWORKStylePtr_t queryCharacterStyle(unsigned id) const;
119 const IWORKStylePtr_t queryParagraphStyle(unsigned id) const;
120 const IWORKStylePtr_t querySectionStyle(unsigned id) const;
121
122 const IWORKStylePtr_t queryGraphicStyle(unsigned id) const;
123 const IWORKStylePtr_t queryMediaStyle(unsigned id) const;
124 const IWORKStylePtr_t queryCellStyle(unsigned id) const;
125 const IWORKStylePtr_t queryTableStyle(unsigned id) const;
126 const IWORKStylePtr_t queryListStyle(unsigned id) const;
127
128 const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const;
129 boost::optional<unsigned> getObjectType(unsigned id) const;
130
131protected:
134 std::shared_ptr<IWORKText> m_currentText;
135
136private:
137 struct Format
138 {
139 Format();
140 boost::optional<IWORKCellType> m_type;
141 boost::variant<IWORKNumberFormat,IWORKDateTimeFormat,IWORKDurationFormat> m_format;
142 };
143
150
152 {
153 TableHeader(unsigned count, float defValue=0);
154
155 mdds::flat_segment_tree<unsigned, float> m_sizes;
156 mdds::flat_segment_tree<unsigned, bool> m_hidden;
157 };
158
159 typedef std::map<unsigned, boost::variant<std::string, unsigned, IWORKFormulaPtr_t, Format> > DataList_t;
160
182
183private:
184 virtual bool parseDocument() = 0;
185
186private:
187 void queryObject(unsigned id, unsigned &type, boost::optional<IWAMessage> &msg) const;
188 const RVNGInputStreamPtr_t queryFile(unsigned id) const;
189
190 void parseObjectIndex();
191
192 void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style);
193 void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style);
194 void parseSectionStyle(unsigned id, IWORKStylePtr_t &style);
195
196 void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style);
197 void parseMediaStyle(unsigned id, IWORKStylePtr_t &style);
198 void parseCellStyle(unsigned id, IWORKStylePtr_t &style);
199 void parseTableStyle(unsigned id, IWORKStylePtr_t &style);
200 void parseListStyle(unsigned id, IWORKStylePtr_t &style);
201
202 void parseHeaderAndFooter(unsigned id, IWORKPageMaster &hf);
203 void parsePageMaster(unsigned id, PageMaster &pageMaster);
204
205 void parseTabularModel(unsigned id);
206 void parseDataList(unsigned id, DataList_t &dataList);
207 void parseTile(unsigned id);
208 void parseTableHeaders(unsigned id, TableHeader &header);
209 void parseTableGridLines(unsigned id, IWORKGridLineMap_t (&gridLines)[4]);
210 void parseTableGridLine(unsigned id, IWORKGridLineMap_t &gridLines);
211 void parseLink(unsigned id, std::string &url);
212
213 bool parseAttachment(unsigned id);
214 bool parseDrawableShape(const IWAMessage &msg, bool isConnectionLine=false);
215 bool parseGroup(const IWAMessage &msg);
216 bool parseShapePlacement(const IWAMessage &msg);
217 bool parseImage(const IWAMessage &msg);
218 bool parseTabularInfo(const IWAMessage &msg);
219 bool parsePath(const IWAMessage &msg, IWORKPathPtr_t &path);
221 bool parseFormat(const IWAMessage &msg, Format &format);
222 virtual bool parseStickyNote(const IWAMessage &msg);
223
224 bool parseArrowProperties(const IWAMessage &msg, IWORKPropertyMap &props, bool headArrow);
226 void parseColumnsProperties(const IWAMessage &msg, IWORKPropertyMap &props);
227
228private:
230
232
233 std::deque<unsigned> m_visited;
234
238
244
245 std::shared_ptr<TableInfo> m_currentTable;
246 std::map<uint64_t,Format> m_uidFormatMap;
247};
248
249}
250
251#endif
252
253/* 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:225
unsigned m_type
Definition IWAParser.h:85
~ObjectMessage()
Definition IWAParser.cpp:205
IWAParser & m_parser
Definition IWAParser.h:82
const IWAMessage & get() const
Definition IWAParser.cpp:220
ObjectMessage(IWAParser &parser, unsigned id, unsigned type=0)
Definition IWAParser.cpp:175
const IWORKStylePtr_t querySectionStyle(unsigned id) const
Definition IWAParser.cpp:960
StyleMap_t m_cellStyles
Definition IWAParser.h:241
void parseTabularModel(unsigned id)
Definition IWAParser.cpp:2412
void parseTableGridLine(unsigned id, IWORKGridLineMap_t &gridLines)
Definition IWAParser.cpp:2944
void parseDataList(unsigned id, DataList_t &dataList)
Definition IWAParser.cpp:2561
void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition IWAParser.cpp:2130
void parseTile(unsigned id)
Definition IWAParser.cpp:2651
void queryObject(unsigned id, unsigned &type, boost::optional< IWAMessage > &msg) const
Definition IWAParser.cpp:230
std::shared_ptr< TableInfo > m_currentTable
Definition IWAParser.h:245
void parseTableStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1929
std::map< unsigned, boost::variant< std::string, unsigned, IWORKFormulaPtr_t, Format > > DataList_t
Definition IWAParser.h:159
bool parseFormula(const IWAMessage &msg, IWORKFormulaPtr_t &formula)
Definition IWAParser.cpp:3119
const IWORKStylePtr_t queryMediaStyle(unsigned id) const
Definition IWAParser.cpp:970
std::shared_ptr< IWORKText > m_currentText
Definition IWAParser.h:134
void parseColumnsProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition IWAParser.cpp:2170
void parseAuthorInComment(unsigned id)
Definition IWAParser.cpp:2342
bool parseGroup(const IWAMessage &msg)
Definition IWAParser.cpp:1487
IWORKLanguageManager m_langManager
Definition IWAParser.h:132
std::map< unsigned, IWORKStylePtr_t > StyleMap_t
Definition IWAParser.h:89
bool parseImage(const IWAMessage &msg)
Definition IWAParser.cpp:2288
void updateGeometryUsingTextRef(unsigned id, IWORKGeometry &geometry, unsigned flags)
Definition IWAParser.cpp:579
StyleMap_t m_graphicStyles
Definition IWAParser.h:239
const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const
Definition IWAParser.cpp:937
void parseSectionStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1690
static boost::optional< unsigned > readRef(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:245
const IWORKStylePtr_t queryGraphicStyle(unsigned id) const
Definition IWAParser.cpp:965
virtual bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry, boost::optional< unsigned > &flags)
Definition IWAParser.cpp:1506
bool parse()
Definition IWAParser.cpp:169
StyleMap_t m_tableStyles
Definition IWAParser.h:242
const IWORKStylePtr_t queryTableStyle(unsigned id) const
Definition IWAParser.cpp:980
bool parseText(unsigned id, bool createNoteAsFootnote=true, const std::function< void(unsigned, IWORKStylePtr_t)> &openPageSpan=nullptr)
Definition IWAParser.cpp:633
void parseTableGridLines(unsigned id, IWORKGridLineMap_t(&gridLines)[4])
Definition IWAParser.cpp:2922
virtual ~IWAParser()
Definition IWAParser.h:58
StyleMap_t m_mediaStyles
Definition IWAParser.h:240
void parseHeaderAndFooter(unsigned id, IWORKPageMaster &hf)
Definition IWAParser.cpp:2251
void parseCellStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1846
const IWORKStylePtr_t queryCharacterStyle(unsigned id) const
Definition IWAParser.cpp:950
static boost::optional< IWORKColor > readColor(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:289
bool readFill(const IWAMessage &msg, IWORKFill &fill)
Definition IWAParser.cpp:424
StyleMap_t m_paraStyles
Definition IWAParser.h:236
static void readPadding(const IWAMessage &msg, IWORKPadding &padding)
Definition IWAParser.cpp:534
StyleMap_t m_sectionStyles
Definition IWAParser.h:237
std::function< void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t
Definition IWAParser.h:90
void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1591
const RVNGInputStreamPtr_t queryFile(unsigned id) const
Definition IWAParser.cpp:240
static void readStroke(const IWAMessage &msg, IWORKStroke &stroke)
Definition IWAParser.cpp:357
bool dispatchShapeWithMessage(const IWAMessage &msg, unsigned type)
Definition IWAParser.cpp:550
boost::optional< unsigned > getObjectType(unsigned id) const
Definition IWAParser.cpp:235
const IWORKStylePtr_t queryParagraphStyle(unsigned id) const
Definition IWAParser.cpp:955
bool parseTabularInfo(const IWAMessage &msg)
Definition IWAParser.cpp:2400
static boost::optional< std::string > readUUID(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:322
void parseLink(unsigned id, std::string &url)
Definition IWAParser.cpp:3412
friend class IWAObjectIndex
Definition IWAParser.h:51
const IWORKStylePtr_t queryListStyle(unsigned id) const
Definition IWAParser.cpp:985
static std::deque< unsigned > readRefs(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:252
bool parseDrawableShape(const IWAMessage &msg, bool isConnectionLine=false)
Definition IWAParser.cpp:1216
static boost::optional< uint64_t > readUID(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:300
IWAObjectIndex m_index
Definition IWAParser.h:231
static boost::optional< IWORKPosition > readPosition(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:267
friend class ObjectMessage
Definition IWAParser.h:87
void parsePageMaster(unsigned id, PageMaster &pageMaster)
Definition IWAParser.cpp:2213
const IWORKStylePtr_t queryCellStyle(unsigned id) const
Definition IWAParser.cpp:975
void parseMediaStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1806
bool dispatchShape(unsigned id)
Definition IWAParser.cpp:542
IWAParser & operator=(const IWAParser &)
std::deque< unsigned > m_visited
Definition IWAParser.h:233
bool parseFormat(const IWAMessage &msg, Format &format)
Definition IWAParser.cpp:2980
void parseTableHeaders(unsigned id, TableHeader &header)
Definition IWAParser.cpp:2898
static std::deque< uint64_t > readUIDs(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:310
bool parseAttachment(unsigned id)
Definition IWAParser.cpp:990
bool parseArrowProperties(const IWAMessage &msg, IWORKPropertyMap &props, bool headArrow)
Definition IWAParser.cpp:1087
void parseCustomFormat(unsigned id)
Definition IWAParser.cpp:3093
void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1714
static void readShadow(const IWAMessage &msg, IWORKShadow &shadow)
Definition IWAParser.cpp:516
void parseMask(unsigned id, IWORKGeometryPtr_t &geometry, IWORKPathPtr_t &path)
Definition IWAParser.cpp:1549
bool parsePath(const IWAMessage &msg, IWORKPathPtr_t &path)
Definition IWAParser.cpp:1120
void parseListStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1973
void parseObjectIndex()
Definition IWAParser.cpp:1562
void parseComment(unsigned id)
Definition IWAParser.cpp:2367
virtual bool parseStickyNote(const IWAMessage &msg)
Definition IWAParser.cpp:1210
static void readGradient(const IWAMessage &msg, IWORKGradient &gradient)
Definition IWAParser.cpp:483
static boost::optional< IWORKSize > readSize(const IWAMessage &msg, unsigned field)
Definition IWAParser.cpp:278
IWORKTableNameMapPtr_t m_tableNameMap
Definition IWAParser.h:133
IWAParser(const IWAParser &)
StyleMap_t m_charStyles
Definition IWAParser.h:235
StyleMap_t m_listStyles
Definition IWAParser.h:243
void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style)
Definition IWAParser.cpp:1567
virtual bool parseDocument()=0
std::map< uint64_t, Format > m_uidFormatMap
Definition IWAParser.h:246
IWORKCollector & m_collector
Definition IWAParser.h:229
Definition IWORKCollector.h:42
Definition IWORKLanguageManager.h:24
Represents a (hierarchical) property map.
Definition IWORKPropertyMap.h:25
Definition IWORKTable.h:32
Definition IWORKText.h:34
@ fill
Definition IWORKToken.h:204
@ padding
Definition IWORKToken.h:349
@ format
Definition IWORKToken.h:537
@ rows
Definition IWORKToken.h:392
@ type
Definition IWORKToken.h:493
@ 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::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:43
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition IWORKStyle_fwd.h:23
std::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition IWORKTypes_fwd.h:34
Definition IWAParser.h:138
Format()
Definition IWAParser.cpp:115
boost::optional< IWORKCellType > m_type
Definition IWAParser.h:140
boost::variant< IWORKNumberFormat, IWORKDateTimeFormat, IWORKDurationFormat > m_format
Definition IWAParser.h:141
Definition IWAParser.h:145
PageMaster()
Definition IWAParser.cpp:121
bool m_headerFootersSameAsPrevious
Definition IWAParser.h:148
IWORKStylePtr_t m_style
Definition IWAParser.h:147
Definition IWAParser.h:152
mdds::flat_segment_tree< unsigned, bool > m_hidden
Definition IWAParser.h:156
mdds::flat_segment_tree< unsigned, float > m_sizes
Definition IWAParser.h:155
TableHeader(unsigned count, float defValue=0)
Definition IWAParser.cpp:127
TableInfo(const std::shared_ptr< IWORKTable > &table, unsigned columns, unsigned rows)
Definition IWAParser.cpp:133
DataList_t m_formatList
Definition IWAParser.h:179
DataList_t m_simpleTextList
Definition IWAParser.h:175
TableHeader m_columnHeader
Definition IWAParser.h:172
DataList_t m_formattedTextList
Definition IWAParser.h:177
DataList_t m_formulaList
Definition IWAParser.h:178
DataList_t m_commentList
Definition IWAParser.h:180
DataList_t m_cellStyleList
Definition IWAParser.h:176
TableHeader m_rowHeader
Definition IWAParser.h:173
IWORKStylePtr_t m_style
Definition IWAParser.h:170
const unsigned m_rows
Definition IWAParser.h:168
const unsigned m_columns
Definition IWAParser.h:167
std::shared_ptr< IWORKTable > m_table
Definition IWAParser.h:165
Definition IWORKTypes.h:62
Definition IWORKTypes.h:300
Definition IWORKTypes.h:100
Definition IWORKTypes.h:358
Definition IWORKTypes.h:313
Definition IWORKTypes.h:278

Generated for libetonyek by doxygen 1.13.2