Debian Codegraph @

src/lib/WPS8Text.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 WPS8_TEXT_H
23 #define WPS8_TEXT_H
24
25 #include <vector>
26
27 #include "libwps_internal.h"
28
29 #include "WPSDebug.h"
30
31 #include "WPSTextParser.h"
32
33 namespace WPS8Struct
34 {
35 struct FileData;
36 }
37
38 namespace WPS8TextInternal
39 {
40 struct State;
41 class SubDocument;
42 }
43
44 class WPS8Parser;
45 class WPS8TextStyle;
46
47 class WPS8Text : public WPSTextParser
48 {
49 friend class WPS8TextInternal::SubDocument;
50 friend class WPS8Parser;
51 friend class WPS8TextStyle;
52 public:
53 explicit WPS8Text(WPS8Parser &parser);
54 ~WPS8Text() override;
55
56 //! sets the listener
57 void setListener(WPSContentListenerPtr &listen);
58
59 //! returns the number of pages
60 int numPages() const;
61
62 //! sends the data which have not yet been sent to the listener
63 void flushExtra();
64
65 //! finds all entries which correspond to the text data, parses them and stores data
66 bool readStructures();
67
68 //! returns the number of different text zones
69 int getNumTextZones() const;
70
71 /** returns the type of a text zone
72 *
73 * 1: mainzone, 2: footnote, 3: endnote, 4: ???, 5: text in table/textbox
74 * 6: header, 7: footer
75 **/
76 int getTextZoneType(int typeId) const;
77
78 //! returns the header entry (if such entry exists, if not returns an invalid entry)
79 WPSEntry getHeaderEntry() const;
80
81 //! returns the footer entry (if such entry exists, if not returns an invalid entry)
82 WPSEntry getFooterEntry() const;
83
84 //! returns the main zone entry (if such entry exists, if not returns an invalid entry)
85 WPSEntry getTextEntry() const;
86
87 //! returns ith zone entry (if such entry exists, if not returns an invalid entry)
88 WPSEntry getEntry(int strsId) const;
89
90 //! reads a text section and sends it to a listener
91 void readText(WPSEntry const &entry);
92
93 //! reads a cell section and sends it to a listener
94 void readTextInCell(int strsId, int cellId);
95
96 protected:
97 //! return the main parser
98 WPS8Parser &mainParser()
99 {
100 return reinterpret_cast<WPS8Parser &>(m_mainParser);
101 }
102 //! return the main parser
103 WPS8Parser const &mainParser() const
104 {
105 return reinterpret_cast<WPS8Parser const &>(m_mainParser);
106 }
107
108 //
109 // interface with WPS8TextStyle
110 //
111 //! reads a font properties
112 bool readFont(long endPos, int &id, std::string &mess);
113
114 //! the paragraph
115 bool readParagraph(long endPos, int &id, std::string &mess);
116
117 //
118 // String+text functions
119 //
120 //! reads a string
121 static bool readString(RVNGInputStreamPtr input, long page_size,
122 librevenge::RVNGString &res);
123 //! reads a utf16 character, \return 0xfffd if an error
124 static long readUTF16LE(RVNGInputStreamPtr input, long endPos, uint16_t firstC);
125
126 /** \brief the footnote ( FTN or EDN )
127 *
128 * \note this function must be called after the creation of the text zones */
129 bool readNotes(WPSEntry const &entry);
130
131 /** \brief creates the notes association : text and notes positions
132 *
133 * \note must be called after all notes have been created */
134 void createNotesCorrespondance();
135
136 //----------------------------------------
137 // PLC parsing, setting
138 //----------------------------------------
139
140 /** definition of the plc data parser (low level)
141 *
142 * \param bot defines the begin of the text zone corresponding to these properties
143 * \param eot define the end of the text zone corresponding to these properties
144 * \param id the number of this properties
145 * \param data a reference to store the parsed data
146 * \param mess a string which can be filled to indicate unparsed data */
147 typedef bool (WPS8Text::* DataParser)
148 (long bot, long eot, int id, WPS8Struct::FileData const &data,
149 std::string &mess);
150 /** definition of the last part of plc data parser (low level)
151 *
152 * \param endPos the end of the properties' definition,
153 * \param textPtrs the list of text positions */
154 typedef bool (WPS8Text::* EndDataParser)
155 (long endPos, std::vector<long> const &textPtrs);
156 /** reads a PLC (Pointer List Composant ?) in zone entry
157 *
158 * \param entry the file zone
159 * \param textPtrs lists of offset in text zones where properties changes
160 * \param listValues lists of properties values (filled only if values are simple types: int, ..)
161 * \param parser the parser to use to read the values
162 * \param endParser the parser to use to read remaining data */
163 bool readPLC(WPSEntry const &entry,
164 std::vector<long> &textPtrs, std::vector<long> &listValues,
165 DataParser parser = &WPS8Text::defDataParser,
166 EndDataParser endParser = nullptr);
167 //! default parser
168 bool defDataParser
169 (long, long, int, WPS8Struct::FileData const &data, std::string &mess);
170 //! the text zones parser: STRS
171 bool textZonesDataParser(long bot, long eot, int nId,
172 WPS8Struct::FileData const &data,
173 std::string &mess);
174 // object
175 //! reads a EOBJ properties: an object id and its size, ...
176 bool objectDataParser(long bot, long eot, int id,
177 WPS8Struct::FileData const &data, std::string &mess);
178 // field type
179 //! reads a field type : TOKN zone
180 bool tokenEndDataParser(long endPage, std::vector<long> const &textPtrs);
181 /** \brief reads a field type : BMKT zone
182 \warning the read data are NOT used*/
183 bool bmktEndDataParser(long endPage, std::vector<long> const &textPtrs);
184
185 protected:
186 //! the listener
187 WPSContentListenerPtr m_listener;
188 //! the graph parser
189 std::shared_ptr<WPS8TextStyle> m_styleParser;
190 //! the internal state
191 mutable std::shared_ptr<WPS8TextInternal::State> m_state;
192 protected:
193 };
194
195
196 #endif /* WPS8_TEXT_H */
197 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */