IWAParser.h Source File documentation

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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 "IWORKLanguageManager.h"
28 #include "IWORKStyle_fwd.h"
29 #include "IWORKTypes.h"
30
31 namespace libetonyek
32 {
33
34 class IWORKCollector;
35 class IWORKPropertyMap;
36 class IWORKTable;
37 class IWORKText;
38
39 class IWAParser
40 {
41 // disable copying
42 IWAParser(const IWAParser &);
43 IWAParser &operator=(const IWAParser &);
44
45 public:
46 struct ObjectRecord
47 {
48 ObjectRecord();
49 ObjectRecord(const RVNGInputStreamPtr_t &stream, unsigned type, long pos, unsigned long headerLen, unsigned long dataLen);
50
51 RVNGInputStreamPtr_t m_stream;
52 unsigned m_type;
53 std::pair<long, long> m_headerRange;
54 std::pair<long, long> m_dataRange;
55 };
56
57 typedef std::map<unsigned, std::pair<std::string, RVNGInputStreamPtr_t> > FileMap_t;
58 typedef std::map<unsigned, std::pair<unsigned, ObjectRecord> > RecordMap_t;
59
60 public:
61 IWAParser(const RVNGInputStreamPtr_t &fragments, const RVNGInputStreamPtr_t &package, IWORKCollector &collector);
62
63 bool parse();
64
65 protected:
66 class ObjectMessage
67 {
68 public:
69 ObjectMessage(IWAParser &parser, unsigned id, unsigned type = 0);
70 ~ObjectMessage();
71
72 operator bool() const;
73 const IWAMessage &get() const;
74
75 unsigned getType() const;
76
77 friend const IWAMessage &get(const ObjectMessage &msg)
78 {
79 return msg.get();
80 }
81
82 private:
83 IWAParser &m_parser;
84 boost::optional<IWAMessage> m_message;
85 const unsigned m_id;
86 unsigned m_type;
87 };
88 friend class ObjectMessage;
89
90 typedef std::map<unsigned, IWORKStylePtr_t> StyleMap_t;
91 typedef boost::function<void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t;
92
93 protected:
94 static boost::optional<unsigned> readRef(const IWAMessage &msg, unsigned field);
95 static std::deque<unsigned> readRefs(const IWAMessage &msg, unsigned field);
96 static boost::optional<IWORKPosition> readPosition(const IWAMessage &msg, unsigned field);
97 static boost::optional<IWORKSize> readSize(const IWAMessage &msg, unsigned field);
98 static boost::optional<IWORKColor> readColor(const IWAMessage &msg, unsigned field);
99 static void readStroke(const IWAMessage &msg, IWORKStroke &stroke);
100 bool readFill(const IWAMessage &msg, IWORKFill &fill);
101 static void readGradient(const IWAMessage &msg, IWORKGradient &gradient);
102 static void readShadow(const IWAMessage &msg, IWORKShadow &shadow);
103 static void readPadding(const IWAMessage &msg, IWORKPadding &padding);
104
105 bool dispatchShape(unsigned id);
106 bool parseText(unsigned id);
107 void parseComment(unsigned id);
108
109 bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry);
110
111 const IWORKStylePtr_t queryCharacterStyle(unsigned id) const;
112 const IWORKStylePtr_t queryParagraphStyle(unsigned id) const;
113 const IWORKStylePtr_t queryGraphicStyle(unsigned id) const;
114 const IWORKStylePtr_t queryCellStyle(unsigned id) const;
115 const IWORKStylePtr_t queryTableStyle(unsigned id) const;
116 const IWORKStylePtr_t queryListStyle(unsigned id) const;
117
118 const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const;
119
120 protected:
121 IWORKLanguageManager m_langManager;
122 boost::shared_ptr<IWORKText> m_currentText;
123
124 private:
125 typedef std::map<unsigned, boost::variant<std::string, unsigned> > DataList_t;
126
127 struct TableHeader
128 {
129 TableHeader(unsigned count);
130
131 mdds::flat_segment_tree<unsigned, float> m_sizes;
132 mdds::flat_segment_tree<unsigned, bool> m_hidden;
133 };
134
135 struct TableInfo
136 {
137 TableInfo(const boost::shared_ptr<IWORKTable> &table, unsigned columns, unsigned rows);
138
139 boost::shared_ptr<IWORKTable> m_table;
140
141 const unsigned m_columns;
142 const unsigned m_rows;
143
144 IWORKStylePtr_t m_style;
145
146 TableHeader m_columnHeader;
147 TableHeader m_rowHeader;
148
149 DataList_t m_simpleTextList;
150 DataList_t m_cellStyleList;
151 DataList_t m_formattedTextList;
152 DataList_t m_commentList;
153 };
154
155 private:
156 virtual bool parseDocument() = 0;
157
158 private:
159 void queryObject(unsigned id, unsigned &type, boost::optional<IWAMessage> &msg) const;
160 const RVNGInputStreamPtr_t queryFile(unsigned id) const;
161
162 void parseObjectIndex();
163
164 void scanFragment(unsigned id);
165 void scanFragment(unsigned id, const RVNGInputStreamPtr_t &stream);
166
167 void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style);
168 void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style);
169 void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style);
170 void parseCellStyle(unsigned id, IWORKStylePtr_t &style);
171 void parseTableStyle(unsigned id, IWORKStylePtr_t &style);
172 void parseListStyle(unsigned id, IWORKStylePtr_t &style);
173
174 void parseTabularModel(unsigned id);
175 void parseDataList(unsigned id, DataList_t &dataList);
176 void parseTile(unsigned id);
177 void parseHeaders(unsigned id, TableHeader &header);
178
179 void parseLink(unsigned id, std::string &url);
180
181 bool parseDrawableShape(const IWAMessage &msg);
182 bool parseGroup(const IWAMessage &msg);
183 bool parseShapePlacement(const IWAMessage &msg);
184 void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props);
185 bool parseImage(const IWAMessage &msg);
186 bool parseTabularInfo(const IWAMessage &msg);
187
188 private:
189 const RVNGInputStreamPtr_t m_fragments;
190 const RVNGInputStreamPtr_t m_package;
191 IWORKCollector &m_collector;
192
193 FileMap_t m_fragmentMap;
194 mutable RecordMap_t m_fragmentObjectMap;
195 mutable FileMap_t m_fileMap;
196
197 std::deque<unsigned> m_visited;
198
199 mutable StyleMap_t m_charStyles;
200 mutable StyleMap_t m_paraStyles;
201 mutable StyleMap_t m_graphicStyles;
202 mutable StyleMap_t m_cellStyles;
203 mutable StyleMap_t m_tableStyles;
204 mutable StyleMap_t m_listStyles;
205
206 IWORKTableNameMapPtr_t m_tableNameMap;
207 boost::shared_ptr<TableInfo> m_currentTable;
208 };
209
210 }
211
212 #endif
213
214 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek::IWAParser::parseCharacterStyle
void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1073
IWORKStyle_fwd.h
IWORKLanguageManager.h
libetonyek
Definition: IWORKBezierElement.cpp:18
libetonyek::IWAParser::TableInfo::m_commentList
DataList_t m_commentList
Definition: IWAParser.h:152
libetonyek::IWAParser::readColor
static boost::optional< IWORKColor > readColor(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:315
libetonyek::IWORKGradient
Definition: IWORKTypes.h:223
libetonyek::IWAParser::ObjectRecord::m_headerRange
std::pair< long, long > m_headerRange
Definition: IWAParser.h:53
libetonyek::IWAParser::readStroke
static void readStroke(const IWAMessage &msg, IWORKStroke &stroke)
Definition: IWAParser.cpp:326
libetonyek::IWAParser::readRef
static boost::optional< unsigned > readRef(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:271
libetonyek::IWAParser::m_visited
std::deque< unsigned > m_visited
Definition: IWAParser.h:197
libetonyek::IWAParser::ObjectRecord::m_stream
RVNGInputStreamPtr_t m_stream
Definition: IWAParser.h:51
libetonyek::IWAParser::queryCharacterStyle
const IWORKStylePtr_t queryCharacterStyle(unsigned id) const
Definition: IWAParser.cpp:639
libetonyek::IWORKStroke
Definition: IWORKTypes.h:202
libetonyek::IWAParser::parseComment
void parseComment(unsigned id)
Definition: IWAParser.cpp:1550
libetonyek::IWAParser::m_paraStyles
StyleMap_t m_paraStyles
Definition: IWAParser.h:200
libetonyek::IWAParser::TableInfo::m_columns
const unsigned m_columns
Definition: IWAParser.h:141
libetonyek::IWAParser::queryGraphicStyle
const IWORKStylePtr_t queryGraphicStyle(unsigned id) const
Definition: IWAParser.cpp:649
libetonyek::IWORKStylePtr_t
boost::shared_ptr< IWORKStyle > IWORKStylePtr_t
Definition: IWORKStyle_fwd.h:21
libetonyek::IWAParser::ObjectMessage::m_parser
IWAParser & m_parser
Definition: IWAParser.h:83
libetonyek::IWAParser::TableInfo::m_rows
const unsigned m_rows
Definition: IWAParser.h:142
libetonyek::IWAParser::TableInfo::m_formattedTextList
DataList_t m_formattedTextList
Definition: IWAParser.h:151
libetonyek::IWAParser::parseTabularModel
void parseTabularModel(unsigned id)
Definition: IWAParser.cpp:1577
libetonyek::IWORKPropertyMap
Represents a (hierarchical) property map.
Definition: IWORKPropertyMap.h:23
libetonyek::IWAParser::m_tableNameMap
IWORKTableNameMapPtr_t m_tableNameMap
Definition: IWAParser.h:206
libetonyek::IWAParser::queryStyle
const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const
Definition: IWAParser.cpp:626
libetonyek::IWAParser::readSize
static boost::optional< IWORKSize > readSize(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:304
libetonyek::IWAParser::StyleParseFun_t
boost::function< void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t
Definition: IWAParser.h:91
libetonyek::IWAParser::readRefs
static std::deque< unsigned > readRefs(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:278
libetonyek::IWAParser::TableHeader
Definition: IWAParser.h:127
libetonyek::IWAParser::m_fragments
const RVNGInputStreamPtr_t m_fragments
Definition: IWAParser.h:189
libetonyek::IWAParser::parseHeaders
void parseHeaders(unsigned id, TableHeader &header)
Definition: IWAParser.cpp:1898
libetonyek::IWAParser::scanFragment
void scanFragment(unsigned id)
Definition: IWAParser.cpp:1009
libetonyek::IWAParser::TableInfo::m_cellStyleList
DataList_t m_cellStyleList
Definition: IWAParser.h:150
libetonyek::IWAParser::parseCharacterProperties
void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition: IWAParser.cpp:1479
libetonyek::IWAParser::ObjectMessage
friend class ObjectMessage
Definition: IWAParser.h:88
libetonyek::IWAParser::parseShapePlacement
bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry)
Definition: IWAParser.cpp:911
IWAMessage.h
libetonyek::IWAParser::readShadow
static void readShadow(const IWAMessage &msg, IWORKShadow &shadow)
Definition: IWAParser.cpp:470
libetonyek::IWAParser::m_collector
IWORKCollector & m_collector
Definition: IWAParser.h:191
libetonyek::IWAParser::queryFile
const RVNGInputStreamPtr_t queryFile(unsigned id) const
Definition: IWAParser.cpp:251
libetonyek::IWAParser::IWAParser
IWAParser(const IWAParser &)
libetonyek::IWORKGeometryPtr_t
boost::shared_ptr< IWORKGeometry > IWORKGeometryPtr_t
Definition: IWORKTypes_fwd.h:40
libetonyek::IWAParser::parseImage
bool parseImage(const IWAMessage &msg)
Definition: IWAParser.cpp:1510
libetonyek::IWAParser::m_package
const RVNGInputStreamPtr_t m_package
Definition: IWAParser.h:190
libetonyek::IWAParser::TableInfo::m_style
IWORKStylePtr_t m_style
Definition: IWAParser.h:144
libetonyek::IWAParser::TableInfo::m_columnHeader
TableHeader m_columnHeader
Definition: IWAParser.h:146
libetonyek::IWAParser::m_tableStyles
StyleMap_t m_tableStyles
Definition: IWAParser.h:203
libetonyek::IWAParser::ObjectMessage::m_message
boost::optional< IWAMessage > m_message
Definition: IWAParser.h:84
libetonyek::IWAParser::ObjectMessage
Definition: IWAParser.h:66
libetonyek::IWAParser::parseGroup
bool parseGroup(const IWAMessage &msg)
Definition: IWAParser.cpp:894
libetonyek::IWAParser::ObjectRecord::m_dataRange
std::pair< long, long > m_dataRange
Definition: IWAParser.h:54
libetonyek::IWAParser::parseTabularInfo
bool parseTabularInfo(const IWAMessage &msg)
Definition: IWAParser.cpp:1565
libetonyek::IWAParser::parseDrawableShape
bool parseDrawableShape(const IWAMessage &msg)
Definition: IWAParser.cpp:669
libetonyek::IWAParser::m_cellStyles
StyleMap_t m_cellStyles
Definition: IWAParser.h:202
libetonyek::IWAParser::readGradient
static void readGradient(const IWAMessage &msg, IWORKGradient &gradient)
Definition: IWAParser.cpp:437
libetonyek::IWAParser::readFill
bool readFill(const IWAMessage &msg, IWORKFill &fill)
Definition: IWAParser.cpp:380
libetonyek::IWORKPadding
Definition: IWORKTypes.h:82
libetonyek::IWAParser::parseText
bool parseText(unsigned id)
Definition: IWAParser.cpp:512
libetonyek::IWORKToken::style
Definition: IWORKToken.h:254
libetonyek::IWAParser::ObjectMessage::m_type
unsigned m_type
Definition: IWAParser.h:86
libetonyek::IWAParser::TableInfo
Definition: IWAParser.h:135
libetonyek::IWAParser::m_fileMap
FileMap_t m_fileMap
Definition: IWAParser.h:195
libetonyek::IWAParser::RecordMap_t
std::map< unsigned, std::pair< unsigned, ObjectRecord > > RecordMap_t
Definition: IWAParser.h:58
libetonyek::IWORKToken::rows
Definition: IWORKToken.h:231
libetonyek::IWAParser::m_fragmentObjectMap
RecordMap_t m_fragmentObjectMap
Definition: IWAParser.h:194
libetonyek::IWORKCollector
Definition: IWORKCollector.h:41
libetonyek::IWAParser::parseLink
void parseLink(unsigned id, std::string &url)
Definition: IWAParser.cpp:1922
libetonyek::IWAParser::m_listStyles
StyleMap_t m_listStyles
Definition: IWAParser.h:204
libetonyek::IWORKToken::padding
Definition: IWORKToken.h:207
libetonyek::IWAParser::parseParagraphStyle
void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1097
libetonyek::IWAParser::ObjectRecord::ObjectRecord
ObjectRecord()
Definition: IWAParser.cpp:118
libetonyek::IWORKShadow
Definition: IWORKTypes.h:245
libetonyek::IWAParser::DataList_t
std::map< unsigned, boost::variant< std::string, unsigned > > DataList_t
Definition: IWAParser.h:125
libetonyek::IWAParser::m_charStyles
StyleMap_t m_charStyles
Definition: IWAParser.h:199
libetonyek::IWORKFill
boost::variant< IWORKColor, IWORKGradient, IWORKFillImage > IWORKFill
Definition: IWORKTypes.h:243
libetonyek::IWAParser::TableHeader::m_hidden
mdds::flat_segment_tree< unsigned, bool > m_hidden
Definition: IWAParser.h:132
libetonyek::IWAParser::ObjectRecord::m_type
unsigned m_type
Definition: IWAParser.h:52
libetonyek::IWAParser::m_fragmentMap
FileMap_t m_fragmentMap
Definition: IWAParser.h:193
libetonyek::IWORKToken::columns
Definition: IWORKToken.h:82
libetonyek::IWORKToken::geometry
Definition: IWORKToken.h:139
libetonyek::IWAParser::m_currentText
boost::shared_ptr< IWORKText > m_currentText
Definition: IWAParser.h:122
libetonyek::IWORKTableNameMapPtr_t
boost::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition: IWORKTypes_fwd.h:33
libetonyek::IWAParser::m_langManager
IWORKLanguageManager m_langManager
Definition: IWAParser.h:121
libetonyek::KEY1Token::gradient
Definition: KEY1Token.h:53
libetonyek::IWAParser::parseCellStyle
void parseCellStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1242
libetonyek::IWAParser::queryObject
void queryObject(unsigned id, unsigned &type, boost::optional< IWAMessage > &msg) const
Definition: IWAParser.cpp:233
libetonyek::IWAParser::parseTile
void parseTile(unsigned id)
Definition: IWAParser.cpp:1731
libetonyek::IWAParser::parseListStyle
void parseListStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1353
libetonyek::IWAParser::m_graphicStyles
StyleMap_t m_graphicStyles
Definition: IWAParser.h:201
libetonyek::IWORKLanguageManager
Definition: IWORKLanguageManager.h:24
libetonyek::IWAParser::parseObjectIndex
void parseObjectIndex()
Definition: IWAParser.cpp:958
libetonyek::RVNGInputStreamPtr_t
boost::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libetonyek_utils.h:111
libetonyek::IWORKToken::header
Definition: IWORKToken.h:149
libetonyek::IWAParser::parseGraphicStyle
void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1175
libetonyek::IWORKToken::string
Definition: IWORKToken.h:252
libetonyek::IWAParser::TableInfo::m_simpleTextList
DataList_t m_simpleTextList
Definition: IWAParser.h:149
libetonyek::IWAParser::StyleMap_t
std::map< unsigned, IWORKStylePtr_t > StyleMap_t
Definition: IWAParser.h:90
libetonyek::IWAParser::parseTableStyle
void parseTableStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1309
libetonyek::IWAParser::dispatchShape
bool dispatchShape(unsigned id)
Definition: IWAParser.cpp:491
IWORKTypes.h
libetonyek::IWAParser::operator=
IWAParser & operator=(const IWAParser &)
libetonyek::IWAParser::parseDocument
virtual bool parseDocument()=0
libetonyek::IWAMessage
Definition: IWAMessage.h:21
libetonyek::IWAParser::m_currentTable
boost::shared_ptr< TableInfo > m_currentTable
Definition: IWAParser.h:207
libetonyek::IWAParser::TableInfo::m_rowHeader
TableHeader m_rowHeader
Definition: IWAParser.h:147
libetonyek::IWAParser
Definition: IWAParser.h:39
libetonyek::IWAParser::queryParagraphStyle
const IWORKStylePtr_t queryParagraphStyle(unsigned id) const
Definition: IWAParser.cpp:644
libetonyek::IWORKToken::type
Definition: IWORKToken.h:281
libetonyek::IWAParser::readPadding
static void readPadding(const IWAMessage &msg, IWORKPadding &padding)
Definition: IWAParser.cpp:483
libetonyek::IWAParser::parseDataList
void parseDataList(unsigned id, DataList_t &dataList)
Definition: IWAParser.cpp:1690
libetonyek_utils.h
libetonyek::IWAParser::FileMap_t
std::map< unsigned, std::pair< std::string, RVNGInputStreamPtr_t > > FileMap_t
Definition: IWAParser.h:57
libetonyek::IWORKToken::stroke
Definition: IWORKToken.h:253
libetonyek::IWAParser::TableInfo::m_table
boost::shared_ptr< IWORKTable > m_table
Definition: IWAParser.h:139
libetonyek::IWAParser::queryListStyle
const IWORKStylePtr_t queryListStyle(unsigned id) const
Definition: IWAParser.cpp:664
libetonyek::IWAParser::readPosition
static boost::optional< IWORKPosition > readPosition(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:293
libetonyek::IWAParser::queryTableStyle
const IWORKStylePtr_t queryTableStyle(unsigned id) const
Definition: IWAParser.cpp:659
libetonyek::IWORKToken::pos
Definition: IWORKToken.h:334
libetonyek::IWORKToken::fill
Definition: IWORKToken.h:108
libetonyek::IWAParser::ObjectRecord
Definition: IWAParser.h:46
libetonyek::IWAParser::ObjectMessage::m_id
const unsigned m_id
Definition: IWAParser.h:85
libetonyek::IWAParser::parse
bool parse()
Definition: IWAParser.cpp:176
libetonyek::IWAParser::queryCellStyle
const IWORKStylePtr_t queryCellStyle(unsigned id) const
Definition: IWAParser.cpp:654
libetonyek::IWAParser::TableHeader::m_sizes
mdds::flat_segment_tree< unsigned, float > m_sizes
Definition: IWAParser.h:131