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 <map>
15 #include <string>
16 
17 #include <boost/function.hpp>
18 #include <boost/optional.hpp>
19 #include <boost/shared_ptr.hpp>
20 #include <boost/unordered_map.hpp>
21 #include <boost/variant.hpp>
22 
23 #include <mdds/flat_segment_tree.hpp>
24 
25 #include "libetonyek_utils.h"
26 #include "IWAMessage.h"
27 #include "IWORKStyle_fwd.h"
28 #include "IWORKTypes.h"
29 
30 namespace libetonyek
31 {
32 
33 class IWORKCollector;
34 class IWORKPropertyMap;
35 class IWORKTable;
36 class IWORKText;
37 
38 class IWAParser
39 {
40  // disable copying
41  IWAParser(const IWAParser &);
42  IWAParser &operator=(const IWAParser &);
43 
44 public:
45  struct ObjectRecord
46  {
47  ObjectRecord();
48  ObjectRecord(const RVNGInputStreamPtr_t &stream, unsigned type, long pos, unsigned long headerLen, unsigned long dataLen);
49 
51  unsigned m_type;
52  std::pair<long, long> m_headerRange;
53  std::pair<long, long> m_dataRange;
54  };
55 
56  typedef std::map<unsigned, std::pair<std::string, RVNGInputStreamPtr_t> > FileMap_t;
57  typedef std::map<unsigned, std::pair<unsigned, ObjectRecord> > RecordMap_t;
58 
59 public:
60  IWAParser(const RVNGInputStreamPtr_t &fragments, const RVNGInputStreamPtr_t &package, IWORKCollector &collector);
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 boost::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 void readStroke(const IWAMessage &msg, IWORKStroke &stroke);
99  bool readFill(const IWAMessage &msg, IWORKFill &fill);
100  static void readGradient(const IWAMessage &msg, IWORKGradient &gradient);
101  static void readShadow(const IWAMessage &msg, IWORKShadow &shadow);
102  static void readPadding(const IWAMessage &msg, IWORKPadding &padding);
103 
104  bool dispatchShape(unsigned id);
105  bool parseText(unsigned id);
106  void parseComment(unsigned id);
107 
109 
110  const IWORKStylePtr_t queryCharacterStyle(unsigned id) const;
111  const IWORKStylePtr_t queryParagraphStyle(unsigned id) const;
112  const IWORKStylePtr_t queryGraphicStyle(unsigned id) const;
113  const IWORKStylePtr_t queryCellStyle(unsigned id) const;
114  const IWORKStylePtr_t queryTableStyle(unsigned id) const;
115 
116  const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const;
117 
118 protected:
119  boost::shared_ptr<IWORKText> m_currentText;
120 
121 private:
122  typedef std::map<unsigned, boost::variant<std::string, unsigned> > DataList_t;
123 
124  struct TableHeader
125  {
126  TableHeader(unsigned count);
127 
128  mdds::flat_segment_tree<unsigned, float> m_sizes;
129  mdds::flat_segment_tree<unsigned, bool> m_hidden;
130  };
131 
132  struct TableInfo
133  {
134  TableInfo(const boost::shared_ptr<IWORKTable> &table, unsigned columns, unsigned rows);
135 
136  boost::shared_ptr<IWORKTable> m_table;
137 
138  const unsigned m_columns;
139  const unsigned m_rows;
140 
142 
145 
146  DataList_t m_simpleTextList;
147  DataList_t m_cellStyleList;
149  DataList_t m_commentList;
150  };
151 
152 private:
153  virtual bool parseDocument() = 0;
154 
155 private:
156  void queryObject(unsigned id, unsigned &type, boost::optional<IWAMessage> &msg) const;
157  const RVNGInputStreamPtr_t queryFile(unsigned id) const;
158 
159  void parseObjectIndex();
160 
161  void scanFragment(unsigned id);
162  void scanFragment(unsigned id, const RVNGInputStreamPtr_t &stream);
163 
164  void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style);
165  void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style);
166  void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style);
167  void parseCellStyle(unsigned id, IWORKStylePtr_t &style);
168  void parseTableStyle(unsigned id, IWORKStylePtr_t &style);
169 
170  void parseTabularModel(unsigned id);
171  void parseDataList(unsigned id, DataList_t &dataList);
172  void parseTile(unsigned id);
173  void parseHeaders(unsigned id, TableHeader &header);
174 
175  bool parseDrawableShape(const IWAMessage &msg);
176  bool parseGroup(const IWAMessage &msg);
177  bool parseShapePlacement(const IWAMessage &msg);
178  void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props);
179  bool parseImage(const IWAMessage &msg);
180  bool parseTabularInfo(const IWAMessage &msg);
181 
182 private:
186 
187  FileMap_t m_fragmentMap;
188  mutable RecordMap_t m_fragmentObjectMap;
189  mutable FileMap_t m_fileMap;
190 
191  std::deque<unsigned> m_visited;
192 
193  mutable StyleMap_t m_charStyles;
194  mutable StyleMap_t m_paraStyles;
195  mutable StyleMap_t m_graphicStyles;
196  mutable StyleMap_t m_cellStyles;
197  mutable StyleMap_t m_tableStyles;
198 
200  boost::shared_ptr<TableInfo> m_currentTable;
201 };
202 
203 }
204 
205 #endif
206 
207 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1089
Definition: IWORKBezierElement.cpp:18
DataList_t m_commentList
Definition: IWAParser.h:149
static boost::optional< IWORKColor > readColor(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:363
Definition: IWORKTypes.h:222
std::pair< long, long > m_headerRange
Definition: IWAParser.h:52
static void readStroke(const IWAMessage &msg, IWORKStroke &stroke)
Definition: IWAParser.cpp:374
static boost::optional< unsigned > readRef(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:319
std::deque< unsigned > m_visited
Definition: IWAParser.h:191
RVNGInputStreamPtr_t m_stream
Definition: IWAParser.h:50
const IWORKStylePtr_t queryCharacterStyle(unsigned id) const
Definition: IWAParser.cpp:660
Definition: IWORKTypes.h:201
void parseComment(unsigned id)
Definition: IWAParser.cpp:1440
StyleMap_t m_paraStyles
Definition: IWAParser.h:194
const unsigned m_columns
Definition: IWAParser.h:138
const IWORKStylePtr_t queryGraphicStyle(unsigned id) const
Definition: IWAParser.cpp:670
boost::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
IWAParser & m_parser
Definition: IWAParser.h:82
const unsigned m_rows
Definition: IWAParser.h:139
DataList_t m_formattedTextList
Definition: IWAParser.h:148
void parseTabularModel(unsigned id)
Definition: IWAParser.cpp:1469
Represents a (hierarchical) property map.
Definition: IWORKPropertyMap.h:23
IWORKTableNameMapPtr_t m_tableNameMap
Definition: IWAParser.h:199
const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const
Definition: IWAParser.cpp:647
static boost::optional< IWORKSize > readSize(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:352
boost::function< void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t
Definition: IWAParser.h:90
static std::deque< unsigned > readRefs(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:326
Definition: IWAParser.h:124
const RVNGInputStreamPtr_t m_fragments
Definition: IWAParser.h:183
void parseHeaders(unsigned id, TableHeader &header)
Definition: IWAParser.cpp:1799
void scanFragment(unsigned id)
Definition: IWAParser.cpp:1025
DataList_t m_cellStyleList
Definition: IWAParser.h:147
void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition: IWAParser.cpp:1369
bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry)
Definition: IWAParser.cpp:927
TableInfo(const boost::shared_ptr< IWORKTable > &table, unsigned columns, unsigned rows)
Definition: IWAParser.cpp:203
static void readShadow(const IWAMessage &msg, IWORKShadow &shadow)
Definition: IWAParser.cpp:518
IWORKCollector & m_collector
Definition: IWAParser.h:185
const RVNGInputStreamPtr_t queryFile(unsigned id) const
Definition: IWAParser.cpp:299
IWAParser(const IWAParser &)
boost::shared_ptr< IWORKGeometry > IWORKGeometryPtr_t
Definition: IWORKTypes_fwd.h:40
bool parseImage(const IWAMessage &msg)
Definition: IWAParser.cpp:1400
const RVNGInputStreamPtr_t m_package
Definition: IWAParser.h:184
IWORKStylePtr_t m_style
Definition: IWAParser.h:141
TableHeader m_columnHeader
Definition: IWAParser.h:143
StyleMap_t m_tableStyles
Definition: IWAParser.h:197
boost::optional< IWAMessage > m_message
Definition: IWAParser.h:83
Definition: IWAParser.h:65
bool parseGroup(const IWAMessage &msg)
Definition: IWAParser.cpp:910
ObjectMessage(IWAParser &parser, unsigned id, unsigned type=0)
Definition: IWAParser.cpp:230
std::pair< long, long > m_dataRange
Definition: IWAParser.h:53
bool parseTabularInfo(const IWAMessage &msg)
Definition: IWAParser.cpp:1459
bool parseDrawableShape(const IWAMessage &msg)
Definition: IWAParser.cpp:685
StyleMap_t m_cellStyles
Definition: IWAParser.h:196
static void readGradient(const IWAMessage &msg, IWORKGradient &gradient)
Definition: IWAParser.cpp:485
bool readFill(const IWAMessage &msg, IWORKFill &fill)
Definition: IWAParser.cpp:428
Definition: IWORKTypes.h:81
bool parseText(unsigned id)
Definition: IWAParser.cpp:560
Definition: IWORKToken.h:241
unsigned m_type
Definition: IWAParser.h:85
unsigned getType() const
Definition: IWAParser.cpp:276
Definition: IWAParser.h:132
FileMap_t m_fileMap
Definition: IWAParser.h:189
std::map< unsigned, std::pair< unsigned, ObjectRecord > > RecordMap_t
Definition: IWAParser.h:57
Definition: IWORKToken.h:218
RecordMap_t m_fragmentObjectMap
Definition: IWAParser.h:188
Definition: IWORKCollector.h:40
Definition: IWORKToken.h:194
void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1113
ObjectRecord()
Definition: IWAParser.cpp:180
Definition: IWORKTypes.h:244
std::map< unsigned, boost::variant< std::string, unsigned > > DataList_t
Definition: IWAParser.h:122
StyleMap_t m_charStyles
Definition: IWAParser.h:193
boost::variant< IWORKColor, IWORKGradient, IWORKFillImage > IWORKFill
Definition: IWORKTypes.h:242
mdds::flat_segment_tree< unsigned, bool > m_hidden
Definition: IWAParser.h:129
unsigned m_type
Definition: IWAParser.h:51
FileMap_t m_fragmentMap
Definition: IWAParser.h:187
Definition: IWORKToken.h:79
Definition: IWORKToken.h:136
boost::shared_ptr< IWORKText > m_currentText
Definition: IWAParser.h:119
boost::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition: IWORKTypes_fwd.h:33
Definition: KEY1Token.h:53
void parseCellStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1258
void queryObject(unsigned id, unsigned &type, boost::optional< IWAMessage > &msg) const
Definition: IWAParser.cpp:281
void parseTile(unsigned id)
Definition: IWAParser.cpp:1623
StyleMap_t m_graphicStyles
Definition: IWAParser.h:195
void parseObjectIndex()
Definition: IWAParser.cpp:974
boost::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libetonyek_utils.h:111
Definition: IWORKToken.h:146
void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1191
DataList_t m_simpleTextList
Definition: IWAParser.h:146
std::map< unsigned, IWORKStylePtr_t > StyleMap_t
Definition: IWAParser.h:89
void parseTableStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1325
bool dispatchShape(unsigned id)
Definition: IWAParser.cpp:539
IWAParser & operator=(const IWAParser &)
virtual bool parseDocument()=0
Definition: IWAMessage.h:21
boost::shared_ptr< TableInfo > m_currentTable
Definition: IWAParser.h:200
TableHeader m_rowHeader
Definition: IWAParser.h:144
TableHeader(unsigned count)
Definition: IWAParser.cpp:197
Definition: IWAParser.h:38
const IWORKStylePtr_t queryParagraphStyle(unsigned id) const
Definition: IWAParser.cpp:665
Definition: IWORKToken.h:266
static void readPadding(const IWAMessage &msg, IWORKPadding &padding)
Definition: IWAParser.cpp:531
void parseDataList(unsigned id, DataList_t &dataList)
Definition: IWAParser.cpp:1582
~ObjectMessage()
Definition: IWAParser.cpp:256
std::map< unsigned, std::pair< std::string, RVNGInputStreamPtr_t > > FileMap_t
Definition: IWAParser.h:56
Definition: IWORKToken.h:240
boost::shared_ptr< IWORKTable > m_table
Definition: IWAParser.h:136
static boost::optional< IWORKPosition > readPosition(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:341
const IWORKStylePtr_t queryTableStyle(unsigned id) const
Definition: IWAParser.cpp:680
Definition: IWORKToken.h:315
Definition: IWORKToken.h:105
Definition: IWAParser.h:45
const unsigned m_id
Definition: IWAParser.h:84
bool parse()
Definition: IWAParser.cpp:224
const IWORKStylePtr_t queryCellStyle(unsigned id) const
Definition: IWAParser.cpp:675
mdds::flat_segment_tree< unsigned, float > m_sizes
Definition: IWAParser.h:128

Generated for libetonyek by doxygen 1.8.10