WPSContentListener.h
Go to the documentation of this file.
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 (fridrich.strba@bluewin.ch)
12  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
13  * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
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 
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 
61  void insertCharacter(uint8_t character) final;
65  void insertUnicode(uint32_t character) final;
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 -----------
75  void setFont(const WPSFont &font) final;
77  WPSFont const &getFont() const final;
78 
79  // ------ paragraph format -----------
81  bool isParagraphOpened() const final;
83  void setParagraph(const WPSParagraph &para) final;
85  WPSParagraph const &getParagraph() const final;
86 
87  // ------ list format -----------
89  void setCurrentList(std::shared_ptr<WPSList> list);
91  std::shared_ptr<WPSList> getCurrentList() const;
92 
93  // ------- fields ----------------
95  void insertField(WPSField const &field) final;
96 
97  // ------- subdocument -----------------
101  void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument);
103  void insertLabelNote(const NoteType noteType, librevenge::RVNGString const &label, WPSSubDocumentPtr &subDocument);
105  void insertComment(WPSSubDocumentPtr &subDocument);
106 
108  void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData,
109  std::string type="image/pict",
110  librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
112  void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj,
113  librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
114 
116  void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
117  librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList());
119  bool openGroup(WPSPosition const &pos) final;
121  void closeGroup() final;
122 
123  // ------- table -----------------
125  void openTable(std::vector<float> const &colWidth, librevenge::RVNGUnit unit);
127  void closeTable();
129  void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false);
131  void closeTableRow();
135  void openTableCell(WPSCell const &cell, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList());
137  void closeTableCell();
139  void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
140 
141  // ------- section ---------------
143  bool isSectionOpened() const;
145  int getSectionNumColumns() const;
147  bool openSection(std::vector<int> colsWidth=std::vector<int>(), librevenge::RVNGUnit unit=librevenge::RVNG_INCH);
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 
186  std::shared_ptr<WPSContentParsingState> _pushParsingState();
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:
198  WPSContentListener &operator=(const WPSContentListener &);
199 };
200 
201 #endif
202 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
void insertPicture(WPSPosition const &pos, const librevenge::RVNGBinaryData &binaryData, std::string type="image/pict", librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList())
adds a picture in given position
Definition: WPSContentListener.cpp:1144
void _closeParagraph()
Definition: WPSContentListener.cpp:751
WPSFont const & getFont() const final
returns the actual font
Definition: WPSContentListener.cpp:368
void startDocument()
Definition: WPSContentListener.cpp:546
void _updatePageSpanDependent(bool set)
Definition: WPSContentListener.cpp:659
class to store the paragraph properties
Definition: WPSParagraph.h:57
void insertCharacter(uint8_t character) final
adds a basic character, ..
Definition: WPSContentListener.cpp:227
void insertTab() final
adds an unicode character to a string ( with correct encoding ).
Definition: WPSContentListener.cpp:276
void setMetaData(const librevenge::RVNGPropertyList &list)
Definition: WPSContentListener.cpp:536
void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList)
Definition: WPSContentListener.cpp:334
void _flushText()
Definition: WPSContentListener.cpp:1001
void _closeListElement()
Definition: WPSContentListener.cpp:847
the document state
Definition: WPSContentListener.cpp:46
void insertLabelNote(const NoteType noteType, librevenge::RVNGString const &label, WPSSubDocumentPtr &subDocument)
adds a label note
Definition: WPSContentListener.cpp:1046
Definition: WPSOLEStream.h:33
void _flushDeferredTabs()
Definition: WPSContentListener.cpp:978
define the font properties
Definition: WPSFont.h:36
void _popParsingState()
resets the previous parsing state
Definition: WPSContentListener.cpp:1818
a field
Definition: libwps_internal.h:462
the content state
Definition: WPSContentListener.cpp:85
void closeTable()
closes this table
Definition: WPSContentListener.cpp:1687
virtual class for content listener
Definition: WPSListener.h:36
void _changeList()
Definition: WPSContentListener.cpp:864
void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false)
Definition: WPSContentListener.cpp:793
void openTable(std::vector< float > const &colWidth, librevenge::RVNGUnit unit)
open a table
Definition: WPSContentListener.cpp:1651
std::shared_ptr< WPSContentParsingState > m_ps
Definition: WPSContentListener.h:192
bool isSectionOpened() const
returns true if a section is opened
Definition: WPSContentListener.cpp:449
std::shared_ptr< WPSList > getCurrentList() const
returns the current list
Definition: WPSContentListener.cpp:419
void _openPageSpan()
Definition: WPSContentListener.cpp:591
bool isHeaderFooterOpened() const
Definition: WPSContentListener.cpp:1626
std::shared_ptr< WPSSubDocument > WPSSubDocumentPtr
shared pointer to WPSSubDocument
Definition: libwps_internal.h:111
Definition: WPSContentListener.h:44
void endDocument()
Definition: WPSContentListener.cpp:562
void setDocumentLanguage(int lcid) final
Definition: WPSContentListener.cpp:528
Definition: WPSContentListener.h:99
void insertUnicodeString(librevenge::RVNGString const &str) final
adds a unicode string
Definition: WPSContentListener.cpp:248
a structure used to defined the cell position, and a format
Definition: WPSCell.h:288
librevenge::RVNGTextInterface * m_documentInterface
Definition: WPSContentListener.h:194
void _startSubDocument()
Definition: WPSContentListener.cpp:1631
void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument, librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList())
adds a textbox in given position
Definition: WPSContentListener.cpp:1131
void closeTableRow()
closes this row
Definition: WPSContentListener.cpp:1725
NoteType
defines the footnote type
Definition: WPSContentListener.h:99
void _closePageSpan()
Definition: WPSContentListener.cpp:647
void _endSubDocument()
Definition: WPSContentListener.cpp:1637
void insertUnicode(uint32_t character) final
adds an unicode character
Definition: WPSContentListener.cpp:239
void insertComment(WPSSubDocumentPtr &subDocument)
adds comment
Definition: WPSContentListener.cpp:1104
SubDocumentType
Definition: libwps_internal.h:248
a small structure used to store the informations about a list
Definition: WPSList.h:36
void closeGroup() final
close a group
Definition: WPSContentListener.cpp:1227
void _openListElement()
Definition: WPSContentListener.cpp:822
void openTableRow(float h, librevenge::RVNGUnit unit, bool headerRow=false)
open a row with given height.
Definition: WPSContentListener.cpp:1702
bool openGroup(WPSPosition const &pos) final
open a group
Definition: WPSContentListener.cpp:1173
void setCurrentList(std::shared_ptr< WPSList > list)
function to set the actual list
Definition: WPSContentListener.cpp:413
std::shared_ptr< WPSContentParsingState > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition: WPSContentListener.cpp:1798
void _openParagraph()
Definition: WPSContentListener.cpp:722
bool isParagraphOpened() const final
returns true if a paragraph or a list is opened
Definition: WPSContentListener.cpp:376
void setFont(const WPSFont &font) final
set the actual font
Definition: WPSContentListener.cpp:354
void _handleFrameParameters(librevenge::RVNGPropertyList &propList, WPSPosition const &pos)
Definition: WPSContentListener.cpp:1308
bool _openFrame(WPSPosition const &pos, librevenge::RVNGPropertyList extras=librevenge::RVNGPropertyList())
Definition: WPSContentListener.cpp:1239
~WPSContentListener() final
Definition: WPSContentListener.cpp:220
void _openSpan()
Definition: WPSContentListener.cpp:940
bool openSection(std::vector< int > colsWidth=std::vector< int >(), librevenge::RVNGUnit unit=librevenge::RVNG_INCH)
open a section if possible
Definition: WPSContentListener.cpp:459
WPSContentListener(std::vector< WPSPageSpan > const &pageList, librevenge::RVNGTextInterface *documentInterface)
Definition: WPSContentListener.cpp:211
bool closeSection()
close a section
Definition: WPSContentListener.cpp:507
void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType)
Definition: WPSContentListener.cpp:1538
void _resetParagraphState(const bool isListElement=false)
Definition: WPSContentListener.cpp:774
int getSectionNumColumns() const
returns the actual number of columns ( or 1 if no section is opened )
Definition: WPSContentListener.cpp:454
void insertField(WPSField const &field) final
adds a field
Definition: WPSContentListener.cpp:427
small class use to define a embedded object
Definition: libwps_internal.h:1076
void setParagraph(const WPSParagraph &para) final
sets the actual paragraph
Definition: WPSContentListener.cpp:386
void insertObject(WPSPosition const &pos, const WPSEmbeddedObject &obj, librevenge::RVNGPropertyList frameExtras=librevenge::RVNGPropertyList())
adds an object with replacement picture in given position
Definition: WPSContentListener.cpp:1157
Definition: WPSParagraph.h:37
void insertEOL(bool softBreak=false) final
Definition: WPSContentListener.cpp:255
Definition: WPSPageSpan.h:38
void closeTableCell()
close a cell
Definition: WPSContentListener.cpp:1777
std::shared_ptr< WPSDocumentParsingState > m_ds
Definition: WPSContentListener.h:191
void _closeFrame()
Definition: WPSContentListener.cpp:1296
void _openSection()
Definition: WPSContentListener.cpp:666
void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument)
adds note
Definition: WPSContentListener.cpp:1035
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: WPSPosition.h:39
Definition: WPSContentListener.h:99
void _closeSection()
Definition: WPSContentListener.cpp:703
void _closeSpan()
Definition: WPSContentListener.cpp:965
void insertBreak(const uint8_t breakType) final
Definition: WPSContentListener.cpp:288
std::vector< std::shared_ptr< WPSContentParsingState > > m_psStack
Definition: WPSContentListener.h:193
void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1, 1))
add empty cell
Definition: WPSContentListener.cpp:1736
void openTableCell(WPSCell const &cell, librevenge::RVNGPropertyList const &extras=librevenge::RVNGPropertyList())
low level function to define a cell.
Definition: WPSContentListener.cpp:1757
WPSParagraph const & getParagraph() const final
returns the actual paragraph
Definition: WPSContentListener.cpp:381

Generated on Fri May 27 2022 03:07:00 for libwps by doxygen 1.8.14