- 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 "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
50 RVNGInputStreamPtr_t m_stream;
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:
65 class ObjectMessage
66 {
67 public:
68 ObjectMessage(IWAParser &parser, unsigned id, unsigned type = 0);
69 ~ObjectMessage();
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:
82 IWAParser &m_parser;
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
108 bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry);
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
141 IWORKStylePtr_t m_style;
142
143 TableHeader m_columnHeader;
144 TableHeader m_rowHeader;
145
146 DataList_t m_simpleTextList;
147 DataList_t m_cellStyleList;
148 DataList_t m_formattedTextList;
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:
183 const RVNGInputStreamPtr_t m_fragments;
184 const RVNGInputStreamPtr_t m_package;
185 IWORKCollector &m_collector;
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
199 IWORKTableNameMapPtr_t m_tableNameMap;
200 boost::shared_ptr<TableInfo> m_currentTable;
201 };
202
203 }
204
205 #endif
206
207 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libetonyek::IWAParser::parseCharacterStyle
void parseCharacterStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1089
IWORKStyle_fwd.h
libetonyek
Definition: IWORKBezierElement.cpp:18
libetonyek::IWAParser::TableInfo::m_commentList
DataList_t m_commentList
Definition: IWAParser.h:149
libetonyek::IWAParser::readColor
static boost::optional< IWORKColor > readColor(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:363
libetonyek::IWORKGradient
Definition: IWORKTypes.h:222
libetonyek::IWAParser::ObjectRecord::m_headerRange
std::pair< long, long > m_headerRange
Definition: IWAParser.h:52
libetonyek::IWAParser::readStroke
static void readStroke(const IWAMessage &msg, IWORKStroke &stroke)
Definition: IWAParser.cpp:374
libetonyek::IWAParser::readRef
static boost::optional< unsigned > readRef(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:319
libetonyek::IWAParser::m_visited
std::deque< unsigned > m_visited
Definition: IWAParser.h:191
libetonyek::IWAParser::ObjectRecord::m_stream
RVNGInputStreamPtr_t m_stream
Definition: IWAParser.h:50
libetonyek::IWAParser::queryCharacterStyle
const IWORKStylePtr_t queryCharacterStyle(unsigned id) const
Definition: IWAParser.cpp:660
libetonyek::IWORKStroke
Definition: IWORKTypes.h:201
libetonyek::IWAParser::parseComment
void parseComment(unsigned id)
Definition: IWAParser.cpp:1440
libetonyek::IWAParser::m_paraStyles
StyleMap_t m_paraStyles
Definition: IWAParser.h:194
libetonyek::IWAParser::TableInfo::m_columns
const unsigned m_columns
Definition: IWAParser.h:138
libetonyek::IWAParser::queryGraphicStyle
const IWORKStylePtr_t queryGraphicStyle(unsigned id) const
Definition: IWAParser.cpp:670
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:82
libetonyek::IWAParser::TableInfo::m_rows
const unsigned m_rows
Definition: IWAParser.h:139
libetonyek::IWAParser::TableInfo::m_formattedTextList
DataList_t m_formattedTextList
Definition: IWAParser.h:148
libetonyek::IWAParser::parseTabularModel
void parseTabularModel(unsigned id)
Definition: IWAParser.cpp:1469
libetonyek::IWORKPropertyMap
Represents a (hierarchical) property map.
Definition: IWORKPropertyMap.h:23
libetonyek::IWAParser::m_tableNameMap
IWORKTableNameMapPtr_t m_tableNameMap
Definition: IWAParser.h:199
libetonyek::IWAParser::queryStyle
const IWORKStylePtr_t queryStyle(unsigned id, StyleMap_t &styleMap, StyleParseFun_t parse) const
Definition: IWAParser.cpp:647
libetonyek::IWAParser::readSize
static boost::optional< IWORKSize > readSize(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:352
libetonyek::IWAParser::StyleParseFun_t
boost::function< void(unsigned, IWORKStylePtr_t &)> StyleParseFun_t
Definition: IWAParser.h:90
libetonyek::IWAParser::readRefs
static std::deque< unsigned > readRefs(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:326
libetonyek::IWAParser::TableHeader
Definition: IWAParser.h:124
libetonyek::IWAParser::m_fragments
const RVNGInputStreamPtr_t m_fragments
Definition: IWAParser.h:183
libetonyek::IWAParser::parseHeaders
void parseHeaders(unsigned id, TableHeader &header)
Definition: IWAParser.cpp:1799
libetonyek::IWAParser::scanFragment
void scanFragment(unsigned id)
Definition: IWAParser.cpp:1025
libetonyek::IWAParser::TableInfo::m_cellStyleList
DataList_t m_cellStyleList
Definition: IWAParser.h:147
libetonyek::IWAParser::parseCharacterProperties
void parseCharacterProperties(const IWAMessage &msg, IWORKPropertyMap &props)
Definition: IWAParser.cpp:1369
libetonyek::IWAParser::parseShapePlacement
bool parseShapePlacement(const IWAMessage &msg, IWORKGeometryPtr_t &geometry)
Definition: IWAParser.cpp:927
IWAMessage.h
libetonyek::IWAParser::TableInfo::TableInfo
TableInfo(const boost::shared_ptr< IWORKTable > &table, unsigned columns, unsigned rows)
Definition: IWAParser.cpp:203
libetonyek::IWAParser::readShadow
static void readShadow(const IWAMessage &msg, IWORKShadow &shadow)
Definition: IWAParser.cpp:518
libetonyek::IWAParser::m_collector
IWORKCollector & m_collector
Definition: IWAParser.h:185
libetonyek::IWAParser::queryFile
const RVNGInputStreamPtr_t queryFile(unsigned id) const
Definition: IWAParser.cpp:299
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:1400
libetonyek::IWAParser::m_package
const RVNGInputStreamPtr_t m_package
Definition: IWAParser.h:184
libetonyek::IWAParser::TableInfo::m_style
IWORKStylePtr_t m_style
Definition: IWAParser.h:141
libetonyek::IWAParser::TableInfo::m_columnHeader
TableHeader m_columnHeader
Definition: IWAParser.h:143
libetonyek::IWAParser::m_tableStyles
StyleMap_t m_tableStyles
Definition: IWAParser.h:197
libetonyek::IWAParser::ObjectMessage::m_message
boost::optional< IWAMessage > m_message
Definition: IWAParser.h:83
libetonyek::IWAParser::ObjectMessage
Definition: IWAParser.h:65
libetonyek::IWAParser::parseGroup
bool parseGroup(const IWAMessage &msg)
Definition: IWAParser.cpp:910
libetonyek::IWAParser::ObjectMessage::ObjectMessage
ObjectMessage(IWAParser &parser, unsigned id, unsigned type=0)
Definition: IWAParser.cpp:230
libetonyek::IWAParser::ObjectRecord::m_dataRange
std::pair< long, long > m_dataRange
Definition: IWAParser.h:53
libetonyek::IWAParser::parseTabularInfo
bool parseTabularInfo(const IWAMessage &msg)
Definition: IWAParser.cpp:1459
libetonyek::IWAParser::parseDrawableShape
bool parseDrawableShape(const IWAMessage &msg)
Definition: IWAParser.cpp:685
libetonyek::IWAParser::m_cellStyles
StyleMap_t m_cellStyles
Definition: IWAParser.h:196
libetonyek::IWAParser::readGradient
static void readGradient(const IWAMessage &msg, IWORKGradient &gradient)
Definition: IWAParser.cpp:485
libetonyek::IWAParser::readFill
bool readFill(const IWAMessage &msg, IWORKFill &fill)
Definition: IWAParser.cpp:428
libetonyek::IWORKPadding
Definition: IWORKTypes.h:81
libetonyek::IWAParser::parseText
bool parseText(unsigned id)
Definition: IWAParser.cpp:560
libetonyek::IWORKToken::style
Definition: IWORKToken.h:241
libetonyek::IWAParser::ObjectMessage::m_type
unsigned m_type
Definition: IWAParser.h:85
libetonyek::IWAParser::ObjectMessage::getType
unsigned getType() const
Definition: IWAParser.cpp:276
libetonyek::IWAParser::TableInfo
Definition: IWAParser.h:132
libetonyek::IWAParser::m_fileMap
FileMap_t m_fileMap
Definition: IWAParser.h:189
libetonyek::IWAParser::RecordMap_t
std::map< unsigned, std::pair< unsigned, ObjectRecord > > RecordMap_t
Definition: IWAParser.h:57
libetonyek::IWORKToken::rows
Definition: IWORKToken.h:218
libetonyek::IWAParser::m_fragmentObjectMap
RecordMap_t m_fragmentObjectMap
Definition: IWAParser.h:188
libetonyek::IWORKCollector
Definition: IWORKCollector.h:40
libetonyek::IWORKToken::padding
Definition: IWORKToken.h:194
libetonyek::IWAParser::parseParagraphStyle
void parseParagraphStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1113
libetonyek::IWAParser::ObjectRecord::ObjectRecord
ObjectRecord()
Definition: IWAParser.cpp:180
libetonyek::IWORKShadow
Definition: IWORKTypes.h:244
libetonyek::IWAParser::DataList_t
std::map< unsigned, boost::variant< std::string, unsigned > > DataList_t
Definition: IWAParser.h:122
libetonyek::IWAParser::m_charStyles
StyleMap_t m_charStyles
Definition: IWAParser.h:193
libetonyek::IWORKFill
boost::variant< IWORKColor, IWORKGradient, IWORKFillImage > IWORKFill
Definition: IWORKTypes.h:242
libetonyek::IWAParser::TableHeader::m_hidden
mdds::flat_segment_tree< unsigned, bool > m_hidden
Definition: IWAParser.h:129
libetonyek::IWAParser::ObjectRecord::m_type
unsigned m_type
Definition: IWAParser.h:51
libetonyek::IWAParser::m_fragmentMap
FileMap_t m_fragmentMap
Definition: IWAParser.h:187
libetonyek::IWORKToken::columns
Definition: IWORKToken.h:79
libetonyek::IWORKToken::geometry
Definition: IWORKToken.h:136
libetonyek::IWAParser::m_currentText
boost::shared_ptr< IWORKText > m_currentText
Definition: IWAParser.h:119
libetonyek::IWORKTableNameMapPtr_t
boost::shared_ptr< IWORKTableNameMap_t > IWORKTableNameMapPtr_t
Definition: IWORKTypes_fwd.h:33
libetonyek::KEY1Token::gradient
Definition: KEY1Token.h:53
libetonyek::IWAParser::parseCellStyle
void parseCellStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1258
libetonyek::IWAParser::queryObject
void queryObject(unsigned id, unsigned &type, boost::optional< IWAMessage > &msg) const
Definition: IWAParser.cpp:281
libetonyek::IWAParser::parseTile
void parseTile(unsigned id)
Definition: IWAParser.cpp:1623
libetonyek::IWAParser::m_graphicStyles
StyleMap_t m_graphicStyles
Definition: IWAParser.h:195
libetonyek::IWAParser::parseObjectIndex
void parseObjectIndex()
Definition: IWAParser.cpp:974
libetonyek::RVNGInputStreamPtr_t
boost::shared_ptr< librevenge::RVNGInputStream > RVNGInputStreamPtr_t
Definition: libetonyek_utils.h:111
libetonyek::IWORKToken::header
Definition: IWORKToken.h:146
libetonyek::IWAParser::parseGraphicStyle
void parseGraphicStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1191
libetonyek::IWAParser::TableInfo::m_simpleTextList
DataList_t m_simpleTextList
Definition: IWAParser.h:146
libetonyek::IWAParser::StyleMap_t
std::map< unsigned, IWORKStylePtr_t > StyleMap_t
Definition: IWAParser.h:89
libetonyek::IWAParser::parseTableStyle
void parseTableStyle(unsigned id, IWORKStylePtr_t &style)
Definition: IWAParser.cpp:1325
libetonyek::IWAParser::dispatchShape
bool dispatchShape(unsigned id)
Definition: IWAParser.cpp:539
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:200
libetonyek::IWAParser::TableInfo::m_rowHeader
TableHeader m_rowHeader
Definition: IWAParser.h:144
libetonyek::IWAParser::TableHeader::TableHeader
TableHeader(unsigned count)
Definition: IWAParser.cpp:197
libetonyek::IWAParser
Definition: IWAParser.h:38
libetonyek::IWAParser::queryParagraphStyle
const IWORKStylePtr_t queryParagraphStyle(unsigned id) const
Definition: IWAParser.cpp:665
libetonyek::IWORKToken::type
Definition: IWORKToken.h:266
libetonyek::IWAParser::readPadding
static void readPadding(const IWAMessage &msg, IWORKPadding &padding)
Definition: IWAParser.cpp:531
libetonyek::IWAParser::parseDataList
void parseDataList(unsigned id, DataList_t &dataList)
Definition: IWAParser.cpp:1582
libetonyek::IWAParser::ObjectMessage::~ObjectMessage
~ObjectMessage()
Definition: IWAParser.cpp:256
libetonyek_utils.h
libetonyek::IWAParser::FileMap_t
std::map< unsigned, std::pair< std::string, RVNGInputStreamPtr_t > > FileMap_t
Definition: IWAParser.h:56
libetonyek::IWORKToken::stroke
Definition: IWORKToken.h:240
libetonyek::IWAParser::TableInfo::m_table
boost::shared_ptr< IWORKTable > m_table
Definition: IWAParser.h:136
libetonyek::IWAParser::readPosition
static boost::optional< IWORKPosition > readPosition(const IWAMessage &msg, unsigned field)
Definition: IWAParser.cpp:341
libetonyek::IWAParser::queryTableStyle
const IWORKStylePtr_t queryTableStyle(unsigned id) const
Definition: IWAParser.cpp:680
libetonyek::IWORKToken::pos
Definition: IWORKToken.h:315
libetonyek::IWORKToken::fill
Definition: IWORKToken.h:105
libetonyek::IWAParser::ObjectRecord
Definition: IWAParser.h:45
libetonyek::IWAParser::ObjectMessage::m_id
const unsigned m_id
Definition: IWAParser.h:84
libetonyek::IWAParser::parse
bool parse()
Definition: IWAParser.cpp:224
libetonyek::IWAParser::queryCellStyle
const IWORKStylePtr_t queryCellStyle(unsigned id) const
Definition: IWAParser.cpp:675
libetonyek::IWAParser::TableHeader::m_sizes
mdds::flat_segment_tree< unsigned, float > m_sizes
Definition: IWAParser.h:128