Debian Codegraph @

src/lib/Quattro.h

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
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 * Major Contributor(s):
10 * Copyright (C) 2006, 2007 Andrew Ziem
11 * Copyright (C) 2003-2005 William Lachance ([email protected])
12 * Copyright (C) 2003 Marc Maurer ([email protected])
13 *
14 * For minor contributions see the git repository.
15 *
16 * Alternatively, the contents of this file may be used under the terms
17 * of the GNU Lesser General Public License Version 2.1 or later
18 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19 * applicable instead of those above.
20 */
21
22 #ifndef QUATTRO_H
23 #define QUATTRO_H
24
25 #include <vector>
26
27 #include <librevenge-stream/librevenge-stream.h>
28 #include "libwps/libwps.h"
29
30 #include "libwps_internal.h"
31 #include "libwps_tools_win.h"
32
33 #include "WKSParser.h"
34
35 namespace QuattroParserInternal
36 {
37 class SubDocument;
38 struct State;
39 }
40
41 //class QuattroChart;
42 class QuattroGraph;
43 class QuattroSpreadsheet;
44
45 namespace QuattroFormulaInternal
46 {
47 class CellReference;
48 }
49 /**
50 * This class parses Quattro Pro spreadsheet: .wb1, ..., .wb3
51 *
52 */
53 class QuattroParser final : public WKSParser
54 {
55 friend class QuattroParserInternal::SubDocument;
56 //friend class QuattroChart;
57 friend class QuattroGraph;
58 friend class QuattroSpreadsheet;
59 public:
60 //! constructor
61 QuattroParser(RVNGInputStreamPtr &input, WPSHeaderPtr &header,
62 libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::UNKNOWN,
63 char const *password=nullptr);
64 //! destructor
65 ~QuattroParser() final;
66 //! called by WPSDocument to parse the file
67 void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) final;
68 //! checks if the document header is correct (or not)
69 bool checkHeader(WPSHeader *header, bool strict=false);
70
71 protected:
72 //! return the file version
73 int version() const;
74 /** returns the default font type, ie. the encoding given by the constructor if given
75 or the encoding deduced from the version.
76 */
77 libwps_tools_win::Font::Type getDefaultFontType() const;
78 //! returns the name of the fId file
79 bool getExternalFileName(int fId, librevenge::RVNGString &fName) const;
80 //! returns the text and cell of a field instruction
81 bool getField(int fId, librevenge::RVNGString &text,
82 QuattroFormulaInternal::CellReference &ref,
83 librevenge::RVNGString const &fileName) const;
84
85 //
86 // interface with QuattroSpreadsheet
87 //
88
89 //! returns the color corresponding to an id
90 bool getColor(int id, WPSColor &color) const;
91 //! returns the font corresponding to an id
92 bool getFont(int id, WPSFont &font, libwps_tools_win::Font::Type &type) const;
93 //! returns the beginning position of a cell
94 Vec2f getCellPosition(int sheetId, Vec2i const &cell) const;
95
96 //
97 // interface with QuattroGraph
98 //
99
100 //! send the page graphic corresponding to a sheet
101 bool sendPageGraphics(int sheetId) const;
102 //! send the graphic corresponding to a cell
103 bool sendGraphics(int sheetId, Vec2i const &cell) const;
104
105 //
106 //
107 //
108
109 /** creates the main listener */
110 std::shared_ptr<WKSContentListener> createListener(librevenge::RVNGSpreadsheetInterface *interface);
111
112 //! send the header/footer
113 void sendHeaderFooter(bool header);
114
115 //
116 // low level
117 //
118
119 //! checks if the document header is correct (or not)
120 bool checkHeader(std::shared_ptr<WPSStream> stream, bool strict);
121 /** finds the different zones (spreadsheet, chart, print, ...) */
122 bool readZones();
123 /** finds the different OLE zones: wb2 */
124 bool readOLEZones(std::shared_ptr<WPSStream> &stream);
125 /** try to read a zone */
126 bool readZone(std::shared_ptr<WPSStream> &stream);
127
128 //////////////////////// generic ////////////////////////////////////
129
130 //! read a list of field name + ...: zone b
131 bool readFieldName(std::shared_ptr<WPSStream> stream);
132 /** read the cell's position: zone 96*/
133 static bool readCellPosition(std::shared_ptr<WPSStream> stream);
134 //! read a external filename/name: zone 97,98
135 bool readExternalData(std::shared_ptr<WPSStream> stream);
136 //! read a font: zone cf, fc and 110
137 bool readFontDef(std::shared_ptr<WPSStream> stream);
138 //! read a color lits: zone e8
139 bool readColorList(std::shared_ptr<WPSStream> stream);
140 //! read a style name: zone d0
141 bool readStyleName(std::shared_ptr<WPSStream> stream);
142 //! reads the header/footer: zone 25,26
143 bool readHeaderFooter(std::shared_ptr<WPSStream> stream, bool header);
144 //! read the pane attribute: d1
145 bool readPaneAttribute(std::shared_ptr<WPSStream> stream);
146 //! read the first optimizer zone: 103
147 bool readOptimizer(std::shared_ptr<WPSStream> stream);
148 //! read the table query command zone: 12f
149 bool readQueryCommand(std::shared_ptr<WPSStream> stream);
150 //! read the serie extension zone: 2dc
151 static bool readSerieExtension(std::shared_ptr<WPSStream> stream);
152 //! try to read a basic C string, knowing the maximum size
153 bool readCString(std::shared_ptr<WPSStream> stream, librevenge::RVNGString &string, long maxSize);
154
155 //////////////////////// unknown zone ////////////////////////////////////
156
157 /** reads some cell reference list (potential followed by other data)*/
158 bool readBlockList(std::shared_ptr<WPSStream> stream);
159 /** reads a big zone(chart?) which contains sub zones: 341 */
160 bool readZone341(std::shared_ptr<WPSStream> stream);
161
162 //////////////////////// Ole specific zone ////////////////////////////////////
163
164 /** try to parse the OLE stream(except the main stream) */
165 bool parseOLEStream(RVNGInputStreamPtr input, std::string const &avoid="");
166 /** try to read the link info sub stream */
167 bool readOleLinkInfo(std::shared_ptr<WPSStream> stream, librevenge::RVNGString &link);
168 /** try to read the BOlePart sub stream: a zone which contains 5 long */
169 static bool readOleBOlePart(std::shared_ptr<WPSStream> stream);
170
171 //////////////////////// decode a quattro stream //////////////////////////////
172
173 //! try to decode a stream, if successful, replace the stream'input by the new one
174 RVNGInputStreamPtr decodeStream(RVNGInputStreamPtr input, std::vector<uint8_t> const &key) const;
175
176 std::shared_ptr<WKSContentListener> m_listener; /** the listener (if set)*/
177 //! the internal state
178 std::shared_ptr<QuattroParserInternal::State> m_state;
179 // the chart manager
180 // std::shared_ptr<QuattroChart> m_chartParser;
181 //! the graph manager
182 std::shared_ptr<QuattroGraph> m_graphParser;
183 //! the spreadsheet manager
184 std::shared_ptr<QuattroSpreadsheet> m_spreadsheetParser;
185 };
186
187 #endif /* WPS4_H */
188 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */