| 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 MS_WKS_DOCUMENT |
| 35 |
# define MS_WKS_DOCUMENT |
| 36 |
|
| 37 |
#include <string> |
| 38 |
#include <map> |
| 39 |
#include <vector> |
| 40 |
|
| 41 |
#include <librevenge/librevenge.h> |
| 42 |
|
| 43 |
#include "libmwaw_internal.hxx" |
| 44 |
|
| 45 |
#include "MWAWDebug.hxx" |
| 46 |
#include "MWAWCell.hxx" |
| 47 |
#include "MWAWParser.hxx" |
| 48 |
|
| 49 |
namespace MsWksDocumentInternal |
| 50 |
{ |
| 51 |
struct State; |
| 52 |
|
| 53 |
class SubDocument; |
| 54 |
} |
| 55 |
|
| 56 |
class MsWksParser; |
| 57 |
class MsWksDBParser; |
| 58 |
class MsWksDRParser; |
| 59 |
class MsWksSSParser; |
| 60 |
class MsWks4Zone; |
| 61 |
|
| 62 |
class MsWksGraph; |
| 63 |
class MsWks3Text; |
| 64 |
class MsWks4Text; |
| 65 |
|
| 66 |
/** \brief the main class to read/store generic data of a MsWorks document v1-v3 |
| 67 |
*/ |
| 68 |
class MsWksDocument |
| 69 |
{ |
| 70 |
friend class MsWksDocumentInternal::SubDocument; |
| 71 |
friend class MsWksParser; |
| 72 |
friend class MsWks4Zone; |
| 73 |
friend class MsWksDBParser; |
| 74 |
friend class MsWksDRParser; |
| 75 |
friend class MsWksSSParser; |
| 76 |
public: |
| 77 |
//! the different type of zone (v1-v3) |
| 78 |
enum ZoneType { Z_MAIN, Z_HEADER, Z_FOOTER, Z_NONE }; |
| 79 |
//! a zone of a MsWksDocument ( main, header, footer ) |
| 80 |
struct Zone { |
| 81 |
//! the constructor |
| 82 |
explicit Zone(ZoneType type=Z_NONE, int zoneId=-1) |
| 83 |
: m_type(type) |
| 84 |
, m_zoneId(zoneId) |
| 85 |
, m_textId(-1) |
| 86 |
{ |
| 87 |
} |
| 88 |
//! the zone type |
| 89 |
ZoneType m_type; |
| 90 |
//! the parser zone id |
| 91 |
int m_zoneId; |
| 92 |
//! the text internal id |
| 93 |
int m_textId; |
| 94 |
}; |
| 95 |
|
| 96 |
public: |
| 97 |
|
| 98 |
//! constructor |
| 99 |
MsWksDocument(MWAWInputStreamPtr const &input, MWAWParser &parser); |
| 100 |
//! destructor |
| 101 |
virtual ~MsWksDocument(); |
| 102 |
|
| 103 |
//! returns the document's version |
| 104 |
int version() const; |
| 105 |
//! sets the document's version |
| 106 |
void setVersion(int vers); |
| 107 |
//! returns the document's kind |
| 108 |
MWAWDocument::Kind getKind() const; |
| 109 |
//! sets the document's kind |
| 110 |
void setKind(MWAWDocument::Kind kind); |
| 111 |
|
| 112 |
//! returns the actual input |
| 113 |
MWAWInputStreamPtr &getInput() |
| 114 |
{ |
| 115 |
return m_input; |
| 116 |
} |
| 117 |
//! returns the main parser |
| 118 |
MWAWParser &getMainParser() |
| 119 |
{ |
| 120 |
return *m_parser; |
| 121 |
} |
| 122 |
//! returns the graph parser |
| 123 |
std::shared_ptr<MsWksGraph> getGraphParser() |
| 124 |
{ |
| 125 |
return m_graphParser; |
| 126 |
} |
| 127 |
//! returns the text parser (for v1-v3 document) |
| 128 |
std::shared_ptr<MsWks3Text> getTextParser3(); |
| 129 |
//! returns the text parser (for v4 document) |
| 130 |
std::shared_ptr<MsWks4Text> getTextParser4(); |
| 131 |
//! a DebugFile used to write what we recognize when we parse the document |
| 132 |
libmwaw::DebugFile &ascii() |
| 133 |
{ |
| 134 |
return m_asciiFile; |
| 135 |
} |
| 136 |
|
| 137 |
// |
| 138 |
// read some v3 structure |
| 139 |
// |
| 140 |
|
| 141 |
//! checks if the file header corresponds to a v1-v3 document (or not) |
| 142 |
bool checkHeader3(MWAWHeader *header, bool strict=false); |
| 143 |
//! returns the length of the file header of a v1-v3 document (if know) |
| 144 |
long getLengthOfFileHeader3() const; |
| 145 |
//! read the print info zone (v1-v3) |
| 146 |
bool readPrintInfo(); |
| 147 |
//! try to read the documentinfo ( v1-v3) |
| 148 |
bool readDocumentInfo(long sz=-1); |
| 149 |
//! try to read a generic zone |
| 150 |
bool readZone(Zone &zone); |
| 151 |
//! try to read a header/footer group |
| 152 |
bool readGroupHeaderFooter(bool header, int check); |
| 153 |
|
| 154 |
// |
| 155 |
// read some ole structures |
| 156 |
// |
| 157 |
|
| 158 |
//! finds the different OLE zones |
| 159 |
bool createOLEZones(MWAWInputStreamPtr input); |
| 160 |
//! returns the list of unparsed OLE zones |
| 161 |
std::vector<std::string> const &getUnparsedOLEZones() const; |
| 162 |
// |
| 163 |
// utilities functions |
| 164 |
// |
| 165 |
|
| 166 |
//! returns true if the document has some header ( found by checkHeader3) |
| 167 |
bool hasHeader() const; |
| 168 |
//! returns true if the document has some footer ( found by checkHeader3) |
| 169 |
bool hasFooter() const; |
| 170 |
//! returns the header/footer height (found by readGroupHeaderFooter) |
| 171 |
float getHeaderFooterHeight(bool header) const; |
| 172 |
//! get the page span list and the number of page for a v1-v3 document |
| 173 |
void getPageSpanList(std::vector<MWAWPageSpan> &pagesList, int &numPages); |
| 174 |
//! returns the color which correspond to an index |
| 175 |
bool getColor(int id, MWAWColor &col, int vers); |
| 176 |
//! returns a list of color corresponding to a version |
| 177 |
std::vector<MWAWColor> const &getPalette(int vers); |
| 178 |
|
| 179 |
//! returns the document entry map of a v1-v3 document |
| 180 |
std::multimap<int, Zone> &getTypeZoneMap(); |
| 181 |
//! returns the zone corresponding to a zoneType (v1-v3 document) |
| 182 |
Zone getZone(ZoneType type) const; |
| 183 |
//! returns a free zone'id |
| 184 |
int getNewZoneId() const; |
| 185 |
//! returns the document entry map of a v4 document |
| 186 |
std::multimap<std::string, MWAWEntry> &getEntryMap(); |
| 187 |
|
| 188 |
// general interface |
| 189 |
|
| 190 |
/** try to send a zone (v1-v3 document) */ |
| 191 |
void sendZone(int zoneType); |
| 192 |
|
| 193 |
// interface with the text parser |
| 194 |
|
| 195 |
//! tries to create a new page |
| 196 |
void newPage(int page, bool softBreak=false); |
| 197 |
/** try to send a footnote content (v4 document) */ |
| 198 |
void sendFootnoteContent(int noteId); |
| 199 |
//! tries to send a footnote |
| 200 |
void sendFootnote(int id); |
| 201 |
/** try to send a text zone (v1-v3 document) */ |
| 202 |
void sendText(int id); |
| 203 |
|
| 204 |
// interface with the graph parser |
| 205 |
|
| 206 |
//! send an OLE zone |
| 207 |
void sendOLE(int id, MWAWPosition const &pos, MWAWGraphicStyle const &style); |
| 208 |
/** send a rbil zone */ |
| 209 |
void sendRBIL(int id, MWAWVec2i const &sz); |
| 210 |
/** send a textbox */ |
| 211 |
void sendTextbox(MWAWEntry const &entry, std::string const &frame); |
| 212 |
|
| 213 |
protected: |
| 214 |
// |
| 215 |
// spreadsheet/database function |
| 216 |
// |
| 217 |
|
| 218 |
/** reads a cell */ |
| 219 |
bool readCellInFormula(MWAWCellContent::FormulaInstruction &instr, bool is2D); |
| 220 |
/** try to read a string */ |
| 221 |
bool readDBString(long endPos, std::string &res); |
| 222 |
/** try to read a number */ |
| 223 |
bool readDBNumber(long endPos, double &res, bool &isNan, std::string &str); |
| 224 |
/* reads a formula */ |
| 225 |
bool readFormula(long endPos, MWAWCellContent &content, std::string &extra); |
| 226 |
|
| 227 |
protected: |
| 228 |
|
| 229 |
// |
| 230 |
// low level |
| 231 |
// |
| 232 |
//! inits the ascii file |
| 233 |
void initAsciiFile(std::string const &name); |
| 234 |
|
| 235 |
private: |
| 236 |
MsWksDocument(MsWksDocument const &orig) = delete; |
| 237 |
MsWksDocument &operator=(MsWksDocument const &orig) = delete; |
| 238 |
|
| 239 |
// |
| 240 |
// data |
| 241 |
// |
| 242 |
|
| 243 |
protected: |
| 244 |
//! the state |
| 245 |
std::shared_ptr<MsWksDocumentInternal::State> m_state; |
| 246 |
public: |
| 247 |
//! the parser state |
| 248 |
std::shared_ptr<MWAWParserState> m_parserState; |
| 249 |
|
| 250 |
protected: |
| 251 |
//! the main parser |
| 252 |
MWAWParser *m_parser; |
| 253 |
//! the parent document (if this is not the main document) |
| 254 |
MsWksDocument *m_parentDocument; |
| 255 |
//! the input which can be an OLE in MSWorks 4 file |
| 256 |
MWAWInputStreamPtr m_input; |
| 257 |
//! the debug file of the actual input |
| 258 |
libmwaw::DebugFile m_asciiFile; |
| 259 |
|
| 260 |
//! the graph document |
| 261 |
std::shared_ptr<MsWksGraph> m_graphParser; |
| 262 |
//! the text document (for v1-3 document) |
| 263 |
std::shared_ptr<MsWks3Text> m_textParser3; |
| 264 |
//! the text document (for v4 document) |
| 265 |
std::shared_ptr<MsWks4Text> m_textParser4; |
| 266 |
|
| 267 |
/** callback used to send a page break */ |
| 268 |
typedef void (MWAWParser::* NewPage)(int page, bool softBreak); |
| 269 |
|
| 270 |
/** the new page callback */ |
| 271 |
NewPage m_newPage; |
| 272 |
}; |
| 273 |
#endif |
| 274 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |