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 <libwpd/libwpd.h>
31 
32 #include "libwps_internal.h"
33 
34 class WPXBinaryData;
35 class WPXDocumentInterface;
36 class WPXString;
37 class WPXPropertyListVector;
38 
39 class WPSCell;
40 class WPSList;
41 class WPSPageSpan;
42 class WPSPosition;
43 class WPSSubDocument;
44 struct WPSTabStop;
45 
46 typedef shared_ptr<WPSSubDocument> WPSSubDocumentPtr;
47 
49 {
50  WPSDocumentParsingState(std::vector<WPSPageSpan> const &pageList);
52 
53  std::vector<WPSPageSpan> m_pageList;
54  WPXPropertyList m_metaData;
55 
57  int m_newListId; // a new free id
58 
60  std::vector<WPSSubDocumentPtr> m_subDocuments;
62 private:
65 };
66 
68 {
71 
72  WPXString m_textBuffer;
74 
76  double m_fontSize;
77  WPXString m_fontName;
78  uint32_t m_fontColor;
80 
89 
90  shared_ptr<WPSList> m_list;
92 
98 
102 
104 
105  std::vector<unsigned int> m_numRowsToSkip;
110 
111  unsigned m_currentPage;
114 
117  std::vector < WPSColumnDefinition > m_textColumns;
119 
123 
128 
129  double m_sectionMarginLeft; // In multicolumn sections, the above two will be rather interpreted
130  double m_sectionMarginRight; // as section margin change
133  double m_paragraphMarginLeft; // resulting paragraph margin that is one of the paragraph
134  double m_paragraphMarginRight; // properties
139  double m_leftMarginByPageMarginChange; // part of the margin due to the PAGE margin change
140  double m_rightMarginByPageMarginChange; // inside a page that already has content.
141  double m_leftMarginByParagraphMarginChange; // part of the margin due to the PARAGRAPH
142  double m_rightMarginByParagraphMarginChange; // margin change (in WP6)
143  double m_leftMarginByTabs; // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
144  double m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
145 
146  double m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
147  double m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
148  double m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
149 
150  double m_listReferencePosition; // position from the left page margin of the list number/bullet
151  double m_listBeginPosition; // position from the left page margin of the beginning of the list
152  std::vector<bool> m_listOrderedLevels;
153 
155  std::vector<WPSTabStop> m_tabStops;
157 
159 
160  bool m_isNote;
162 
163 private:
166 };
167 
169 {
170 public:
171  WPSContentListener(std::vector<WPSPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
172  virtual ~WPSContentListener();
173 
174  void setDocumentLanguage(int lcid);
175 
176  void startDocument();
177  void endDocument();
178  void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
179  bool isHeaderFooterOpened() const;
180 
181  // ------ text data -----------
182 
184  void insertCharacter(uint8_t character);
188  void insertUnicode(uint32_t character);
190  void insertUnicodeString(WPXString const &str);
192  static void appendUnicode(uint32_t val, WPXString &buffer);
193 
194  void insertTab();
195  void insertEOL(bool softBreak=false);
196  void insertBreak(const uint8_t breakType);
197 
198  // ------ text format -----------
199  void setTextFont(const WPXString &fontName);
200  void setFontSize(const uint16_t fontSize);
201  void setFontAttributes(const uint32_t fontAttributes);
202  void setTextLanguage(int lcid);
203  void setTextColor(const uint32_t rgb);
204  void setFont(const WPSFont &font);
205 
206  // ------ paragraph format -----------
208  bool isParagraphOpened() const;
209  void setParagraphLineSpacing(const double lineSpacing, WPXUnit unit=WPX_PERCENT);
212  void setParagraphJustification(libwps::Justification justification, bool force=false);
214  void setParagraphTextIndent(double margin);
219  void setParagraphMargin(double margin, int pos);
223  void setTabs(const std::vector<WPSTabStop> &tabStops);
225  void setParagraphBackgroundColor(uint32_t color=0xFFFFFF);
230  void setParagraphBorders(int which, WPSBorder style=WPSBorder());
231 
232  // ------ list format -----------
234  void setCurrentList(shared_ptr<WPSList> list);
236  shared_ptr<WPSList> getCurrentList() const;
239  void setCurrentListLevel(int level);
240 
241  // ------- fields ----------------
245  void insertField(FieldType type);
247  void insertDateTimeField(char const *format);
248 
249  // ------- subdocument -----------------
253  void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument);
255  void insertLabelNote(const NoteType noteType, WPXString const &label, WPSSubDocumentPtr &subDocument);
257  void insertComment(WPSSubDocumentPtr &subDocument);
258 
260  void insertPicture(WPSPosition const &pos, const WPXBinaryData &binaryData,
261  std::string type="image/pict",
262  WPXPropertyList frameExtras=WPXPropertyList());
264  void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
265  WPXPropertyList frameExtras=WPXPropertyList());
266 
267 
268  // ------- table -----------------
270  void openTable(std::vector<float> const &colWidth, WPXUnit unit);
272  void closeTable();
274  void openTableRow(float h, WPXUnit unit, bool headerRow=false);
276  void closeTableRow();
280  void openTableCell(WPSCell const &cell, WPXPropertyList const &extras);
282  void closeTableCell();
284  void addEmptyTableCell(Vec2i const &pos, Vec2i span=Vec2i(1,1));
285 
286  // ------- section ---------------
288  bool isSectionOpened() const;
290  int getSectionNumColumns() const;
292  bool openSection(std::vector<int> colsWidth=std::vector<int>(), WPXUnit unit=WPX_INCH);
294  bool closeSection();
295 
296 protected:
297  void _openSection();
298  void _closeSection();
299 
300  void _openPageSpan();
301  void _closePageSpan();
302  void _updatePageSpanDependent(bool set);
304 
305  void _startSubDocument();
306  void _endSubDocument();
307 
308  void _handleFrameParameters( WPXPropertyList &propList, WPSPosition const &pos);
309  bool _openFrame(WPSPosition const &pos, WPXPropertyList extras=WPXPropertyList());
310  void _closeFrame();
311 
312  void _openParagraph();
313  void _closeParagraph();
314  void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
315  void _getTabStops(WPXPropertyListVector &tabStops);
316  void _appendJustification(WPXPropertyList &propList, libwps::Justification justification);
317  void _resetParagraphState(const bool isListElement=false);
318 
319  void _openListElement();
320  void _closeListElement();
321  void _changeList();
322 
323  void _openSpan();
324  void _closeSpan();
325 
326  void _flushText();
327  void _flushDeferredTabs();
328 
329  void _insertBreakIfNecessary(WPXPropertyList &propList);
330 
331  static void _addLanguage(int lcid, WPXPropertyList &propList);
332 
336  shared_ptr<WPSContentParsingState> _pushParsingState();
338  void _popParsingState();
339 
340 protected:
341  shared_ptr<WPSDocumentParsingState> m_ds; // main parse state
342  shared_ptr<WPSContentParsingState> m_ps; // parse state
343  std::vector<shared_ptr<WPSContentParsingState> > m_psStack;
344  WPXDocumentInterface *m_documentInterface;
345 
346 private:
349 };
350 
351 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
352 
353 #endif
354 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */

Generated on Mon May 27 2013 07:15:18 for libwps by doxygen 1.8.3.1