MWAWContentListener.hxx
Go to the documentation of this file.
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 (wrlach@gmail.com)
18 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
19 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
20 * Copyright (C) 2006, 2007 Andrew Ziem
21 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
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 #ifndef MWAW_CONTENT_LISTENER_H
35 #define MWAW_CONTENT_LISTENER_H
36 
37 #include <vector>
38 
39 #include <libwpd/libwpd.h>
40 
41 #include "libmwaw_internal.hxx"
42 
43 class WPXBinaryData;
44 class WPXDocumentInterface;
45 class WPXString;
46 class WPXPropertyListVector;
47 
48 class MWAWCell;
49 class MWAWFont;
50 class MWAWInputStream;
51 class MWAWList;
52 class MWAWPageSpan;
53 class MWAWParagraph;
54 class MWAWParserState;
55 class MWAWPosition;
56 class MWAWSection;
58 
59 typedef shared_ptr<MWAWInputStream> MWAWInputStreamPtr;
60 typedef shared_ptr<MWAWSubDocument> MWAWSubDocumentPtr;
61 
62 namespace MWAWContentListenerInternal
63 {
64 struct DocumentState;
65 struct State;
66 }
67 
69 {
70 public:
72 
74  MWAWContentListener(MWAWParserState &parserState, std::vector<MWAWPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
76  virtual ~MWAWContentListener();
77 
79  void setDocumentLanguage(std::string locale);
80 
82  void startDocument();
84  void endDocument(bool sendDelayedSubDoc=true);
85 
87  void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType);
89  bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const;
90 
91  // ------ page --------
93  bool isPageSpanOpened() const;
97  MWAWPageSpan const &getPageSpan();
98 
99  // ------ header/footer --------
101  bool insertHeader(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
103  bool insertFooter(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras);
105  bool isHeaderFooterOpened() const;
106 
107  // ------ text data -----------
108 
110  void insertChar(uint8_t character);
113  void insertCharacter(unsigned char c);
119  int insertCharacter(unsigned char c, MWAWInputStreamPtr &input, long endPos=-1);
122  void insertUnicode(uint32_t character);
124  void insertUnicodeString(WPXString const &str);
125 
127  void insertTab();
129  void insertEOL(bool softBreak=false);
131  void insertBreak(BreakType breakType);
132 
133  // ------ text format -----------
135  void setFont(MWAWFont const &font);
137  MWAWFont const &getFont() const;
138 
139  // ------ paragraph format -----------
141  bool isParagraphOpened() const;
143  void setParagraph(MWAWParagraph const &paragraph);
145  MWAWParagraph const &getParagraph() const;
146 
147  // ------- fields ----------------
149  void insertField(MWAWField const&field);
150 
151  // ------- subdocument -----------------
153  void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument);
154 
156  void insertComment(MWAWSubDocumentPtr &subDocument);
157 
159  void insertPicture(MWAWPosition const &pos, const WPXBinaryData &binaryData,
160  std::string type="image/pict",
161  WPXPropertyList frameExtras=WPXPropertyList());
163  void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument,
164  WPXPropertyList frameExtras=WPXPropertyList(),
165  WPXPropertyList textboxExtras=WPXPropertyList());
166 
167  // ------- table -----------------
169  void openTable(std::vector<float> const &colWidth, WPXUnit unit,
170  WPXPropertyList tableExtras=WPXPropertyList());
172  void closeTable();
174  void openTableRow(float h, WPXUnit unit, bool headerRow=false);
176  void closeTableRow();
180  void openTableCell(MWAWCell const &cell, WPXPropertyList const &extras);
182  void closeTableCell();
184  void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
185 
186  // ------- section ---------------
188  bool isSectionOpened() const;
190  MWAWSection const &getSection() const;
192  bool openSection(MWAWSection const &section);
194  bool closeSection();
195 
196 protected:
197  void _openSection();
198  void _closeSection();
199 
200  void _openPageSpan(bool sendHeaderFooters=true);
201  void _closePageSpan();
202 
203  void _startSubDocument();
204  void _endSubDocument();
205 
206  void _handleFrameParameters( WPXPropertyList &propList, MWAWPosition const &pos);
207  bool openFrame(MWAWPosition const &pos, WPXPropertyList extras=WPXPropertyList());
208  void closeFrame();
209 
210 
211  void _openParagraph();
212  void _closeParagraph();
213  void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
214  void _resetParagraphState(const bool isListElement=false);
215 
217  void _openListElement();
219  void _closeListElement();
221  void _changeList();
226  int _getListId() const;
227 
228  void _openSpan();
229  void _closeSpan();
230 
231  void _flushText();
232  void _flushDeferredTabs();
233 
234  void _insertBreakIfNecessary(WPXPropertyList &propList);
235 
239  shared_ptr<MWAWContentListenerInternal::State> _pushParsingState();
241  void _popParsingState();
242 
243 protected:
245  shared_ptr<MWAWContentListenerInternal::DocumentState> m_ds;
247  shared_ptr<MWAWContentListenerInternal::State> m_ps;
249  std::vector<shared_ptr<MWAWContentListenerInternal::State> > m_psStack;
253  WPXDocumentInterface *m_documentInterface;
254 
255 private:
258 };
259 
260 typedef shared_ptr<MWAWContentListener> MWAWContentListenerPtr;
261 
262 #endif
263 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
void _openParagraph()
Definition: MWAWContentListener.cxx:697
bool isHeaderFooterOpened() const
returns true if the header/footer is open
Definition: MWAWContentListener.cxx:581
bool isParagraphOpened() const
returns true if a paragraph or a list is opened
Definition: MWAWContentListener.cxx:380
void closeTable()
closes this table
Definition: MWAWContentListener.cxx:1490
shared_ptr< MWAWSubDocument > MWAWSubDocumentPtr
Definition: MSK4Zone.hxx:47
void _closeListElement()
close a list level
Definition: MWAWContentListener.cxx:800
shared_ptr< MWAWContentListenerInternal::DocumentState > m_ds
the main parse state
Definition: MWAWContentListener.hxx:245
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
Definition: ACText.hxx:44
void insertCharacter(unsigned char c)
insert a character using the font converter to find the utf8 character
Definition: MWAWContentListener.cxx:209
MWAWParagraph const & getParagraph() const
returns the actual paragraph
Definition: MWAWContentListener.cxx:392
MWAWPageSpan const & getPageSpan()
returns the current page span
Definition: MWAWContentListener.cxx:515
void insertField(MWAWField const &field)
adds a field type
Definition: MWAWContentListener.cxx:400
A class which defines the page properties.
Definition: MWAWPageSpan.hxx:100
bool isSectionOpened() const
returns true if a section is opened
Definition: MWAWContentListener.cxx:615
bool closeSection()
close a section
Definition: MWAWContentListener.cxx:641
bool openSection(MWAWSection const &section)
open a section if possible
Definition: MWAWContentListener.cxx:625
void handleSubDocument(MWAWSubDocumentPtr subDocument, libmwaw::SubDocumentType subDocumentType)
function called to add a subdocument
Definition: MWAWContentListener.cxx:1357
bool insertHeader(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras)
insert a header
Definition: MWAWContentListener.cxx:586
void _openSection()
Definition: MWAWContentListener.cxx:656
void openTableRow(float h, WPXUnit unit, bool headerRow=false)
open a row with given height ( if h &lt; 0.0, set min-row-height = -h )
Definition: MWAWContentListener.cxx:1504
void insertUnicode(uint32_t character)
adds an unicode character.
Definition: MWAWContentListener.cxx:251
void insertEOL(bool softBreak=false)
adds an end of line ( by default an hard one)
Definition: MWAWContentListener.cxx:268
void _flushText()
Definition: MWAWContentListener.cxx:946
SubDocumentType
Definition: libmwaw_internal.hxx:157
void insertComment(MWAWSubDocumentPtr &subDocument)
adds comment
Definition: MWAWContentListener.cxx:1031
void _insertBreakIfNecessary(WPXPropertyList &propList)
Definition: MWAWContentListener.cxx:340
void startDocument()
starts the document
Definition: MWAWContentListener.cxx:464
int _getListId() const
low level: find a list id which corresponds to actual list and a change of level. ...
Definition: MWAWContentListener.cxx:816
void insertTab()
adds a tab
Definition: MWAWContentListener.cxx:285
virtual ~MWAWContentListener()
destructor
Definition: MWAWContentListener.cxx:190
void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false)
Definition: MWAWContentListener.cxx:755
a structure used to defined the cell position, and a format
Definition: MWAWCell.hxx:295
Vec2< int > Vec2i
Vec2 of int.
Definition: libmwaw_internal.hxx:543
WPXDocumentInterface * m_documentInterface
the document interface
Definition: MWAWContentListener.hxx:253
shared_ptr< MWAWContentListener > MWAWContentListenerPtr
Definition: MWAWContentListener.hxx:260
void _handleFrameParameters(WPXPropertyList &propList, MWAWPosition const &pos)
Definition: MWAWContentListener.cxx:1161
shared_ptr< MWAWContentListenerInternal::State > m_ps
the actual local parse state
Definition: MWAWContentListener.hxx:247
void closeTableRow()
closes this row
Definition: MWAWContentListener.cxx:1525
void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1, 1))
add empty cell
Definition: MWAWContentListener.cxx:1535
bool isPageSpanOpened() const
returns true if a page is opened
Definition: MWAWContentListener.cxx:510
void openTableCell(MWAWCell const &cell, WPXPropertyList const &extras)
low level function to define a cell.
Definition: MWAWContentListener.cxx:1554
Internal class used to read the file stream Internal class used to read the file stream, this class adds some usefull functions to the basic WPXInputStream:
Definition: MWAWInputStream.hxx:59
Class to store font.
Definition: MWAWFont.hxx:47
void openTable(std::vector< float > const &colWidth, WPXUnit unit, WPXPropertyList tableExtras=WPXPropertyList())
open a table
Definition: MWAWContentListener.cxx:1454
a class to define the parser state
Definition: MWAWParser.hxx:60
void insertUnicodeString(WPXString const &str)
adds a unicode string
Definition: MWAWContentListener.cxx:261
void endDocument(bool sendDelayedSubDoc=true)
ends the document
Definition: MWAWContentListener.cxx:479
void _openPageSpan(bool sendHeaderFooters=true)
Definition: MWAWContentListener.cxx:523
void insertBreak(BreakType breakType)
inserts a break type: ColumBreak, PageBreak, ..
Definition: MWAWContentListener.cxx:296
bool insertFooter(MWAWSubDocumentPtr subDocument, WPXPropertyList const &extras)
insert a footer
Definition: MWAWContentListener.cxx:599
void _resetParagraphState(const bool isListElement=false)
Definition: MWAWContentListener.cxx:747
void _closeSection()
Definition: MWAWContentListener.cxx:677
abstract class used to store a subdocument (with a comparison function)
Definition: MWAWSubDocument.hxx:49
void _closeParagraph()
Definition: MWAWContentListener.cxx:726
void _openSpan()
Definition: MWAWContentListener.cxx:890
void _closeSpan()
Definition: MWAWContentListener.cxx:914
void _flushDeferredTabs()
Definition: MWAWContentListener.cxx:927
BreakType
Definition: MWAWContentListener.hxx:71
void _openListElement()
open a list level
Definition: MWAWContentListener.cxx:768
void setParagraph(MWAWParagraph const &paragraph)
sets the paragraph
Definition: MWAWContentListener.cxx:385
a class which stores section properties
Definition: MWAWSection.hxx:45
void setFont(MWAWFont const &font)
sets the font
Definition: MWAWContentListener.cxx:359
void _changeList()
update the list so that it corresponds to the actual level
Definition: MWAWContentListener.cxx:833
void insertTextBox(MWAWPosition const &pos, MWAWSubDocumentPtr subDocument, WPXPropertyList frameExtras=WPXPropertyList(), WPXPropertyList textboxExtras=WPXPropertyList())
adds a textbox in given position
Definition: MWAWContentListener.cxx:1056
MWAWFont const & getFont() const
returns the actual font
Definition: MWAWContentListener.cxx:375
class to store the paragraph properties
Definition: MWAWParagraph.hxx:83
void _endSubDocument()
Definition: MWAWContentListener.cxx:1440
void insertChar(uint8_t character)
adds a basic character, ..
Definition: MWAWContentListener.cxx:198
bool openFrame(MWAWPosition const &pos, WPXPropertyList extras=WPXPropertyList())
Definition: MWAWContentListener.cxx:1094
a field
Definition: libmwaw_internal.hxx:279
void insertNote(MWAWNote const &note, MWAWSubDocumentPtr &subDocument)
insert a note
Definition: MWAWContentListener.cxx:976
void _popParsingState()
resets the previous parsing state
Definition: MWAWContentListener.cxx:1718
bool isSubDocumentOpened(libmwaw::SubDocumentType &subdocType) const
returns try if a subdocument is open
Definition: MWAWContentListener.cxx:1426
MWAWParserState & m_parserState
the parser state
Definition: MWAWContentListener.hxx:251
a note
Definition: libmwaw_internal.hxx:297
Definition: MWAWContentListener.hxx:71
Class to define the position of an object (textbox, picture, ..) in the document. ...
Definition: MWAWPosition.hxx:47
MWAWContentListener & operator=(const MWAWContentListener &)
void _startSubDocument()
Definition: MWAWContentListener.cxx:1434
Definition: MWAWContentListener.hxx:68
void _closePageSpan()
Definition: MWAWContentListener.cxx:566
a small structure used to store the informations about a list
Definition: MWAWList.hxx:101
void closeFrame()
Definition: MWAWContentListener.cxx:1150
shared_ptr< MWAWContentListenerInternal::State > _pushParsingState()
creates a new parsing state (copy of the actual state)
Definition: MWAWContentListener.cxx:1704
Definition: MWAWContentListener.hxx:71
void insertPicture(MWAWPosition const &pos, const WPXBinaryData &binaryData, std::string type="image/pict", WPXPropertyList frameExtras=WPXPropertyList())
adds a picture in given position
Definition: MWAWContentListener.cxx:1069
std::vector< shared_ptr< MWAWContentListenerInternal::State > > m_psStack
stack of local state
Definition: MWAWContentListener.hxx:249
void closeTableCell()
close a cell
Definition: MWAWContentListener.cxx:1684
void setDocumentLanguage(std::string locale)
sets the documents language
Definition: MWAWContentListener.cxx:458
MWAWSection const & getSection() const
returns the actual section
Definition: MWAWContentListener.cxx:620
Definition: MWAWContentListener.hxx:71
MWAWContentListener(MWAWParserState &parserState, std::vector< MWAWPageSpan > const &pageList, WPXDocumentInterface *documentInterface)
constructor
Definition: MWAWContentListener.cxx:184

Generated for libmwaw by doxygen 1.8.5