Debian Codegraph @

src/lib/WPSContentListener.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) 2006 Fridrich Strba ([email protected])
12 * Copyright (C) 2003-2005 William Lachance ([email protected])
13 * Copyright (C) 2003 Marc Maurer ([email protected])
14 *
15 * For minor contributions see the git repository.
16 *
17 * Alternatively, the contents of this file may be used under the terms
18 * of the GNU Lesser General Public License Version 2.1 or later
19 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
20 * applicable instead of those above.
21 *
22 * For further information visit http://libwps.sourceforge.net
23 */
24
25 #ifndef WPSCONTENTLISTENER_H
26 #define WPSCONTENTLISTENER_H
27
28 #include <vector>
29
30 #include <librevenge/librevenge.h>
31
32 #include "libwps_internal.h"
33
34 #include "WPSListener.h"
35
36 class WPSList;
37 class WPSPageSpan;
38 struct WPSParagraph;
39 struct WPSTabStop;
40
41 struct WPSContentParsingState;
42 struct WPSDocumentParsingState;
43
44 class WPSContentListener final : public WPSListener
45 {
46 public:
47 WPSContentListener(std::vector<WPSPageSpan> const &pageList, librevenge::RVNGTextInterface *documentInterface);
48 ~WPSContentListener() final;
49
50 void setDocumentLanguage(int lcid) final;
51 void setMetaData(const librevenge::RVNGPropertyList &list);
52
53 void startDocument();
54 void endDocument();
55 void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
56 bool isHeaderFooterOpened() const;
57
58 // ------ text data -----------
59
60 //! adds a basic character, ..
61 void insertCharacter(uint8_t character) final;
62 /** adds an unicode character
63 *
64 * by convention if \a character=0xfffd(undef), no character is added */
65 void insertUnicode(uint32_t character) final;
66 //! adds a unicode string
67 void insertUnicodeString(librevenge::RVNGString const &str) final;
68
69 void insertTab() final;
70 void insertEOL(bool softBreak=false) final;
71 void insertBreak(const uint8_t breakType) final;
72
73 // ------ text format -----------
74 //! set the actual font
75 void setFont(const WPSFont &font) final;
76 //! returns the actual font
77 WPSFont const &getFont() const final;
78
79 // ------ paragraph format -----------
80 //! returns true if a paragraph or a list is opened
81 bool isParagraphOpened() const final;
82 //! sets the actual paragraph
83 void setParagraph(const WPSParagraph &para) final;
84 //! returns the actual paragraph
85 WPSParagraph const &getParagraph() const final;
86
87 // ------ list format -----------
88 /** function to set the actual list */
89 void setCurrentList(std::shared_ptr<WPSList> list);
90 /** returns the current list */
91 std::shared_ptr<WPSList> getCurrentList() const;
92
93 // ------- fields ----------------
94 //! adds a field
95 void insertField(WPSField const &field) final;
96
97 // ------- subdocument -----------------
98 /** defines the footnote type */
99 enum NoteType { FOOTNOTE, ENDNOTE };
100 /** adds note */
101 void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument);
102 /** adds a label note */
103 void insertLabelNote(const NoteType noteType, librevenge::RVNGString const &label, WPSSubDocumentPtr &subDocument);
104 /** adds comment */
105 void insertComment(WPSSubDocumentPtr &subDocument);
106
107 /** adds a picture in given position */
108 void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
109 std::string const &type="image/pict",
110 librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
111 /** adds an object with replacement picture in given position */
112 void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj,
113 librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
114
115 /** adds a textbox in given position */
116 void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
117 librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
118 /** open a group */
119 bool openGroup(WPSPosition const &pos) final;
120 /** close a group */
121 void closeGroup() final;
122
123 // ------- table -----------------
124 /** open a table*/
125 void openTable(std::vector<float> const &colWidth, librevenge::RVNGUnit unit);
126 /** closes this table */
127 void closeTable();
128 /** open a row with given height. If h<0, use min-row-heigth */
129 void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
130 /** closes this row */
131 void closeTableRow();
132 /** low level function to define a cell.
133 \param cell the cell position, alignement, ...
134 \param extras to be used to pass extra data, for instance spreadsheet data*/
135 void openTableCell(WPSCell const &cell, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList());
136 /** close a cell */
137 void closeTableCell();
138 /** add empty cell */
139 void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
140
141 // ------- section ---------------
142 //! returns true if a section is opened
143 bool isSectionOpened() const;
144 //! returns the actual number of columns ( or 1 if no section is opened )
145 int getSectionNumColumns() const;
146 //! open a section if possible
147 bool openSection(std::vector<int> colsWidth=std::vector<int>(), librevenge::RVNGUnit unit=librevenge::RVNG_INCH);
148 //! close a section
149 bool closeSection();
150
151 protected:
152 void _openSection();
153 void _closeSection();
154
155 void _openPageSpan();
156 void _closePageSpan();
157 void _updatePageSpanDependent(bool set);
158
159 void _startSubDocument();
160 void _endSubDocument();
161
162 void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos);
163 bool _openFrame(WPSPosition const &pos, librevenge::RVNGPropertyList extras=librevenge::RVNGPropertyList());
164 void _closeFrame();
165
166 void _openParagraph();
167 void _closeParagraph();
168 void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
169 void _resetParagraphState(const bool isListElement=false);
170
171 void _openListElement();
172 void _closeListElement();
173 void _changeList();
174
175 void _openSpan();
176 void _closeSpan();
177
178 void _flushText();
179 void _flushDeferredTabs();
180
181 void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
182
183 /** creates a new parsing state (copy of the actual state)
184 *
185 * \return the old one */
186 std::shared_ptr<WPSContentParsingState> _pushParsingState();
187 //! resets the previous parsing state
188 void _popParsingState();
189
190 protected:
191 std::shared_ptr<WPSDocumentParsingState> m_ds; // main parse state
192 std::shared_ptr<WPSContentParsingState> m_ps; // parse state
193 std::vector<std::shared_ptr<WPSContentParsingState> > m_psStack;
194 librevenge::RVNGTextInterface *m_documentInterface;
195
196 private:
197 WPSContentListener(const WPSContentListener &);
198 WPSContentListener &operator=(const WPSContentListener &);
199 };
200
201 #endif
202 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */