Coverage Report

Created: 2026-04-29 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmwaw/src/lib/MWAWParser.hxx
Line
Count
Source
1
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3
/* libmwaw
4
* Version: MPL 2.0 / LGPLv2+
5
*
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 2.0 (the "License"); you may not use this file except in compliance with
8
* the License or as specified alternatively below. You may obtain a copy of
9
* the License at http://www.mozilla.org/MPL/
10
*
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
14
* License.
15
*
16
* Major Contributor(s):
17
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
18
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20
* Copyright (C) 2006, 2007 Andrew Ziem
21
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
22
*
23
*
24
* All Rights Reserved.
25
*
26
* For minor contributions see the git repository.
27
*
28
* Alternatively, the contents of this file may be used under the terms of
29
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
30
* in which case the provisions of the LGPLv2+ are applicable
31
* instead of those above.
32
*/
33
34
#ifndef MWAW_PARSER_H
35
#define MWAW_PARSER_H
36
37
#include <ostream>
38
#include <string>
39
#include <vector>
40
41
#include "MWAWDebug.hxx"
42
#include "MWAWInputStream.hxx"
43
44
#include "MWAWEntry.hxx"
45
#include "MWAWHeader.hxx"
46
#include "MWAWPageSpan.hxx"
47
48
/** a class to define the parser state */
49
class MWAWParserState
50
{
51
public:
52
  //! the parser state type
53
  enum Type { Graphic, Presentation, Spreadsheet, Text };
54
  //! Constructor
55
  MWAWParserState(Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
56
  //! destructor
57
  ~MWAWParserState();
58
  //! returns the main listener
59
  MWAWListenerPtr getMainListener();
60
  //! the state type
61
  Type m_type;
62
  //! the document kind
63
  MWAWDocument::Kind m_kind;
64
  //! the input
65
  MWAWInputStreamPtr m_input;
66
  //! the header
67
  MWAWHeader *m_header;
68
  //! the resource parser
69
  MWAWRSRCParserPtr m_rsrcParser;
70
  //! the actual document size
71
  MWAWPageSpan m_pageSpan;
72
73
  //! the font converter
74
  MWAWFontConverterPtr m_fontConverter;
75
  //! the font manager
76
  MWAWFontManagerPtr m_fontManager;
77
  //! the graphic listener
78
  MWAWGraphicListenerPtr m_graphicListener;
79
  //! the list manager
80
  MWAWListManagerPtr m_listManager;
81
  //! the presentation listener
82
  MWAWPresentationListenerPtr m_presentationListener;
83
  //! the spreadsheet listener
84
  MWAWSpreadsheetListenerPtr m_spreadsheetListener;
85
  //! the text listener
86
  MWAWTextListenerPtr m_textListener;
87
  //! the actual version
88
  int m_version;
89
90
  //! the debug file
91
  libmwaw::DebugFile m_asciiFile;
92
93
private:
94
  MWAWParserState(MWAWParserState const &orig) = delete;
95
  MWAWParserState &operator=(MWAWParserState const &orig) = delete;
96
};
97
98
/** virtual class which defines the ancestor of all main zone parser */
99
class MWAWParser
100
{
101
public:
102
  //! virtual destructor
103
  virtual ~MWAWParser();
104
  //! virtual function used to check if the document header is correct (or not)
105
  virtual bool checkHeader(MWAWHeader *header, bool strict=false) = 0;
106
107
  //! returns the works version
108
  int version() const
109
296M
  {
110
296M
    return m_parserState->m_version;
111
296M
  }
112
  //! returns the parser state
113
  MWAWParserStatePtr getParserState()
114
16.1M
  {
115
16.1M
    return m_parserState;
116
16.1M
  }
117
  //! returns the header
118
  MWAWHeader *getHeader()
119
0
  {
120
0
    return m_parserState->m_header;
121
0
  }
122
  //! returns the actual input
123
  MWAWInputStreamPtr &getInput()
124
479M
  {
125
479M
    return m_parserState->m_input;
126
479M
  }
127
  //! returns the main listener
128
  MWAWListenerPtr getMainListener();
129
  //! returns the graphic listener
130
  MWAWGraphicListenerPtr &getGraphicListener()
131
28.4M
  {
132
28.4M
    return m_parserState->m_graphicListener;
133
28.4M
  }
134
  //! returns the presentation listener
135
  MWAWPresentationListenerPtr &getPresentationListener()
136
431k
  {
137
431k
    return m_parserState->m_presentationListener;
138
431k
  }
139
  //! returns the spreadsheet listener
140
  MWAWSpreadsheetListenerPtr &getSpreadsheetListener()
141
4.50M
  {
142
4.50M
    return m_parserState->m_spreadsheetListener;
143
4.50M
  }
144
  //! returns the text listener
145
  MWAWTextListenerPtr &getTextListener()
146
590M
  {
147
590M
    return m_parserState->m_textListener;
148
590M
  }
149
  //! returns the font converter
150
  MWAWFontConverterPtr &getFontConverter()
151
227k
  {
152
227k
    return m_parserState->m_fontConverter;
153
227k
  }
154
  //! returns the font manager
155
  MWAWFontManagerPtr &getFontManager()
156
1.04k
  {
157
1.04k
    return m_parserState->m_fontManager;
158
1.04k
  }
159
  //! returns the actual page dimension
160
  MWAWPageSpan const &getPageSpan() const
161
20.7k
  {
162
20.7k
    return m_parserState->m_pageSpan;
163
20.7k
  }
164
  //! returns the actual page dimension
165
  MWAWPageSpan &getPageSpan()
166
7.03M
  {
167
7.03M
    return m_parserState->m_pageSpan;
168
7.03M
  }
169
  //! returns the form length
170
  double getFormLength() const
171
2.14M
  {
172
2.14M
    return m_parserState->m_pageSpan.getFormLength();
173
2.14M
  }
174
  //! returns the form width
175
  double getFormWidth() const
176
221k
  {
177
221k
    return m_parserState->m_pageSpan.getFormWidth();
178
221k
  }
179
  //! returns the page length (form length without margin )
180
  double getPageLength() const
181
8.02k
  {
182
8.02k
    return m_parserState->m_pageSpan.getPageLength();
183
8.02k
  }
184
  //! returns the page width (form width without margin )
185
  double getPageWidth() const
186
2.79M
  {
187
2.79M
    return m_parserState->m_pageSpan.getPageWidth();
188
2.79M
  }
189
  //! returns the rsrc parser
190
  MWAWRSRCParserPtr &getRSRCParser()
191
894k
  {
192
894k
    return m_parserState->m_rsrcParser;
193
894k
  }
194
  //! a DebugFile used to write what we recognize when we parse the document
195
  libmwaw::DebugFile &ascii()
196
703M
  {
197
703M
    return m_parserState->m_asciiFile;
198
703M
  }
199
protected:
200
  //! constructor (protected)
201
  MWAWParser(MWAWParserState::Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header);
202
  //! constructor using a state
203
0
  explicit MWAWParser(MWAWParserStatePtr const &state) : m_parserState(state), m_asciiName("") { }
204
205
  //! sets the document's version
206
  void setVersion(int vers)
207
1.54M
  {
208
1.54M
    m_parserState->m_version = vers;
209
1.54M
  }
210
  //! sets the graphic listener
211
  void setGraphicListener(MWAWGraphicListenerPtr &listener);
212
  //! resets the listener
213
  void resetGraphicListener();
214
  //! sets the presentation listener
215
  void setPresentationListener(MWAWPresentationListenerPtr &listener);
216
  //! resets the listener
217
  void resetPresentationListener();
218
  //! sets the spreadsheet listener
219
  void setSpreadsheetListener(MWAWSpreadsheetListenerPtr &listener);
220
  //! resets the listener
221
  void resetSpreadsheetListener();
222
  //! sets the text listener
223
  void setTextListener(MWAWTextListenerPtr &listener);
224
  //! resets the listener
225
  void resetTextListener();
226
  //! Debugging: change the default ascii file
227
  void setAsciiName(char const *name)
228
2.30M
  {
229
2.30M
    m_asciiName = name;
230
2.30M
  }
231
  //! return the ascii file name
232
  std::string const &asciiName() const
233
838k
  {
234
838k
    return m_asciiName;
235
838k
  }
236
237
private:
238
  //! private copy constructor: forbidden
239
  MWAWParser(const MWAWParser &) = delete;
240
  //! private operator=: forbidden
241
  MWAWParser &operator=(const MWAWParser &) = delete;
242
243
  //! the parser state
244
  MWAWParserStatePtr m_parserState;
245
  //! the debug file name
246
  std::string m_asciiName;
247
};
248
249
/** virtual class which defines the ancestor of all graphic zone parser */
250
class MWAWGraphicParser : public MWAWParser
251
{
252
public:
253
  //! destructor
254
  ~MWAWGraphicParser() override;
255
  //! virtual function used to parse the input
256
  virtual void parse(librevenge::RVNGDrawingInterface *documentInterface) = 0;
257
protected:
258
  //! constructor (protected)
259
770k
  MWAWGraphicParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Graphic, input, rsrcParser, header) {}
260
  //! constructor using a state
261
  explicit MWAWGraphicParser(MWAWParserStatePtr const &state)
262
0
    : MWAWParser(state) {}
263
};
264
265
/** virtual class which defines the ancestor of all presentation zone parser */
266
class MWAWPresentationParser : public MWAWParser
267
{
268
public:
269
  //! destructor
270
  ~MWAWPresentationParser() override;
271
  //! virtual function used to parse the input
272
  virtual void parse(librevenge::RVNGPresentationInterface *documentInterface) = 0;
273
protected:
274
  //! constructor (protected)
275
51.8k
  MWAWPresentationParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Presentation, input, rsrcParser, header) {}
276
  //! constructor using a state
277
  explicit MWAWPresentationParser(MWAWParserStatePtr const &state)
278
0
    : MWAWParser(state) {}
279
};
280
281
/** virtual class which defines the ancestor of all spreadsheet zone parser */
282
class MWAWSpreadsheetParser : public MWAWParser
283
{
284
public:
285
  //! destructor
286
  ~MWAWSpreadsheetParser() override;
287
  //! virtual function used to parse the input
288
  virtual void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) = 0;
289
protected:
290
  //! constructor (protected)
291
106k
  MWAWSpreadsheetParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Spreadsheet, input, rsrcParser, header) {}
292
  //! constructor using a state
293
  explicit MWAWSpreadsheetParser(MWAWParserStatePtr const &state)
294
0
    : MWAWParser(state) {}
295
};
296
297
/** virtual class which defines the ancestor of all text zone parser */
298
class MWAWTextParser : public MWAWParser
299
{
300
public:
301
  //! destructor
302
  ~MWAWTextParser() override;
303
  //! virtual function used to parse the input
304
  virtual void parse(librevenge::RVNGTextInterface *documentInterface) = 0;
305
protected:
306
  //! constructor (protected)
307
1.41M
  MWAWTextParser(MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) : MWAWParser(MWAWParserState::Text, input, rsrcParser, header) {}
308
  //! constructor using a state
309
  explicit MWAWTextParser(MWAWParserStatePtr const &state)
310
0
    : MWAWParser(state) {}
311
};
312
313
#endif /* MWAWPARSER_H */
314
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: