[go: up one dir, main page]

Menu

[2117e7]: / src / lib / Lotus.h  Maximize  Restore  History

Download this file

230 lines (196 with data), 7.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* libwps
* Version: MPL 2.0 / LGPLv2.1+
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Major Contributor(s):
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
* Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU Lesser General Public License Version 2.1 or later
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
* applicable instead of those above.
*/
#ifndef LOTUS_H
#define LOTUS_H
#include <vector>
#include <librevenge-stream/librevenge-stream.h>
#include "libwps_internal.h"
#include "libwps_tools_win.h"
#include "WPSDebug.h"
#include "WKSParser.h"
namespace LotusParserInternal
{
class SubDocument;
struct State;
}
class LotusGraph;
class LotusChart;
class LotusSpreadsheet;
class LotusStyleManager;
class WPSGraphicStyle;
class WPSOLE1Parser;
/* .wk3: a spreadsheet is composed in two files
+ a wk3 file which contains the spreadsheet data
+ a fm3 file which contains the different formatings
.wk4: the file contains three parts:
+ the wk3 previous file
+ the fm3 file
+ an unknown part, which may code the file structure,
Normally the wk3 and the fm3 are a sequence of small zones,
but picture seems to be appeared at random position inside the
fm3 part (and even inside some structure fm3 structures...)
search for .ole and OLE1
.123: the file contains at least two parts:
+ the 123 storing the spreadsheet's data and format
+ the last part containing the file's structure
+ some optional part containing chart, picture, ...
*/
/**
* This class parses a wk3,wk4,123 Lotus spreadsheet
*
*/
class LotusParser final : public WKSParser
{
friend class LotusParserInternal::SubDocument;
friend class LotusChart;
friend class LotusGraph;
friend class LotusSpreadsheet;
friend class LotusStyleManager;
public:
//! constructor
LotusParser(RVNGInputStreamPtr &input, WPSHeaderPtr &header,
libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::UNKNOWN,
char const *password=nullptr);
//! destructor
~LotusParser() final;
//! called by WPSDocument to parse the file
void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) final;
//! checks if the document header is correct (or not)
bool checkHeader(WPSHeader *header, bool strict=false);
//! basic struct used to store link
struct Link
{
//! constructor
Link() : m_name(), m_linkName()
{
}
//! the basic name(used to retrieve a data)
std::string m_name;
//! the cell positions
WPSVec3i m_cells[2];
//! the link name
librevenge::RVNGString m_linkName;
};
protected:
//! return the file version
int version() const;
//
// interface
//
//! returns the font corresponding to an id
bool getFont(int id, WPSFont &font, libwps_tools_win::Font::Type &type) const;
/** returns the default font type, ie. the encoding given by the constructor if given
or the encoding deduced from the version.
*/
libwps_tools_win::Font::Type getDefaultFontType() const;
//! returns a list of links corresponding to an id
std::vector<Link> getLinksList(int lId) const;
//
// interface with LotusChart
//
//! try to send a chart
bool sendChart(int cId, WPSPosition const &pos, WPSGraphicStyle const &style);
//
// interface with LotusGraph
//
//! return true if the sheet sheetId has some graphic
bool hasGraphics(int sheetId) const;
//! send the graphics corresponding to a sheetId
void sendGraphics(int sheetId);
//
// interface with LotusSpreadsheet
//
//! returns the left top position of a cell
bool getLeftTopPosition(Vec2i const &cell, int spreadsheet, Vec2f &pos) const;
//! returns the name of the id's spreadsheet
librevenge::RVNGString getSheetName(int id) const;
//
// interface with WPSOLE1Parser
//
/** try to retrieve the content of a graphic, knowing it local id */
bool updateEmbeddedObject(int id, WPSEmbeddedObject &object) const;
/** try to parse the different zones */
bool createZones();
/** creates the main listener */
bool createListener(librevenge::RVNGSpreadsheetInterface *interface);
//
// low level
//
/// check for the existence of a format stream, if it exists, parse it
bool parseFormatStream();
//! checks if the document header is correct (or not)
bool checkHeader(std::shared_ptr<WPSStream> stream, bool mainStream, bool strict);
/** finds the different zones (spreadsheet, chart, print, ...) */
bool readZones(std::shared_ptr<WPSStream> stream);
/** parse the different zones 1B */
bool readDataZone(std::shared_ptr<WPSStream> stream);
//! reads a zone
bool readZone(std::shared_ptr<WPSStream> &stream);
//! reads a zone of type 1: 123 files
bool readZone1(std::shared_ptr<WPSStream> stream);
//! reads a zone of type 2: 123 files
bool readSheetZone(std::shared_ptr<WPSStream> stream);
//! reads a zone of type 4: 123 files
bool readZone4(std::shared_ptr<WPSStream> stream);
//! reads a zone of type 5: 123 files
bool readChartZone(std::shared_ptr<WPSStream> stream);
//! reads a zone of type 6: 123 files
bool readRefZone(std::shared_ptr<WPSStream> stream);
//! reads a zone of type 7: 123 files
bool readZone7(std::shared_ptr<WPSStream> stream);
//! reads a zone of type 8: 123 files
bool readZone8(std::shared_ptr<WPSStream> stream);
//! reads a zone of type a: 123 files
bool readVersionZone(std::shared_ptr<WPSStream> stream);
//! parse a wk123 zone
bool readZoneV3(std::shared_ptr<WPSStream> stream);
//! find the default encoding if no encoding is given
void findDefaultEncoding(std::shared_ptr<WPSStream> &stream);
//////////////////////// generic ////////////////////////////////////
//! reads a mac font name
bool readMacFontName(std::shared_ptr<WPSStream> stream, long endPos);
//! reads a format style name: b6
bool readFMTStyleName(std::shared_ptr<WPSStream> stream);
//! reads a link
bool readLinkZone(std::shared_ptr<WPSStream> stream);
//! reads a mac document info zone: zone 1b, then 2af8
bool readDocumentInfoMac(std::shared_ptr<WPSStream> stream, long endPos);
//////////////////////// decode a stream //////////////////////////////
//! try to decode a stream, if successful, replace the stream'input by the new one
static RVNGInputStreamPtr decodeStream(RVNGInputStreamPtr input, long endPos, std::vector<uint8_t> const &key);
//! try to guess a password knowing its file keys. Returns the keys if it founds a valid password
static std::vector<uint8_t> retrievePasswordKeys(std::vector<uint8_t> const &fileKeys);
std::shared_ptr<WKSContentListener> m_listener; /** the listener (if set)*/
//! the internal state
std::shared_ptr<LotusParserInternal::State> m_state;
//! the style manager
std::shared_ptr<LotusStyleManager> m_styleManager;
//! the chart manager
std::shared_ptr<LotusChart> m_chartParser;
//! the graph manager
std::shared_ptr<LotusGraph> m_graphParser;
//! the spreadsheet manager
std::shared_ptr<LotusSpreadsheet> m_spreadsheetParser;
//! the ole1 parser
std::shared_ptr<WPSOLE1Parser> m_ole1Parser;
};
#endif /* LOTUS_H */
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */