- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
48 struct WPSDocumentParsingState
49 {
50 WPSDocumentParsingState(std::vector<WPSPageSpan> const &pageList);
51 ~WPSDocumentParsingState();
52
53 std::vector<WPSPageSpan> m_pageList;
54 WPXPropertyList m_metaData;
55
56 int m_footNoteNumber , m_endNoteNumber ;
57 int m_newListId; // a new free id
58
59 bool m_isDocumentStarted, m_isHeaderFooterStarted;
60 std::vector<WPSSubDocumentPtr> m_subDocuments;
62 private:
63 WPSDocumentParsingState(const WPSDocumentParsingState &);
64 WPSDocumentParsingState &operator=(const WPSDocumentParsingState &);
65 };
66
67 struct WPSContentParsingState
68 {
69 WPSContentParsingState();
70 ~WPSContentParsingState();
71
72 WPXString m_textBuffer;
73 int m_numDeferredTabs;
74
75 uint32_t m_textAttributeBits;
76 double m_fontSize;
77 WPXString m_fontName;
78 uint32_t m_fontColor;
79 int m_textLanguage;
80
81 bool m_isParagraphColumnBreak;
82 bool m_isParagraphPageBreak;
83 libwps::Justification m_paragraphJustification;
84 double m_paragraphLineSpacing;
85 WPXUnit m_paragraphLineSpacingUnit;
86 uint32_t m_paragraphBackgroundColor;
87 int m_paragraphBorders;
88 WPSBorder m_paragraphBordersStyle;
89
90 shared_ptr<WPSList> m_list;
91 uint8_t m_currentListLevel;
92
93 bool m_isPageSpanOpened;
94 bool m_isSectionOpened;
95 bool m_isFrameOpened;
96 bool m_isPageSpanBreakDeferred;
97 bool m_isHeaderFooterWithoutParagraph;
98
99 bool m_isSpanOpened;
100 bool m_isParagraphOpened;
101 bool m_isListElementOpened;
102
103 bool m_firstParagraphInPageSpan;
104
105 std::vector<unsigned int> m_numRowsToSkip;
106 bool m_isTableOpened;
107 bool m_isTableRowOpened;
108 bool m_isTableColumnOpened;
109 bool m_isTableCellOpened;
110
111 unsigned m_currentPage;
112 int m_numPagesRemainingInSpan;
113 int m_currentPageNumber;
114
115 bool m_sectionAttributesChanged;
116 int m_numColumns;
117 std::vector < WPSColumnDefinition > m_textColumns;
118 bool m_isTextColumnWithoutParagraph;
119
120 double m_pageFormLength;
121 double m_pageFormWidth;
122 bool m_pageFormOrientationIsPortrait;
123
124 double m_pageMarginLeft;
125 double m_pageMarginRight;
126 double m_pageMarginTop;
127 double m_pageMarginBottom;
128
129 double m_sectionMarginLeft; // In multicolumn sections, the above two will be rather interpreted
130 double m_sectionMarginRight; // as section margin change
131 double m_sectionMarginTop;
132 double m_sectionMarginBottom;
133 double m_paragraphMarginLeft; // resulting paragraph margin that is one of the paragraph
134 double m_paragraphMarginRight; // properties
135 double m_paragraphMarginTop;
136 WPXUnit m_paragraphMarginTopUnit;
137 double m_paragraphMarginBottom;
138 WPXUnit m_paragraphMarginBottomUnit;
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
154 uint16_t m_alignmentCharacter;
155 std::vector<WPSTabStop> m_tabStops;
156 bool m_isTabPositionRelative;
157
158 bool m_inSubDocument;
159
160 bool m_isNote;
161 libwps::SubDocumentType m_subDocumentType;
162
163 private:
164 WPSContentParsingState(const WPSContentParsingState &);
165 WPSContentParsingState &operator=(const WPSContentParsingState &);
166 };
167
168 class WPSContentListener
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 ----------------
243 enum FieldType { None, PageNumber, Date, Time, Title, Link, Database };
245 void insertField(FieldType type);
247 void insertDateTimeField(char const *format);
248
249 // ------- subdocument -----------------
251 enum NoteType { FOOTNOTE, ENDNOTE };
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);
303 void _recomputeParagraphPositions();
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:
347 WPSContentListener(const WPSContentListener &);
348 WPSContentListener &operator=(const WPSContentListener &);
349 };
350
351 typedef shared_ptr<WPSContentListener> WPSContentListenerPtr;
352
353 #endif
354 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */