| 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 ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 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 |
{ |
| 110 |
return m_parserState->m_version; |
| 111 |
} |
| 112 |
//! returns the parser state |
| 113 |
MWAWParserStatePtr getParserState() |
| 114 |
{ |
| 115 |
return m_parserState; |
| 116 |
} |
| 117 |
//! returns the header |
| 118 |
MWAWHeader *getHeader() |
| 119 |
{ |
| 120 |
return m_parserState->m_header; |
| 121 |
} |
| 122 |
//! returns the actual input |
| 123 |
MWAWInputStreamPtr &getInput() |
| 124 |
{ |
| 125 |
return m_parserState->m_input; |
| 126 |
} |
| 127 |
//! returns the main listener |
| 128 |
MWAWListenerPtr getMainListener(); |
| 129 |
//! returns the graphic listener |
| 130 |
MWAWGraphicListenerPtr &getGraphicListener() |
| 131 |
{ |
| 132 |
return m_parserState->m_graphicListener; |
| 133 |
} |
| 134 |
//! returns the presentation listener |
| 135 |
MWAWPresentationListenerPtr &getPresentationListener() |
| 136 |
{ |
| 137 |
return m_parserState->m_presentationListener; |
| 138 |
} |
| 139 |
//! returns the spreadsheet listener |
| 140 |
MWAWSpreadsheetListenerPtr &getSpreadsheetListener() |
| 141 |
{ |
| 142 |
return m_parserState->m_spreadsheetListener; |
| 143 |
} |
| 144 |
//! returns the text listener |
| 145 |
MWAWTextListenerPtr &getTextListener() |
| 146 |
{ |
| 147 |
return m_parserState->m_textListener; |
| 148 |
} |
| 149 |
//! returns the font converter |
| 150 |
MWAWFontConverterPtr &getFontConverter() |
| 151 |
{ |
| 152 |
return m_parserState->m_fontConverter; |
| 153 |
} |
| 154 |
//! returns the font manager |
| 155 |
MWAWFontManagerPtr &getFontManager() |
| 156 |
{ |
| 157 |
return m_parserState->m_fontManager; |
| 158 |
} |
| 159 |
//! returns the actual page dimension |
| 160 |
MWAWPageSpan const &getPageSpan() const |
| 161 |
{ |
| 162 |
return m_parserState->m_pageSpan; |
| 163 |
} |
| 164 |
//! returns the actual page dimension |
| 165 |
MWAWPageSpan &getPageSpan() |
| 166 |
{ |
| 167 |
return m_parserState->m_pageSpan; |
| 168 |
} |
| 169 |
//! returns the form length |
| 170 |
double getFormLength() const |
| 171 |
{ |
| 172 |
return m_parserState->m_pageSpan.getFormLength(); |
| 173 |
} |
| 174 |
//! returns the form width |
| 175 |
double getFormWidth() const |
| 176 |
{ |
| 177 |
return m_parserState->m_pageSpan.getFormWidth(); |
| 178 |
} |
| 179 |
//! returns the page length (form length without margin ) |
| 180 |
double getPageLength() const |
| 181 |
{ |
| 182 |
return m_parserState->m_pageSpan.getPageLength(); |
| 183 |
} |
| 184 |
//! returns the page width (form width without margin ) |
| 185 |
double getPageWidth() const |
| 186 |
{ |
| 187 |
return m_parserState->m_pageSpan.getPageWidth(); |
| 188 |
} |
| 189 |
//! returns the rsrc parser |
| 190 |
MWAWRSRCParserPtr &getRSRCParser() |
| 191 |
{ |
| 192 |
return m_parserState->m_rsrcParser; |
| 193 |
} |
| 194 |
//! a DebugFile used to write what we recognize when we parse the document |
| 195 |
libmwaw::DebugFile &ascii() |
| 196 |
{ |
| 197 |
return m_parserState->m_asciiFile; |
| 198 |
} |
| 199 |
protected: |
| 200 |
//! constructor (protected) |
| 201 |
MWAWParser(MWAWParserState::Type type, MWAWInputStreamPtr const &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 202 |
//! constructor using a state |
| 203 |
explicit MWAWParser(MWAWParserStatePtr const &state) : m_parserState(state), m_asciiName("") { } |
| 204 |
|
| 205 |
//! sets the document's version |
| 206 |
void setVersion(int vers) |
| 207 |
{ |
| 208 |
m_parserState->m_version = vers; |
| 209 |
} |
| 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 |
{ |
| 229 |
m_asciiName = name; |
| 230 |
} |
| 231 |
//! return the ascii file name |
| 232 |
std::string const &asciiName() const |
| 233 |
{ |
| 234 |
return m_asciiName; |
| 235 |
} |
| 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 |
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 |
: 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 |
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 |
: 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 |
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 |
: 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 |
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 |
: MWAWParser(state) {} |
| 311 |
}; |
| 312 |
|
| 313 |
#endif /* MWAWPARSER_H */ |
| 314 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |