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  * Copyright (C) 2006, 2007 Andrew Ziem
4  * Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
5  * Copyright (C) 2003-2005 William Lachance (william.lachance@sympatico.ca)
6  * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21  *
22  * For further information visit http://libwps.sourceforge.net
23  */
24 
25 /* "This product is not manufactured, approved, or supported by
26  * Corel Corporation or Corel Corporation Limited."
27  */
28 
29 #ifndef WPSCONTENTLISTENER_H
30 #define WPSCONTENTLISTENER_H
31 
32 #include <vector>
33 
34 #include <libwpd/WPXPropertyList.h>
35 
36 #include "libwps_internal.h"
37 
38 class WPXBinaryData;
39 class WPXDocumentInterface;
40 class WPXString;
41 class WPXPropertyListVector;
42 
43 class WPSCell;
44 class WPSList;
45 class WPSPageSpan;
46 class WPSPosition;
47 class WPSSubDocument;
48 struct WPSTabStop;
49 
50 typedef shared_ptr<WPSSubDocument> WPSSubDocumentPtr;
51 
53 {
54  WPSDocumentParsingState(std::vector<WPSPageSpan> const &pageList);
56 
57  std::vector<WPSPageSpan> m_pageList;
58  WPXPropertyList m_metaData;
59 
61  int m_newListId; // a new free id
62 
64  std::vector<WPSSubDocumentPtr> m_subDocuments;
66 private:
69 };
70 
72 {
75 
76  WPXString m_textBuffer;
78 
80  double m_fontSize;
81  WPXString m_fontName;
82  uint32_t m_fontColor;
84 
94 
95  shared_ptr<WPSList> m_list;
97 
103 
107 
109 
110  std::vector<unsigned int> m_numRowsToSkip;
115 
116  unsigned m_currentPage;
119 
122  std::vector < WPSColumnDefinition > m_textColumns;
124 
128 
133 
134  double m_sectionMarginLeft; // In multicolumn sections, the above two will be rather interpreted
135  double m_sectionMarginRight; // as section margin change
138  double m_paragraphMarginLeft; // resulting paragraph margin that is one of the paragraph
139  double m_paragraphMarginRight; // properties
144  double m_leftMarginByPageMarginChange; // part of the margin due to the PAGE margin change
145  double m_rightMarginByPageMarginChange; // inside a page that already has content.
146  double m_leftMarginByParagraphMarginChange; // part of the margin due to the PARAGRAPH
147  double m_rightMarginByParagraphMarginChange; // margin change (in WP6)
148  double m_leftMarginByTabs; // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
149  double m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
150 
151  double m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
152  double m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
153  double m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
154 
155  double m_listReferencePosition; // position from the left page margin of the list number/bullet
156  double m_listBeginPosition; // position from the left page margin of the beginning of the list
157  std::vector<bool> m_listOrderedLevels;
158 
160  std::vector<WPSTabStop> m_tabStops;
162 
164 
165  bool m_isNote;
167 
168 private:
171 };
172 
174 {
175 public:
176  WPSContentListener(std::vector<WPSPageSpan> const &pageList, WPXDocumentInterface *documentInterface);
177  virtual ~WPSContentListener();
178 
179  void setDocumentLanguage(int lcid);
180 
181  void startDocument();
182  void endDocument();
183  void handleSubDocument(WPSSubDocumentPtr &subDocument, libwps::SubDocumentType subDocumentType);
184  bool isHeaderFooterOpened() const;
185 
186  // ------ text data -----------
187 
189  void insertCharacter(uint8_t character);
193  void insertUnicode(uint32_t character);
195  void insertUnicodeString(WPXString const &str);
197  static void appendUnicode(uint32_t val, WPXString &buffer);
198 
199  void insertTab();
200  void insertEOL(bool softBreak=false);
201  void insertBreak(const uint8_t breakType);
202 
203  // ------ text format -----------
204  void setTextFont(const WPXString &fontName);
205  void setFontSize(const uint16_t fontSize);
206  void setFontAttributes(const uint32_t fontAttributes);
207  void setTextLanguage(int lcid);
208  void setTextColor(const uint32_t rgb);
209  void setFont(const WPSFont &font);
210 
211  // ------ paragraph format -----------
213  bool isParagraphOpened() const;
214  void setParagraphLineSpacing(const double lineSpacing, WPXUnit unit=WPX_PERCENT);
217  void setParagraphJustification(libwps::Justification justification, bool force=false);
219  void setParagraphTextIndent(double margin);
224  void setParagraphMargin(double margin, int pos);
228  void setTabs(const std::vector<WPSTabStop> &tabStops);
235  void setParagraphBorders(int which, libwps::BorderStyle style=libwps::BorderSingle, int width=1, uint32_t color=0);
236 
237  // ------ list format -----------
239  void setCurrentList(shared_ptr<WPSList> list);
241  shared_ptr<WPSList> getCurrentList() const;
244  void setCurrentListLevel(int level);
245 
246  // ------- fields ----------------
250  void insertField(FieldType type);
252  void insertDateTimeField(char const *format);
253 
254  // ------- subdocument -----------------
258  void insertNote(const NoteType noteType, WPSSubDocumentPtr &subDocument);
260  void insertLabelNote(const NoteType noteType, WPXString const &label, WPSSubDocumentPtr &subDocument);
262  void insertComment(WPSSubDocumentPtr &subDocument);
263 
265  void insertPicture(WPSPosition const &pos, const WPXBinaryData &binaryData,
266  std::string type="image/pict",
267  WPXPropertyList frameExtras=WPXPropertyList());
269  void insertTextBox(WPSPosition const &pos, WPSSubDocumentPtr subDocument,
270  WPXPropertyList frameExtras=WPXPropertyList());
271 
272 
273  // ------- table -----------------
275  void openTable(std::vector<float> const &colWidth, WPXUnit unit);
277  void closeTable();
279  void openTableRow(float h, WPXUnit unit, bool headerRow=false);
281  void closeTableRow();
285  void openTableCell(WPSCell const &cell, WPXPropertyList const &extras);
287  void closeTableCell();
288 
289  // ------- section ---------------
291  bool isSectionOpened() const;
293  bool openSection(std::vector<int> colsWidth=std::vector<int>(), WPXUnit unit=WPX_INCH);
295  bool closeSection();
296 
297 protected:
298  void _openSection();
299  void _closeSection();
300 
301  void _openPageSpan();
302  void _closePageSpan();
303  void _updatePageSpanDependent(bool set);
305 
306  void _startSubDocument();
307  void _endSubDocument();
308 
309  void _handleFrameParameters( WPXPropertyList &propList, WPSPosition const &pos);
310  bool _openFrame(WPSPosition const &pos, WPXPropertyList extras=WPXPropertyList());
311  void _closeFrame();
312 
313  void _openParagraph();
314  void _closeParagraph();
315  void _appendParagraphProperties(WPXPropertyList &propList, const bool isListElement=false);
316  void _getTabStops(WPXPropertyListVector &tabStops);
317  void _appendJustification(WPXPropertyList &propList, libwps::Justification justification);
318  void _resetParagraphState(const bool isListElement=false);
319 
320  void _openListElement();
321  void _closeListElement();
322  void _changeList();
323 
324  void _openSpan();
325  void _closeSpan();
326 
327  void _flushText();
328  void _flushDeferredTabs();
329 
330  void _insertBreakIfNecessary(WPXPropertyList &propList);
331 
332  static void _addLanguage(int lcid, WPXPropertyList &propList);
333 
337  shared_ptr<WPSContentParsingState> _pushParsingState();
339  void _popParsingState();
340 
341 protected:
342  shared_ptr<WPSDocumentParsingState> m_ds; // main parse state
343  shared_ptr<WPSContentParsingState> m_ps; // parse state
344  std::vector<shared_ptr<WPSContentParsingState> > m_psStack;
345  WPXDocumentInterface *m_documentInterface;
346 
347 private:
350 };
351 
352 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
353 
354 #endif
355 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */

Generated on Wed Aug 8 2012 16:07:56 for libwps by doxygen 1.8.1.2