WPXContentListener.h Source File documentation

WPXContentListener.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwpd
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 Fridrich Strba (fridrich.strba@bluewin.ch)
11 *
12 * For minor contributions see the git repository.
13 *
14 * Alternatively, the contents of this file may be used under the terms
15 * of the GNU Lesser General Public License Version 2.1 or later
16 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
17 * applicable instead of those above.
18 *
19 * For further information visit http://libwpd.sourceforge.net
20 */
21
22 /* "This product is not manufactured, approved, or supported by
23 * Corel Corporation or Corel Corporation Limited."
24 */
25
26 #ifndef WPXCONTENTLISTENER_H
27 #define WPXCONTENTLISTENER_H
28
29 #include "WPXTable.h"
30 #include "libwpd_internal.h"
31 #include "WPXSubDocument.h"
32 #include "WPXPageSpan.h"
33 #include "WPXListener.h"
34 #include <memory>
35 #include <vector>
36 #include <list>
37 #include <set>
38
39 struct WPXTableDefinition
40 {
41 WPXTableDefinition() : m_positionBits(0), m_leftOffset(0.0), m_columns(), m_columnsProperties() {}
42 unsigned char m_positionBits;
43 double m_leftOffset;
44 std::vector < WPXColumnDefinition > m_columns;
45 std::vector < WPXColumnProperties > m_columnsProperties;
46 };
47
48 struct WPXContentParsingState
49 {
50 WPXContentParsingState();
51 ~WPXContentParsingState();
52
53 unsigned m_textAttributeBits;
54 double m_fontSize;
55 std::unique_ptr<librevenge::RVNGString> m_fontName;
56 std::unique_ptr<RGBSColor> m_fontColor;
57 std::unique_ptr<RGBSColor> m_highlightColor;
58
59 bool m_isParagraphColumnBreak;
60 bool m_isParagraphPageBreak;
61 unsigned char m_paragraphJustification;
62 unsigned char m_tempParagraphJustification; // TODO: remove this one after the tabs are properly implemented
63 double m_paragraphLineSpacing;
64
65 bool m_isDocumentStarted;
66 bool m_isPageSpanOpened;
67 bool m_isSectionOpened;
68 bool m_isPageSpanBreakDeferred;
69 bool m_isHeaderFooterWithoutParagraph;
70
71 bool m_isSpanOpened;
72 bool m_isParagraphOpened;
73 bool m_isListElementOpened;
74
75 bool m_firstParagraphInPageSpan;
76
77 std::vector<unsigned int> m_numRowsToSkip;
78 WPXTableDefinition m_tableDefinition;
79 int m_currentTableCol;
80 int m_currentTableRow;
81 int m_currentTableCellNumberInRow;
82 bool m_isTableOpened;
83 bool m_isTableRowOpened;
84 bool m_isTableColumnOpened;
85 bool m_isTableCellOpened;
86 bool m_wasHeaderRow;
87 bool m_isCellWithoutParagraph;
88 bool m_isRowWithoutCell;
89 unsigned m_cellAttributeBits;
90 unsigned char m_paragraphJustificationBeforeTable;
91
92 unsigned m_currentPage;
93 unsigned m_numPagesRemainingInSpan;
94 unsigned m_currentPageNumber;
95
96 bool m_sectionAttributesChanged;
97 unsigned m_numColumns;
98 std::vector < WPXColumnDefinition > m_textColumns;
99 bool m_isTextColumnWithoutParagraph;
100
101 double m_pageFormLength;
102 double m_pageFormWidth;
103 WPXFormOrientation m_pageFormOrientation;
104
105 double m_pageMarginLeft;
106 double m_pageMarginRight;
107 double m_pageMarginTop;
108 double m_pageMarginBottom;
109 double m_paragraphMarginLeft; // resulting paragraph margin that is one of the paragraph
110 double m_paragraphMarginRight; // properties
111 double m_paragraphMarginTop;
112 double m_paragraphMarginBottom;
113 double m_leftMarginByPageMarginChange; // part of the margin due to the PAGE margin change
114 double m_rightMarginByPageMarginChange; // inside a page that already has content.
115 double m_sectionMarginLeft; // In multicolumn sections, the above two will be rather interpreted
116 double m_sectionMarginRight; // as section margin change
117 double m_leftMarginByParagraphMarginChange; // part of the margin due to the PARAGRAPH
118 double m_rightMarginByParagraphMarginChange; // margin change (in WP6)
119 double m_leftMarginByTabs; // part of the margin due to the LEFT or LEFT/RIGHT Indent; the
120 double m_rightMarginByTabs; // only part of the margin that is reset at the end of a paragraph
121
122 double m_listReferencePosition; // position from the left page margin of the list number/bullet
123 double m_listBeginPosition; // position from the left page margin of the beginning of the list
124
125 double m_paragraphTextIndent; // resulting first line indent that is one of the paragraph properties
126 double m_textIndentByParagraphIndentChange; // part of the indent due to the PARAGRAPH indent (WP6???)
127 double m_textIndentByTabs; // part of the indent due to the "Back Tab" or "Left Tab"
128
129 unsigned char m_currentListLevel;
130
131 unsigned m_alignmentCharacter;
132 std::vector<WPXTabStop> m_tabStops;
133 bool m_isTabPositionRelative;
134
135 std::set <const WPXSubDocument *> m_subDocuments;
136
137 bool m_inSubDocument;
138 bool m_isNote;
139 WPXSubDocumentType m_subDocumentType;
140
141 private:
142 WPXContentParsingState(const WPXContentParsingState &);
143 WPXContentParsingState &operator=(const WPXContentParsingState &);
144 };
145
146 class WPXContentListener : public WPXListener
147 {
148 protected:
149 WPXContentListener(std::list<WPXPageSpan> &pageList, librevenge::RVNGTextInterface *documentInterface);
150 ~WPXContentListener() override;
151
152 void startDocument();
153 void startSubDocument();
154 void endDocument();
155 void endSubDocument();
156 void handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, unsigned nextTableIndice);
157 void insertBreak(const unsigned char breakType);
158 void lineSpacingChange(const double lineSpacing);
159 void justificationChange(const unsigned char justification);
160
161 std::unique_ptr<WPXContentParsingState> m_ps; // parse state
162 librevenge::RVNGTextInterface *m_documentInterface;
163 librevenge::RVNGPropertyList m_metaData;
164
165 virtual void _handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, unsigned nextTableIndice) = 0;
166 virtual void _flushText() = 0;
167 virtual void _changeList() = 0;
168
169 void _openSection();
170 void _closeSection();
171
172 void _openPageSpan();
173 void _closePageSpan();
174
175 void _appendParagraphProperties(librevenge::RVNGPropertyList &propList, const bool isListElement=false);
176 void _getTabStops(librevenge::RVNGPropertyListVector &tabStops);
177 void _appendJustification(librevenge::RVNGPropertyList &propList, int justification);
178 void _resetParagraphState(const bool isListElement=false);
179 virtual void _openParagraph();
180 void _closeParagraph();
181
182 void _openListElement();
183 void _closeListElement();
184
185 void _openSpan();
186 void _closeSpan();
187
188 void _openTable();
189 void _closeTable();
190 void _openTableRow(const double height, const bool isMinimumHeight, const bool isHeaderRow);
191 void _closeTableRow();
192 void _openTableCell(const unsigned char colSpan, const unsigned char rowSpan, const unsigned char borderBits,
193 const RGBSColor *cellFgColor, const RGBSColor *cellBgColor,
194 const RGBSColor *cellBorderColor,
195 const WPXVerticalAlignment cellVerticalAlignment);
196 void _closeTableCell();
197
198 double _movePositionToFirstColumn(double position);
199
200 double _getNextTabStop() const;
201 double _getPreviousTabStop() const;
202
203 void _insertText(const librevenge::RVNGString &textBuffer);
204
205 void _insertBreakIfNecessary(librevenge::RVNGPropertyList &propList);
206
207 void _insertPageNumberParagraph(WPXPageNumberPosition position, WPXNumberingType type, librevenge::RVNGString fontName, double fontSize);
208
209 unsigned _mapNonUnicodeCharacter(unsigned character);
210
211 private:
212 WPXContentListener(const WPXContentListener &);
213 WPXContentListener &operator=(const WPXContentListener &);
214 librevenge::RVNGString _colorToString(const RGBSColor *color);
215 librevenge::RVNGString _mergeColorsToString(const RGBSColor *fgColor, const RGBSColor *bgColor);
216 unsigned _mapSymbolFontCharacter(unsigned character);
217 unsigned _mapDingbatsFontCharacter(unsigned character);
218 };
219
220 #endif /* WPXCONTENTLISTENER_H */
221 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPXNumberingType
WPXNumberingType
Definition: libwpd_internal.h:92
WPXContentParsingState::m_textAttributeBits
unsigned m_textAttributeBits
Definition: WPXContentListener.h:53
WPXContentParsingState::m_listReferencePosition
double m_listReferencePosition
Definition: WPXContentListener.h:122
WPXTableDefinition::m_leftOffset
double m_leftOffset
Definition: WPXContentListener.h:43
WPXContentParsingState::m_isSectionOpened
bool m_isSectionOpened
Definition: WPXContentListener.h:67
WPXContentParsingState::m_subDocuments
std::set< const WPXSubDocument * > m_subDocuments
Definition: WPXContentListener.h:135
WPXContentParsingState::m_numPagesRemainingInSpan
unsigned m_numPagesRemainingInSpan
Definition: WPXContentListener.h:93
WPXContentParsingState::m_isTableCellOpened
bool m_isTableCellOpened
Definition: WPXContentListener.h:85
WPXContentParsingState::m_pageMarginBottom
double m_pageMarginBottom
Definition: WPXContentListener.h:108
WPXTable.h
WPXContentParsingState::m_textColumns
std::vector< WPXColumnDefinition > m_textColumns
Definition: WPXContentListener.h:98
WPXPageSpan.h
WPXContentParsingState::m_pageFormWidth
double m_pageFormWidth
Definition: WPXContentListener.h:102
WPXContentListener::m_ps
std::unique_ptr< WPXContentParsingState > m_ps
Definition: WPXContentListener.h:161
WPXContentParsingState::m_isListElementOpened
bool m_isListElementOpened
Definition: WPXContentListener.h:73
WPXTableDefinition::m_columns
std::vector< WPXColumnDefinition > m_columns
Definition: WPXContentListener.h:44
WPXListener
Definition: WPXListener.h:34
WPXContentParsingState::m_tableDefinition
WPXTableDefinition m_tableDefinition
Definition: WPXContentListener.h:78
WPXSubDocument.h
WPXTableDefinition
Definition: WPXContentListener.h:39
WPXContentParsingState::m_isHeaderFooterWithoutParagraph
bool m_isHeaderFooterWithoutParagraph
Definition: WPXContentListener.h:69
WPXTableDefinition::m_columnsProperties
std::vector< WPXColumnProperties > m_columnsProperties
Definition: WPXContentListener.h:45
WPXContentParsingState::m_isPageSpanOpened
bool m_isPageSpanOpened
Definition: WPXContentListener.h:66
WPXContentParsingState::m_isSpanOpened
bool m_isSpanOpened
Definition: WPXContentListener.h:71
WPXContentParsingState::m_sectionMarginRight
double m_sectionMarginRight
Definition: WPXContentListener.h:116
WPXContentParsingState::m_tabStops
std::vector< WPXTabStop > m_tabStops
Definition: WPXContentListener.h:132
WPXContentParsingState::m_currentTableCellNumberInRow
int m_currentTableCellNumberInRow
Definition: WPXContentListener.h:81
libwpd_internal.h
WPXContentParsingState::m_tempParagraphJustification
unsigned char m_tempParagraphJustification
Definition: WPXContentListener.h:62
WPXContentParsingState::m_pageMarginLeft
double m_pageMarginLeft
Definition: WPXContentListener.h:105
WPXContentParsingState::m_paragraphLineSpacing
double m_paragraphLineSpacing
Definition: WPXContentListener.h:63
WPXContentListener::m_metaData
librevenge::RVNGPropertyList m_metaData
Definition: WPXContentListener.h:163
WPXContentParsingState::m_firstParagraphInPageSpan
bool m_firstParagraphInPageSpan
Definition: WPXContentListener.h:75
WPXSubDocumentType
WPXSubDocumentType
Definition: libwpd_internal.h:111
WPXContentParsingState::m_paragraphJustificationBeforeTable
unsigned char m_paragraphJustificationBeforeTable
Definition: WPXContentListener.h:90
WPXContentParsingState::m_isTableOpened
bool m_isTableOpened
Definition: WPXContentListener.h:82
WPXContentParsingState::m_pageMarginTop
double m_pageMarginTop
Definition: WPXContentListener.h:107
WPXContentParsingState::m_currentPageNumber
unsigned m_currentPageNumber
Definition: WPXContentListener.h:94
WPXTableDefinition::m_positionBits
unsigned char m_positionBits
Definition: WPXContentListener.h:42
WPXContentListener
Definition: WPXContentListener.h:146
WPXListener.h
WPXTableList
Definition: WPXTable.h:79
WPXContentParsingState::m_isTableRowOpened
bool m_isTableRowOpened
Definition: WPXContentListener.h:83
WPXContentParsingState::m_textIndentByParagraphIndentChange
double m_textIndentByParagraphIndentChange
Definition: WPXContentListener.h:126
WPXContentParsingState::m_paragraphMarginTop
double m_paragraphMarginTop
Definition: WPXContentListener.h:111
WPXContentParsingState::m_paragraphMarginBottom
double m_paragraphMarginBottom
Definition: WPXContentListener.h:112
WPXContentParsingState::m_leftMarginByPageMarginChange
double m_leftMarginByPageMarginChange
Definition: WPXContentListener.h:113
WPXContentParsingState
Definition: WPXContentListener.h:48
WPXTableDefinition::WPXTableDefinition
WPXTableDefinition()
Definition: WPXContentListener.h:41
WPXContentParsingState::m_paragraphMarginLeft
double m_paragraphMarginLeft
Definition: WPXContentListener.h:109
WPXContentParsingState::m_isParagraphColumnBreak
bool m_isParagraphColumnBreak
Definition: WPXContentListener.h:59
WPXContentParsingState::m_listBeginPosition
double m_listBeginPosition
Definition: WPXContentListener.h:123
WPXContentParsingState::m_pageFormOrientation
WPXFormOrientation m_pageFormOrientation
Definition: WPXContentListener.h:103
WPXContentParsingState::m_paragraphJustification
unsigned char m_paragraphJustification
Definition: WPXContentListener.h:61
WPXContentParsingState::m_fontSize
double m_fontSize
Definition: WPXContentListener.h:54
WPXContentParsingState::m_isCellWithoutParagraph
bool m_isCellWithoutParagraph
Definition: WPXContentListener.h:87
WPXFormOrientation
WPXFormOrientation
Definition: libwpd_internal.h:105
WPXContentParsingState::m_currentListLevel
unsigned char m_currentListLevel
Definition: WPXContentListener.h:129
WPXContentParsingState::m_isParagraphOpened
bool m_isParagraphOpened
Definition: WPXContentListener.h:72
WPXContentParsingState::m_isTabPositionRelative
bool m_isTabPositionRelative
Definition: WPXContentListener.h:133
WPXContentParsingState::m_isTableColumnOpened
bool m_isTableColumnOpened
Definition: WPXContentListener.h:84
WPXContentParsingState::m_textIndentByTabs
double m_textIndentByTabs
Definition: WPXContentListener.h:127
WPXContentParsingState::m_rightMarginByParagraphMarginChange
double m_rightMarginByParagraphMarginChange
Definition: WPXContentListener.h:118
WPXSubDocument
Definition: WPXSubDocument.h:34
WPXContentParsingState::m_currentTableRow
int m_currentTableRow
Definition: WPXContentListener.h:80
WPXContentParsingState::m_sectionAttributesChanged
bool m_sectionAttributesChanged
Definition: WPXContentListener.h:96
WPXContentParsingState::m_paragraphMarginRight
double m_paragraphMarginRight
Definition: WPXContentListener.h:110
WPXVerticalAlignment
WPXVerticalAlignment
Definition: libwpd_internal.h:107
WPXContentParsingState::m_isRowWithoutCell
bool m_isRowWithoutCell
Definition: WPXContentListener.h:88
WPXContentParsingState::m_sectionMarginLeft
double m_sectionMarginLeft
Definition: WPXContentListener.h:115
WPXContentParsingState::m_rightMarginByPageMarginChange
double m_rightMarginByPageMarginChange
Definition: WPXContentListener.h:114
WPXContentParsingState::m_currentTableCol
int m_currentTableCol
Definition: WPXContentListener.h:79
WPXContentParsingState::m_inSubDocument
bool m_inSubDocument
Definition: WPXContentListener.h:137
WPXContentParsingState::m_numRowsToSkip
std::vector< unsigned int > m_numRowsToSkip
Definition: WPXContentListener.h:77
WPXContentParsingState::m_numColumns
unsigned m_numColumns
Definition: WPXContentListener.h:97
WPXContentParsingState::m_currentPage
unsigned m_currentPage
Definition: WPXContentListener.h:92
WPXContentParsingState::m_highlightColor
std::unique_ptr< RGBSColor > m_highlightColor
Definition: WPXContentListener.h:57
WPXContentParsingState::m_pageFormLength
double m_pageFormLength
Definition: WPXContentListener.h:101
WPXContentParsingState::m_wasHeaderRow
bool m_wasHeaderRow
Definition: WPXContentListener.h:86
RGBSColor
Definition: libwpd_internal.h:166
WPXContentParsingState::m_rightMarginByTabs
double m_rightMarginByTabs
Definition: WPXContentListener.h:120
WPXContentParsingState::m_isNote
bool m_isNote
Definition: WPXContentListener.h:138
WPXContentParsingState::m_paragraphTextIndent
double m_paragraphTextIndent
Definition: WPXContentListener.h:125
WPXContentParsingState::m_fontColor
std::unique_ptr< RGBSColor > m_fontColor
Definition: WPXContentListener.h:56
WPXContentParsingState::m_leftMarginByTabs
double m_leftMarginByTabs
Definition: WPXContentListener.h:119
WPXPageNumberPosition
WPXPageNumberPosition
Definition: libwpd_internal.h:97
WPXContentParsingState::m_alignmentCharacter
unsigned m_alignmentCharacter
Definition: WPXContentListener.h:131
WPXContentParsingState::m_isParagraphPageBreak
bool m_isParagraphPageBreak
Definition: WPXContentListener.h:60
WPXContentParsingState::m_pageMarginRight
double m_pageMarginRight
Definition: WPXContentListener.h:106
WPXContentParsingState::m_fontName
std::unique_ptr< librevenge::RVNGString > m_fontName
Definition: WPXContentListener.h:55
WPXContentParsingState::m_cellAttributeBits
unsigned m_cellAttributeBits
Definition: WPXContentListener.h:89
WPXContentParsingState::m_isPageSpanBreakDeferred
bool m_isPageSpanBreakDeferred
Definition: WPXContentListener.h:68
WPXContentListener::m_documentInterface
librevenge::RVNGTextInterface * m_documentInterface
Definition: WPXContentListener.h:162
WPXContentParsingState::m_leftMarginByParagraphMarginChange
double m_leftMarginByParagraphMarginChange
Definition: WPXContentListener.h:117
WPXContentParsingState::m_subDocumentType
WPXSubDocumentType m_subDocumentType
Definition: WPXContentListener.h:139
WPXContentParsingState::m_isDocumentStarted
bool m_isDocumentStarted
Definition: WPXContentListener.h:65
WPXContentParsingState::m_isTextColumnWithoutParagraph
bool m_isTextColumnWithoutParagraph
Definition: WPXContentListener.h:99