Coverage Report

Created: 2026-06-13 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwps/src/lib/Quattro9.h
Line
Count
Source
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 (william.lachance@sympatico.ca)
12
 * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
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_9_H
23
#define QUATTRO_9_H
24
25
#include <map>
26
#include <vector>
27
28
#include <librevenge-stream/librevenge-stream.h>
29
#include "libwps/libwps.h"
30
31
#include "libwps_internal.h"
32
#include "libwps_tools_win.h"
33
34
#include "WPSEntry.h"
35
#include "WKSParser.h"
36
#include "WPSGraphicStyle.h"
37
38
namespace Quattro9ParserInternal
39
{
40
class SubDocument;
41
struct State;
42
43
struct TextEntry
44
{
45
  //! constructor
46
  TextEntry()
47
471k
    : m_entry()
48
471k
    , m_fontsList()
49
471k
    , m_posFontIdMap()
50
471k
    , m_flag(0)
51
471k
    , m_extra()
52
471k
  {
53
471k
  }
54
  //! returns true if the string is empty
55
  bool empty() const
56
292k
  {
57
292k
    return !m_entry.valid();
58
292k
  }
59
  //! returns the string
60
  librevenge::RVNGString getString(std::shared_ptr<WPSStream> const &stream, libwps_tools_win::Font::Type type=libwps_tools_win::Font::WIN3_WEUROPE) const;
61
  //! sends the text to the main listener
62
  void send(std::shared_ptr<WPSStream> const &stream, WPSFont const &font, libwps_tools_win::Font::Type type, WKSContentListenerPtr &listener);
63
  //! internal: returns a debug string
64
  std::string getDebugString(std::shared_ptr<WPSStream> const &stream) const;
65
  //! the text entry
66
  WPSEntry m_entry;
67
  //! the list of fonts
68
  std::vector<WPSFont> m_fontsList;
69
  //! the position to font map(complex text)
70
  std::map<int, int> m_posFontIdMap;
71
  //! the flag
72
  int m_flag;
73
  //! extra data
74
  std::string m_extra;
75
};
76
}
77
78
class Quattro9Graph;
79
class Quattro9Spreadsheet;
80
81
namespace QuattroFormulaInternal
82
{
83
class CellReference;
84
}
85
86
/**
87
 * This class parses Quattro Pro WP spreadsheet: .qpw
88
 *
89
 */
90
class Quattro9Parser final : public WKSParser
91
{
92
  friend class Quattro9ParserInternal::SubDocument;
93
  friend class Quattro9Graph;
94
  friend class Quattro9Spreadsheet;
95
96
public:
97
  //! constructor
98
  Quattro9Parser(RVNGInputStreamPtr &input, WPSHeaderPtr &header,
99
                 libwps_tools_win::Font::Type encoding=libwps_tools_win::Font::UNKNOWN,
100
                 char const *password=nullptr);
101
  //! destructor
102
  ~Quattro9Parser() final;
103
  //! called by WPSDocument to parse the file
104
  void parse(librevenge::RVNGSpreadsheetInterface *documentInterface) final;
105
  //! checks if the document header is correct (or not)
106
  bool checkHeader(WPSHeader *header, bool strict=false);
107
108
protected:
109
  //! return the file version
110
  int version() const;
111
  //! return the file sub version
112
  int subversion() const;
113
  /** returns the default font type, ie. the encoding given by the constructor if given
114
    or the encoding deduced from the version.
115
   */
116
  libwps_tools_win::Font::Type getDefaultFontType() const;
117
  //! returns the name of the fId file
118
  bool getExternalFileName(int fId, librevenge::RVNGString &fName) const;
119
  //! returns the text and cell of a field instruction
120
  bool getField(int fId, librevenge::RVNGString &text,
121
                QuattroFormulaInternal::CellReference &ref,
122
                librevenge::RVNGString const &fileName) const;
123
124
  //
125
  // interface with Quattro9Spreadsheet
126
  //
127
128
  //! returns the font corresponding to an id
129
  bool getFont(int id, WPSFont &font) const;
130
  //! returns the beginning position of a cell
131
  Vec2f getCellPosition(int sheetId, Vec2i const &cell) const;
132
133
  //
134
  // interface with Quattro9Graph
135
  //
136
137
  //! returns the color corresponding to an id
138
  bool getColor(int id, WPSColor &color) const;
139
  //! returns the pattern corresponding to a pattern id between 0 and 24
140
  bool getPattern(int id, WPSGraphicStyle::Pattern &pattern) const;
141
  //! send the page graphic corresponding to a sheet
142
  bool sendPageGraphics(int sheetId) const;
143
144
  //
145
  //
146
  //
147
148
  /** creates the main listener */
149
  std::shared_ptr<WKSContentListener> createListener(librevenge::RVNGSpreadsheetInterface *interface);
150
151
  //! send the header/footer
152
  void sendHeaderFooter(bool header);
153
154
  //
155
  // low level
156
  //
157
158
  //! checks if the document header is correct (or not)
159
  bool checkHeader(std::shared_ptr<WPSStream> stream, bool strict);
160
  /** finds the different zones in the main OLE stream (spreadsheet, chart, print, ...) */
161
  bool readZones();
162
  /** try to read a zone */
163
  bool readZone(std::shared_ptr<WPSStream> &stream);
164
165
  //////////////////////// generic ////////////////////////////////////
166
167
  /** try to read a string: length[2bytes], unknow[bytes] followed by the string */
168
  bool readPString(std::shared_ptr<WPSStream> const &stream, long endPos, Quattro9ParserInternal::TextEntry &entry);
169
  //! read a font name zone: zone 6
170
  bool readFontNames(std::shared_ptr<WPSStream> const &stream);
171
  //! read a font style zone: zone 7
172
  bool readFontStyles(std::shared_ptr<WPSStream> const &stream);
173
  //! read a zone which contains two files position (prev and next): zone 2,402,602,a02
174
  static bool readFilePositions(std::shared_ptr<WPSStream> const &stream, long (&filePos)[2]);
175
  //! read a zone 406 which contains a list of fields
176
  bool readDocumentFields(std::shared_ptr<WPSStream> const &stream);
177
  //! read a zone 407 which contains a list of stream
178
  bool readDocumentStrings(std::shared_ptr<WPSStream> const &stream);
179
180
  //! read a text entry style zone
181
  bool readTextStyles(std::shared_ptr<WPSStream> const &stream, long endPos, Quattro9ParserInternal::TextEntry &entry);
182
  //! read a font style in a text entry zone
183
  bool readTextFontStyles(std::shared_ptr<WPSStream> const &stream, int dataSz, WPSFont &font);
184
185
  //! add the document strings to the spreadsheetParser
186
  void addDocumentStrings();
187
188
  //////////////////////// unknown zone ////////////////////////////////////
189
190
191
  //////////////////////// Ole specific zone ////////////////////////////////////
192
193
  /** try to parse the OLE stream(except the main stream) */
194
  bool parseOLEStream(RVNGInputStreamPtr input, std::string const &avoid="");
195
  /** try to read the link info sub stream */
196
  static bool readOleLinkInfo(std::shared_ptr<WPSStream> stream);
197
  /** try to read the BOlePart sub stream: a zone which contains 5 long */
198
  static bool readOleBOlePart(std::shared_ptr<WPSStream> stream);
199
200
  //////////////////////// decode a quattro stream //////////////////////////////
201
202
  //! try to decode a stream, if successful, replace the stream'input by the new one
203
  static RVNGInputStreamPtr decodeStream(RVNGInputStreamPtr input, std::vector<uint8_t> const &key);
204
205
  std::shared_ptr<WKSContentListener> m_listener; /** the listener (if set)*/
206
  //! the internal state
207
  std::shared_ptr<Quattro9ParserInternal::State> m_state;
208
  //! the graph manager
209
  std::shared_ptr<Quattro9Graph> m_graphParser;
210
  //! the spreadsheet manager
211
  std::shared_ptr<Quattro9Spreadsheet> m_spreadsheetParser;
212
};
213
214
#endif /* WPS4_H */
215
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */