Debian Codegraph @

src/lib/MWAWTextListener.hxx

raw
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 /** \file MWAWTextListener.hxx
35 * Defines MWAWTextListener: the libmwaw word processor listener
36 *
37 * \note this class is the only class which does the interface with
38 * the librevenge::RVNGTextInterface
39 */
40 #ifndef MWAW_TEXT_LISTENER_H
41 #define MWAW_TEXT_LISTENER_H
42
43 #include <vector>
44
45 #include <librevenge/librevenge.h>
46
47 #include "libmwaw_internal.hxx"
48 #include "MWAWGraphicStyle.hxx"
49
50 #include "MWAWListener.hxx"
51
52 class MWAWCell;
53 class MWAWGraphicStyle;
54 class MWAWGraphicShape;
55 class MWAWTable;
56
57 namespace MWAWTextListenerInternal
58 {
59 struct DocumentState;
60 struct State;
61 }
62
63 /** This class contents the main functions needed to create a Word processing Document */
64 class MWAWTextListener final : public MWAWListener
65 {
66 public:
67 /** constructor */
68 MWAWTextListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, librevenge::RVNGTextInterface *documentInterface);
69 /** destructor */
70 ~MWAWTextListener() final;
71
72 /** returns the listener type */
73 Type getType() const final
74 {
75 return Text;
76 }
77
78 /** sets the documents metadata */
79 void setDocumentMetaData(librevenge::RVNGPropertyList const &metadata) final;
80 /** sets the documents language */
81 void setDocumentLanguage(std::string const &locale) final;
82
83 /** starts the document */
84 void startDocument() final;
85 /** ends the document */
86 void endDocument(bool sendDelayedSubDoc=true) final;
87 /** returns true if a document is opened */
88 bool isDocumentStarted() const final;
89
90 /** function called to add a subdocument */
91 void handleSubDocument(MWAWSubDocumentPtr const &subDocument, libmwaw::SubDocumentType subDocumentType) final;
92 /** returns try if a subdocument is open */
93 bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const final;
94 /** tries to open a frame */
95 bool openFrame(MWAWPosition const &pos, MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()) final;
96 /** tries to close the last open frame */
97 void closeFrame() final;
98 /** open a group */
99 bool openGroup(MWAWPosition const &pos) final;
100 /** close a group */
101 void closeGroup() final;
102
103 /** returns true if we can add text data */
104 bool canWriteText() const final
105 {
106 return MWAWTextListener::isDocumentStarted();
107 }
108
109 // ------ page --------
110 /** returns true if a page is opened */
111 bool isPageSpanOpened() const final;
112 /** returns the current page span
113
114 \note this forces the opening of a new page if no page is opened.*/
115 MWAWPageSpan const &getPageSpan() final;
116
117 // ------ header/footer --------
118 /** insert a header */
119 bool insertHeader(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) final;
120 /** insert a footer */
121 bool insertFooter(MWAWSubDocumentPtr const &subDocument, librevenge::RVNGPropertyList const &extras) final;
122 /** returns true if the header/footer is open */
123 bool isHeaderFooterOpened() const final;
124
125 // ------ text data -----------
126
127 //! adds a basic character, ..
128 void insertChar(uint8_t character) final;
129 /** insert a character using the font converter to find the utf8
130 character */
131 void insertCharacter(unsigned char c) final;
132 /** insert a character using the font converter to find the utf8
133 character and if needed, input to read extra character.
134
135 \return the number of extra character read
136 */
137 int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1) final;
138 /** adds an unicode character.
139 * By convention if \a character=0xfffd(undef), no character is added */
140 void insertUnicode(uint32_t character) final;
141 //! adds a unicode string
142 void insertUnicodeString(librevenge::RVNGString const &str) final;
143
144 //! adds a tab
145 void insertTab() final;
146 //! adds an end of line ( by default an hard one)
147 void insertEOL(bool softBreak=false) final;
148
149 // ------ text format -----------
150 //! sets the font
151 void setFont(MWAWFont const &font) final;
152 //! returns the actual font
153 MWAWFont const &getFont() const final;
154
155 // ------ paragraph format -----------
156 //! returns true if a paragraph or a list is opened
157 bool isParagraphOpened() const final;
158 //! sets the paragraph
159 void setParagraph(MWAWParagraph const &paragraph) final;
160 //! returns the actual paragraph
161 MWAWParagraph const &getParagraph() const final;
162
163 // ------- fields ----------------
164 //! adds a field type
165 void insertField(MWAWField const &field) final;
166
167 // ------- link ----------------
168 //! open a link
169 void openLink(MWAWLink const &link) final;
170 //! close a link
171 void closeLink() final;
172
173 // ------- subdocument -----------------
174 /** insert a note */
175 void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument) final;
176
177 /** adds comment */
178 void insertComment(MWAWSubDocumentPtr &subDocument) final;
179
180 /** adds a picture with potential various representationin given position */
181 void insertPicture(MWAWPosition const &pos, MWAWEmbeddedObject const &picture,
182 MWAWGraphicStyle const &style=MWAWGraphicStyle::emptyStyle()) final;
183 /** adds a shape picture in given position */
184 void insertShape(MWAWPosition const &pos, MWAWGraphicShape const &shape,
185 MWAWGraphicStyle const &style) final;
186 /** adds a textbox in given position */
187 void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr const &subDocument,
188 MWAWGraphicStyle const &frameStyle=MWAWGraphicStyle::emptyStyle()) final;
189
190 // ------- table -----------------
191 /** open a table*/
192 void openTable(MWAWTable const &table) final;
193 /** closes this table */
194 void closeTable() final;
195 /** open a row with given height ( if h < 0.0, set min-row-height = -h )*/
196 void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false) final;
197 /** closes this row */
198 void closeTableRow() final;
199 /** open a cell */
200 void openTableCell(MWAWCell const &cell) final;
201 /** close a cell */
202 void closeTableCell() final;
203 /** add empty cell */
204 void addEmptyTableCell(MWAWVec2i const &pos, MWAWVec2i span=MWAWVec2i(1,1)) final;
205
206 // ------- section ---------------
207 /** returns true if we can add open a section, add page break, ... */
208 bool canOpenSectionAddBreak() const final;
209 //! returns true if a section is opened
210 bool isSectionOpened() const final;
211 //! returns the actual section
212 MWAWSection const &getSection() const final;
213 //! open a section if possible
214 bool openSection(MWAWSection const &section) final;
215 //! close a section
216 bool closeSection() final;
217 //! inserts a break type: ColumBreak, PageBreak, ..
218 void insertBreak(BreakType breakType) final;
219
220 protected:
221 //! does open a section (low level)
222 void _openSection();
223 //! does close a section (low level)
224 void _closeSection();
225 //! does open a new page (low level)
226 void _openPageSpan(bool sendHeaderFooters=true);
227 //! does close a page (low level)
228 void _closePageSpan();
229
230 void _startSubDocument();
231 void _endSubDocument();
232
233 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, MWAWPosition const &pos);
234
235 void _openParagraph();
236 void _closeParagraph();
237 void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
238 void _resetParagraphState(const bool isListElement=false);
239
240 /** open a list level */
241 void _openListElement();
242 /** close a list level */
243 void _closeListElement();
244 /** update the list so that it corresponds to the actual level */
245 void _changeList();
246 /** low level: find a list id which corresponds to actual list and a change of level.
247
248 \note called when the list id is not set
249 */
250 int _getListId() const;
251
252 /** low level: the function which opens a new span property */
253 void _openSpan();
254 /** low level: the function which closes the last opened span property */
255 void _closeSpan();
256
257 /** low level: flush the deferred text */
258 void _flushText();
259 /** low level: flush the deferred tabs */
260 void _flushDeferredTabs();
261
262 void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
263
264 /** creates a new parsing state (copy of the actual state)
265 *
266 * \return the old one */
267 std::shared_ptr<MWAWTextListenerInternal::State> _pushParsingState();
268 //! resets the previous parsing state
269 void _popParsingState();
270
271 protected:
272 //! the main parse state
273 std::shared_ptr<MWAWTextListenerInternal::DocumentState> m_ds;
274 //! the actual local parse state
275 std::shared_ptr<MWAWTextListenerInternal::State> m_ps;
276 //! stack of local state
277 std::vector<std::shared_ptr<MWAWTextListenerInternal::State> > m_psStack;
278 //! the parser state
279 MWAWParserState &m_parserState;
280 //! the document interface
281 librevenge::RVNGTextInterface *m_documentInterface;
282
283 private:
284 //! copy constructor (unimplemented)
285 MWAWTextListener(const MWAWTextListener &) = delete;
286 //! operator= (unimplemented)
287 MWAWTextListener &operator=(const MWAWTextListener &) = delete;
288 };
289
290 #endif
291 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: