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"
35 #include "IWORKLanguageManager.h"
36 #include "IWORKOutputElements.h"
37 #include "IWORKStyle_fwd.h"
38 #include "IWORKTypes.h"
39 
40 namespace libetonyek
41 {
42 
43 class IWORKCollector;
44 class IWAObjectIndex;
45 class IWORKPropertyMap;
46 class IWORKTable;
47 class IWORKText;
48 
49 class IWAParser
50 {
51  friend class IWAObjectIndex; // for readColor
52 
53  // disable copying
54  IWAParser(const IWAParser &);
55  IWAParser &operator=(const IWAParser &);
56 public:
57  IWAParser(const RVNGInputStreamPtr_t &fragments, const RVNGInputStreamPtr_t &package, IWORKCollector &collector);
58  virtual ~IWAParser()
59  {
60  }
61 
62  bool parse();
63 
64 protected:
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 
92 protected:
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 
131 protected:
134  std::shared_ptr<IWORKText> m_currentText;
135 
136 private:
137  struct Format
138  {
139  Format();
140  boost::optional<IWORKCellType> m_type;
141  boost::variant<IWORKNumberFormat,IWORKDateTimeFormat,IWORKDurationFormat> m_format;
142  };
143 
144  struct PageMaster
145  {
146  PageMaster();
149  };
150 
151  struct TableHeader
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 
161  struct TableInfo
162  {
163  TableInfo(const std::shared_ptr<IWORKTable> &table, unsigned columns, unsigned rows);
164 
165  std::shared_ptr<IWORKTable> m_table;
166 
167  const unsigned m_columns;
168  const unsigned m_rows;
169 
171 
174 
181  };
182 
183 private:
184  virtual bool parseDocument() = 0;
185 
186 private:
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);
225  void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props);
226  void parseColumnsProperties(const IWAMessage &msg, IWORKPropertyMap &props);
227 
228 private:
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: */
void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1567
virtual ~IWAParser()
Definition: IWAParser.h:58
std::shared_ptr< IWORKGeometry > IWORKGeometryPtr_t
Definition: IWORKTypes_fwd.h:41
DataList_t m_commentList
Definition: IWAParser.h:180
std::shared_ptr< IWORKTable > m_table
Definition: IWAParser.h:165
static boost::optional< IWORKColor > readColor(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:289
Definition: IWORKTypes.h:299
Definition: IWORKToken.h:365
IWAObjectIndex m_index
Definition: IWAParser.h:231
static void readStroke(const IWAMessage &msg, IWORKStroke &stroke)
Definition: IWAParser.cpp:357
static boost::optional< unsigned > readRef(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:245
std::deque< unsigned > m_visited
Definition: IWAParser.h:233
bool parseFormula(const IWAMessage &msg, IWORKFormulaPtr_t &formula)
Definition: IWAParser.cpp:3119
const IWORKStylePtr_t queryCharacterStyle(unsigned id) const
Definition: IWAParser.cpp:950
Definition: IWORKTypes.h:277
void parseComment(unsigned id)
Definition: IWAParser.cpp:2367
StyleMap_t m_paraStyles
Definition: IWAParser.h:236
const unsigned m_columns
Definition: IWAParser.h:167
std::shared_ptr< IWORKText > m_currentText
Definition: IWAParser.h:134
const IWORKStylePtr_t queryGraphicStyle(unsigned id) const
Definition: IWAParser.cpp:965
IWAParser & m_parser
Definition: IWAParser.h:82
const unsigned m_rows
Definition: IWAParser.h:168
DataList_t m_formattedTextList
Definition: IWAParser.h:177
void parseTabularModel(unsigned id)
Definition: IWAParser.cpp:2412
Represents a (hierarchical) property map.
Definition: IWORKPropertyMap.h:24
IWORKTableNameMapPtr_t m_tableNameMap
Definition: IWAParser.h:133
const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const
Definition: IWAParser.cpp:937
static boost::optional< IWORKSize > readSize(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:278
static std::deque< unsigned > readRefs(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:252
void parseCustomFormat(unsigned id)
Definition: IWAParser.cpp:3093
Definition: IWAParser.h:151
PageMaster()
Definition: IWAParser.cpp:121
DataList_t m_cellStyleList
Definition: IWAParser.h:176
void parseTableGridLine(unsigned id, IWORKGridLineMap_t &gridLines)
Definition: IWAParser.cpp:2944
std::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition: IWAParser.cpp:2130
std::map< unsigned, boost::variant< std::string, unsigned, IWORKFormulaPtr_t, Format > > DataList_t
Definition: IWAParser.h:159
boost::optional< IWORKCellType > m_type
Definition: IWAParser.h:140
StyleMap_t m_sectionStyles
Definition: IWAParser.h:237
void parsePageMaster(unsigned id, PageMaster &pageMaster)
Definition: IWAParser.cpp:2213
static void readShadow(const IWAMessage &msg, IWORKShadow &shadow)
Definition: IWAParser.cpp:516
bool m_headerFootersSameAsPrevious
Definition: IWAParser.h:148
IWORKCollector & m_collector
Definition: IWAParser.h:229
const RVNGInputStreamPtr_t queryFile(unsigned id) const
Definition: IWAParser.cpp:240
IWAParser(const IWAParser &)
bool parseImage(const IWAMessage &msg)
Definition: IWAParser.cpp:2288
std::function< void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t
Definition: IWAParser.h:90
IWORKStylePtr_t m_style
Definition: IWAParser.h:170
TableHeader m_columnHeader
Definition: IWAParser.h:172
Definition: IWAParser.h:144
const IWORKStylePtr_t queryMediaStyle(unsigned id) const
Definition: IWAParser.cpp:970
bool parseDrawableShape(const IWAMessage &msg, bool isConnectionLine=false)
Definition: IWAParser.cpp:1216
StyleMap_t m_tableStyles
Definition: IWAParser.h:242
boost::optional< IWAMessage > m_message
Definition: IWAParser.h:83
Definition: IWAParser.h:65
bool parsePath(const IWAMessage &msg, IWORKPathPtr_t &path)
Definition: IWAParser.cpp:1120
IWORKStylePtr_t m_style
Definition: IWAParser.h:147
bool parseGroup(const IWAMessage &msg)
Definition: IWAParser.cpp:1487
Definition: KEY1Token.h:198
Format()
Definition: IWAParser.cpp:115
virtual bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry, boost::optional< unsigned > &flags)
Definition: IWAParser.cpp:1506
bool parseArrowProperties(const IWAMessage &msg, IWORKPropertyMap &props, bool headArrow)
Definition: IWAParser.cpp:1087
ObjectMessage(IWAParser &parser, unsigned id, unsigned type=0)
Definition: IWAParser.cpp:175
void parseHeaderAndFooter(unsigned id, IWORKPageMaster &hf)
Definition: IWAParser.cpp:2251
bool parseTabularInfo(const IWAMessage &msg)
Definition: IWAParser.cpp:2400
StyleMap_t m_cellStyles
Definition: IWAParser.h:241
static void readGradient(const IWAMessage &msg, IWORKGradient &gradient)
Definition: IWAParser.cpp:483
static boost::optional< uint64_t > readUID(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:300
bool readFill(const IWAMessage &msg, IWORKFill &fill)
Definition: IWAParser.cpp:424
Definition: IWAObjectIndex.h:26
Definition: IWORKTypes.h:99
Definition: IWORKToken.h:421
unsigned m_type
Definition: IWAParser.h:85
unsigned getType() const
Definition: IWAParser.cpp:225
Definition: IWAParser.h:161
void parseMediaStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1806
boost::variant< IWORKNumberFormat, IWORKDateTimeFormat, IWORKDurationFormat > m_format
Definition: IWAParser.h:141
Definition: IWORKToken.h:392
Definition: IWORKCollector.h:41
void parseLink(unsigned id, std::string &url)
Definition: IWAParser.cpp:3412
std::shared_ptr< IWORKFormula > IWORKFormulaPtr_t
Definition: IWORKTypes.h:123
StyleMap_t m_listStyles
Definition: IWAParser.h:243
const IWORKStylePtr_t querySectionStyle(unsigned id) const
Definition: IWAParser.cpp:960
Definition: IWORKToken.h:349
void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1591
Definition: IWORKTypes.h:312
static std::deque< uint64_t > readUIDs(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:310
StyleMap_t m_charStyles
Definition: IWAParser.h:235
std::map< uint64_t, Format > m_uidFormatMap
Definition: IWAParser.h:246
mdds::flat_segment_tree< unsigned, bool > m_hidden
Definition: IWAParser.h:156
void parseColumnsProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition: IWAParser.cpp:2170
bool parseFormat(const IWAMessage &msg, Format &format)
Definition: IWAParser.cpp:2980
TableHeader(unsigned count, float defValue=0)
Definition: IWAParser.cpp:127
bool parseText(unsigned id, bool createNoteAsFootnote=true, const std::function< void(unsigned, IWORKStylePtr_t)> &openPageSpan=nullptr)
Definition: IWAParser.cpp:633
Definition: IWORKToken.h:158
StyleMap_t m_mediaStyles
Definition: IWAParser.h:240
std::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libetonyek_utils.h:82
Definition: IWORKToken.h:236
Definition: IWAParser.h:137
IWORKLanguageManager m_langManager
Definition: IWAParser.h:132
Definition: KEY1Token.h:58
void parseCellStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1846
std::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition: IWORKTypes_fwd.h:34
std::map< unsigned, IWORKGridLine_t > IWORKGridLineMap_t
Definition: IWORKTypes.h:122
void queryObject(unsigned id, unsigned &type, boost::optional< IWAMessage > &msg) const
Definition: IWAParser.cpp:230
void parseTile(unsigned id)
Definition: IWAParser.cpp:2651
void parseListStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1973
Definition: IWORKToken.h:537
void parseSectionStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1690
StyleMap_t m_graphicStyles
Definition: IWAParser.h:239
virtual bool parseStickyNote(const IWAMessage &msg)
Definition: IWAParser.cpp:1210
Definition: IWORKLanguageManager.h:23
void parseObjectIndex()
Definition: IWAParser.cpp:1562
Definition: IWORKTypes.h:357
Definition: IWORKTypes.h:61
Definition: IWORKToken.h:256
void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1714
static boost::optional< std::string > readUUID(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:322
void parseTableHeaders(unsigned id, TableHeader &header)
Definition: IWAParser.cpp:2898
bool dispatchShapeWithMessage(const IWAMessage &msg, unsigned type)
Definition: IWAParser.cpp:550
Definition: IWORKToken.h:418
Definition: IWORKToken.h:228
DataList_t m_simpleTextList
Definition: IWAParser.h:175
boost::optional< unsigned > getObjectType(unsigned id) const
Definition: IWAParser.cpp:235
Definition: IWORKToken.h:534
std::shared_ptr< IWORKPath > IWORKPathPtr_t
Definition: IWORKPath_fwd.h:20
std::map< unsigned, IWORKStylePtr_t > StyleMap_t
Definition: IWAParser.h:89
void parseTableStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1929
bool dispatchShape(unsigned id)
Definition: IWAParser.cpp:542
IWAParser & operator=(const IWAParser &)
void updateGeometryUsingTextRef(unsigned id, IWORKGeometry &geometry, unsigned flags)
Definition: IWAParser.cpp:579
void parseMask(unsigned id, IWORKGeometryPtr_t &geometry, IWORKPathPtr_t &path)
Definition: IWAParser.cpp:1549
virtual bool parseDocument()=0
Definition: IWAMessage.h:21
void parseAuthorInComment(unsigned id)
Definition: IWAParser.cpp:2342
boost::variant< IWORKColor, IWORKGradient, IWORKMediaContent > IWORKFill
Definition: IWORKTypes.h:309
TableHeader m_rowHeader
Definition: IWAParser.h:173
DataList_t m_formatList
Definition: IWAParser.h:179
DataList_t m_formulaList
Definition: IWAParser.h:178
Definition: IWAParser.h:49
const IWORKStylePtr_t queryParagraphStyle(unsigned id) const
Definition: IWAParser.cpp:955
Definition: IWORKToken.h:493
static void readPadding(const IWAMessage &msg, IWORKPadding &padding)
Definition: IWAParser.cpp:534
void parseDataList(unsigned id, DataList_t &dataList)
Definition: IWAParser.cpp:2561
~ObjectMessage()
Definition: IWAParser.cpp:205
bool parseAttachment(unsigned id)
Definition: IWAParser.cpp:990
void parseTableGridLines(unsigned id, IWORKGridLineMap_t(&gridLines)[4])
Definition: IWAParser.cpp:2922
TableInfo(const std::shared_ptr< IWORKTable > &table, unsigned columns, unsigned rows)
Definition: IWAParser.cpp:133
Definition: IWORKToken.h:419
const IWORKStylePtr_t queryListStyle(unsigned id) const
Definition: IWAParser.cpp:985
Definition: IWORKToken.h:522
static boost::optional< IWORKPosition > readPosition(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:267
const IWORKStylePtr_t queryTableStyle(unsigned id) const
Definition: IWAParser.cpp:980
Definition: IWORKToken.h:204
const unsigned m_id
Definition: IWAParser.h:84
bool parse()
Definition: IWAParser.cpp:169
std::shared_ptr< TableInfo > m_currentTable
Definition: IWAParser.h:245
const IWORKStylePtr_t queryCellStyle(unsigned id) const
Definition: IWAParser.cpp:975
mdds::flat_segment_tree< unsigned, float > m_sizes
Definition: IWAParser.h:155

Generated for libetonyek by doxygen 1.8.6