WP6ContentListener.h Source File documentation

WP6ContentListener.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) 2002 William Lachance (wrlach@gmail.com)
11 * Copyright (C) 2002 Marc Maurer (uwog@uwog.net)
12 * Copyright (C) 2005-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
13 *
14 * For minor contributions see the git repository.
15 *
16 * Alternatively, the contents of this file may be used under the terms
17 * of the GNU Lesser General Public License Version 2.1 or later
18 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
19 * applicable instead of those above.
20 *
21 * For further information visit http://libwpd.sourceforge.net
22 */
23
24 /* "This product is not manufactured, approved, or supported by
25 * Corel Corporation or Corel Corporation Limited."
26 */
27
28 #ifndef WP6CONTENTLISTENER_H
29 #define WP6CONTENTLISTENER_H
30
31 #include <librevenge/librevenge.h>
32 #include "WP6Listener.h"
33 #include "WPXContentListener.h"
34 #include "WP6FileStructure.h"
35
36 #include <stack>
37 #include <map>
38 #include <memory>
39 #include <vector>
40
41 class WPXTable;
42
43 enum WP6StyleState { NORMAL, DOCUMENT_NOTE, DOCUMENT_NOTE_GLOBAL,
44 BEGIN_BEFORE_NUMBERING,
45 BEGIN_NUMBERING_BEFORE_DISPLAY_REFERENCING,
46 DISPLAY_REFERENCING,
47 BEGIN_NUMBERING_AFTER_DISPLAY_REFERENCING,
48 BEGIN_AFTER_NUMBERING, STYLE_BODY, STYLE_END
49 };
50
51 enum WP6ListType { ORDERED, UNORDERED };
52
53 const int STATE_MEMORY = 3;
54 class WP6StyleStateSequence
55 {
56 public:
57 WP6StyleStateSequence() : m_stateSequence()
58 {
59 clear();
60 }
61 void setCurrentState(WP6StyleState state)
62 {
63 for (unsigned i=(STATE_MEMORY-1); i>0; i--) m_stateSequence[i] = m_stateSequence[i-1];
64 m_stateSequence[0]=state;
65 }
66 WP6StyleState getCurrentState() const
67 {
68 return m_stateSequence[0];
69 }
70 WP6StyleState getPreviousState() const
71 {
72 return m_stateSequence[1];
73 }
74 void clear()
75 {
76 m_stateSequence.clear();
77 for (int i=0; i<STATE_MEMORY; i++) m_stateSequence.push_back(NORMAL);
78 }
79
80 private:
81 std::vector<WP6StyleState> m_stateSequence;
82 };
83
84 struct WP6ContentParsingState
85 {
86 WP6ContentParsingState(WPXTableList tableList, unsigned nextTableIndice = 0);
87 ~WP6ContentParsingState();
88 librevenge::RVNGString m_bodyText;
89 librevenge::RVNGString m_textBeforeNumber;
90 librevenge::RVNGString m_textBeforeDisplayReference;
91 librevenge::RVNGString m_numberText;
92 librevenge::RVNGString m_textAfterDisplayReference;
93 librevenge::RVNGString m_textAfterNumber;
94
95 double m_paragraphMarginBottomRelative;
96 double m_paragraphMarginBottomAbsolute;
97
98 unsigned m_numRemovedParagraphBreaks;
99
100 unsigned m_numListExtraTabs;
101 bool m_isListReference;
102
103 WPXTableList m_tableList;
104 WPXTable *m_currentTable;
105 unsigned m_nextTableIndice;
106
107 std::stack<unsigned> m_listLevelStack;
108 std::stack<WP6ListType> m_listTypeStack;
109 unsigned short m_currentOutlineHash; // probably should replace Hash with Key in these sorts of cases
110 unsigned char m_oldListLevel;
111 WP6StyleStateSequence m_styleStateSequence;
112 bool m_putativeListElementHasParagraphNumber;
113 bool m_putativeListElementHasDisplayReferenceNumber;
114
115 unsigned m_noteTextPID;
116 unsigned m_numNestedNotes;
117
118 bool m_isFrameOpened;
119
120 bool m_isLinkOpened;
121
122 unsigned m_leaderCharacter;
123 unsigned char m_leaderNumSpaces;
124 std::vector<WPXTabStop> m_tempTabStops;
125 std::vector<bool> m_tempUsePreWP9LeaderMethod;
126
127 WPXNumberingType m_currentPageNumberingType;
128
129 private:
130 WP6ContentParsingState(const WP6ContentParsingState &);
131 WP6ContentParsingState &operator=(const WP6ContentParsingState &);
132 };
133
134 struct WP6ListLevel
135 {
136 int m_level;
137 bool m_isListElementOpenAtLevel;
138 };
139
140 class WP6OutlineDefinition
141 {
142 public:
143 WP6OutlineDefinition();
144 WP6OutlineDefinition(const unsigned char *numberingMethods, const unsigned char tabBehaviourFlag);
145 void update(const unsigned char *numberingMethods, const unsigned char tabBehaviourFlag);
146
147 WPXNumberingType getListType(int level)
148 {
149 if (level >= 0 && unsigned(level) < WPD_NUM_ELEMENTS(m_listTypes))
150 return m_listTypes[level];
151 return WPXNumberingType();
152 }
153
154 protected:
155 void _updateNumberingMethods(const unsigned char *numberingMethods);
156
157 private:
158 WPXNumberingType m_listTypes[WP6_NUM_LIST_LEVELS];
159 };
160
161 class WP6ContentListener : public WP6Listener, protected WPXContentListener
162 {
163 public:
164 WP6ContentListener(std::list<WPXPageSpan> &pageList, WPXTableList tableList, librevenge::RVNGTextInterface *documentInterface);
165 ~WP6ContentListener() override;
166
167 void startDocument() override
168 {
169 WPXContentListener::startDocument();
170 }
171 void startSubDocument() override
172 {
173 WPXContentListener::startSubDocument();
174 }
175 void setDate(const unsigned short type, const unsigned short year,
176 const unsigned char month, const unsigned char day,
177 const unsigned char hour, const unsigned char minute,
178 const unsigned char second, const unsigned char dayOfWeek,
179 const unsigned char timeZone, const unsigned char unused) override;
180 void setExtendedInformation(const unsigned short type, const librevenge::RVNGString &data) override;
181 void setAlignmentCharacter(const unsigned character) override;
182 void setLeaderCharacter(const unsigned character, const unsigned char numSpaces) override;
183 void defineTabStops(const bool isRelative, const std::vector<WPXTabStop> &tabStops,
184 const std::vector<bool> &usePreWP9LeaderMethods) override;
185 void insertCharacter(unsigned character) override;
186 void insertTab(const unsigned char tabType, double tabPosition) override;
187 void handleLineBreak() override;
188 void insertEOL() override;
189 void insertBreak(const unsigned char breakType) override
190 {
191 WPXContentListener::insertBreak(breakType);
192 }
193 void lineSpacingChange(const double lineSpacing) override
194 {
195 WPXContentListener::lineSpacingChange(lineSpacing);
196 }
197 void justificationChange(const unsigned char justification) override
198 {
199 WPXContentListener::justificationChange(justification);
200 }
201 void characterColorChange(const unsigned char red, const unsigned char green, const unsigned char blue) override;
202 void characterShadingChange(const unsigned char shading) override;
203 void highlightChange(const bool isOn, const RGBSColor &color) override;
204 void fontChange(const unsigned short matchedFontPointSize, const unsigned short fontPID, const librevenge::RVNGString &fontName) override;
205 void attributeChange(const bool isOn, const unsigned char attribute) override;
206 void spacingAfterParagraphChange(const double spacingRelative, const double spacingAbsolute) override;
207 void pageNumberingChange(const WPXPageNumberPosition /* page numbering position */, const unsigned short /* matchedFontPointSize */, const unsigned short /* fontPID */) override {}
208 void pageMarginChange(const unsigned char /* side */, const unsigned short /* margin */) override {}
209 void pageFormChange(const unsigned short /* length */, const unsigned short /* width */, const WPXFormOrientation /* orientation */) override {}
210 void marginChange(const unsigned char side, const unsigned short margin) override;
211 void paragraphMarginChange(const unsigned char side, const signed short margin) override;
212 void indentFirstLineChange(const signed short offset) override;
213 void columnChange(const WPXTextColumnType columnType, const unsigned char numColumns, const std::vector<double> &columnWidth,
214 const std::vector<bool> &isFixedWidth) override;
215 void updateOutlineDefinition(const unsigned short outlineHash, const unsigned char *numberingMethods, const unsigned char tabBehaviourFlag) override;
216
217 void paragraphNumberOn(const unsigned short outlineHash, const unsigned char level, const unsigned char flag) override;
218 void paragraphNumberOff() override;
219 void displayNumberReferenceGroupOn(const unsigned char subGroup, const unsigned char level) override;
220 void displayNumberReferenceGroupOff(const unsigned char subGroup) override;
221 void styleGroupOn(const unsigned char subGroup) override;
222 void styleGroupOff(const unsigned char subGroup) override;
223 void globalOn(const unsigned char systemStyle) override;
224 void globalOff() override;
225 void noteOn(const unsigned short textPID) override;
226 void noteOff(const WPXNoteType noteType) override;
227 void headerFooterGroup(const unsigned char /* headerFooterType */, const unsigned char /* occurrenceBits */, const unsigned short /* textPID */) override {}
228 void suppressPageCharacteristics(const unsigned char /* suppressCode */) override {}
229 void setPageNumber(const unsigned short /* pageNumber */) override {}
230 void setPageNumberingType(const WPXNumberingType pageNumberingType) override;
231 void endDocument() override
232 {
233 WPXContentListener::endDocument();
234 }
235 void endSubDocument() override
236 {
237 WPXContentListener::endSubDocument();
238 }
239
240 void defineTable(const unsigned char position, const unsigned short leftOffset) override;
241 void addTableColumnDefinition(const unsigned width, const unsigned leftGutter, const unsigned rightGutter,
242 const unsigned attributes, const unsigned char alignment) override;
243 void startTable() override;
244 void insertRow(const unsigned short rowHeight, const bool isMinimumHeight, const bool isHeaderRow) override;
245 void insertCell(const unsigned char colSpan, const unsigned char rowSpan, const unsigned char borderBits,
246 const RGBSColor *cellFgColor, const RGBSColor *cellBgColor,
247 const RGBSColor *cellBorderColor, const WPXVerticalAlignment cellVerticalAlignment,
248 const bool useCellAttributes, const unsigned cellAttributes) override;
249 void endTable() override;
250 void boxOn(const unsigned char anchoringType, const unsigned char generalPositioningFlags, const unsigned char horizontalPositioningFlags,
251 const signed short horizontalOffset, const unsigned char leftColumn, const unsigned char rightColumn,
252 const unsigned char verticalPositioningFlags, const signed short verticalOffset, const unsigned char widthFlags, const unsigned short width,
253 const unsigned char heightFlags, const unsigned short height, const unsigned char boxContentType, const unsigned short nativeWidth,
254 const unsigned short nativeHeight,
255 const librevenge::RVNGString &linkTarget) override;
256 void boxOff() override;
257 void insertGraphicsData(const unsigned short packetId) override;
258 void insertTextBox(const WP6SubDocument *subDocument) override;
259 void commentAnnotation(const unsigned short textPID) override;
260
261 void undoChange(const unsigned char undoType, const unsigned short undoLevel) override;
262
263 protected:
264 void _handleSubDocument(const WPXSubDocument *subDocument, WPXSubDocumentType subDocumentType, WPXTableList tableList, unsigned nextTableIndice = 0) override;
265
266 //void _handleLineBreakElementBegin();
267 void _paragraphNumberOn(const unsigned short outlineHash, const unsigned char level);
268 void _flushText() override;
269 void _handleListChange(const unsigned short outlineHash);
270
271 void _changeList() override;
272
273 private:
274 WP6ContentListener(const WP6ContentListener &);
275 WP6ContentListener &operator=(const WP6ContentListener &);
276 std::unique_ptr<WP6ContentParsingState> m_parseState;
277
278 std::map<unsigned short,WP6OutlineDefinition> m_outlineDefineHash;
279 std::map<unsigned, librevenge::RVNGPropertyList> m_listDefinitions;
280 };
281
282 #endif /* WP6CONTENTLISTENER_H */
283 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
WPXNumberingType
WPXNumberingType
Definition: libwpd_internal.h:92
WP6ContentParsingState::m_isFrameOpened
bool m_isFrameOpened
Definition: WP6ContentListener.h:118
DOCUMENT_NOTE
Definition: WP6ContentListener.h:43
BEGIN_NUMBERING_AFTER_DISPLAY_REFERENCING
Definition: WP6ContentListener.h:47
WP6ContentListener::pageFormChange
void pageFormChange(const unsigned short, const unsigned short, const WPXFormOrientation) override
Definition: WP6ContentListener.h:209
WP6FileStructure.h
WP6ContentParsingState::m_numberText
librevenge::RVNGString m_numberText
Definition: WP6ContentListener.h:91
WP6Listener
Definition: WP6Listener.h:40
BEGIN_AFTER_NUMBERING
Definition: WP6ContentListener.h:48
BEGIN_NUMBERING_BEFORE_DISPLAY_REFERENCING
Definition: WP6ContentListener.h:45
WP6StyleStateSequence::WP6StyleStateSequence
WP6StyleStateSequence()
Definition: WP6ContentListener.h:57
WPXTable
Definition: WPXTable.h:49
WP6ContentListener::setPageNumber
void setPageNumber(const unsigned short) override
Definition: WP6ContentListener.h:229
WPXContentListener::justificationChange
void justificationChange(const unsigned char justification)
Definition: WPXContentListener.cpp:1304
DISPLAY_REFERENCING
Definition: WP6ContentListener.h:46
WPXContentListener::startSubDocument
void startSubDocument()
Definition: WPXContentListener.cpp:153
WP6ContentParsingState::m_textBeforeNumber
librevenge::RVNGString m_textBeforeNumber
Definition: WP6ContentListener.h:89
WP6ContentListener::m_outlineDefineHash
std::map< unsigned short, WP6OutlineDefinition > m_outlineDefineHash
Definition: WP6ContentListener.h:278
WPXContentListener::endDocument
void endDocument()
Definition: WPXContentListener.cpp:159
UNORDERED
Definition: WP6ContentListener.h:51
WP6ContentParsingState::m_currentPageNumberingType
WPXNumberingType m_currentPageNumberingType
Definition: WP6ContentListener.h:127
WPXTextColumnType
WPXTextColumnType
Definition: libwpd_internal.h:109
STATE_MEMORY
const int STATE_MEMORY
Definition: WP6ContentListener.h:53
ORDERED
Definition: WP6ContentListener.h:51
WP6ContentParsingState::m_putativeListElementHasDisplayReferenceNumber
bool m_putativeListElementHasDisplayReferenceNumber
Definition: WP6ContentListener.h:113
WP6ContentParsingState::m_styleStateSequence
WP6StyleStateSequence m_styleStateSequence
Definition: WP6ContentListener.h:111
WP6StyleState
WP6StyleState
Definition: WP6ContentListener.h:43
WP6ContentParsingState::m_paragraphMarginBottomAbsolute
double m_paragraphMarginBottomAbsolute
Definition: WP6ContentListener.h:96
WP6ContentParsingState::m_nextTableIndice
unsigned m_nextTableIndice
Definition: WP6ContentListener.h:105
WPXContentListener::insertBreak
void insertBreak(const unsigned char breakType)
Definition: WPXContentListener.cpp:1242
WP6ContentParsingState::m_tempUsePreWP9LeaderMethod
std::vector< bool > m_tempUsePreWP9LeaderMethod
Definition: WP6ContentListener.h:125
WP6ContentListener::pageNumberingChange
void pageNumberingChange(const WPXPageNumberPosition, const unsigned short, const unsigned short) override
Definition: WP6ContentListener.h:207
WP6ContentParsingState::m_numListExtraTabs
unsigned m_numListExtraTabs
Definition: WP6ContentListener.h:100
WP6ListType
WP6ListType
Definition: WP6ContentListener.h:51
DOCUMENT_NOTE_GLOBAL
Definition: WP6ContentListener.h:43
WP6ContentParsingState::m_textBeforeDisplayReference
librevenge::RVNGString m_textBeforeDisplayReference
Definition: WP6ContentListener.h:90
WPXSubDocumentType
WPXSubDocumentType
Definition: libwpd_internal.h:111
WP6ContentParsingState::m_putativeListElementHasParagraphNumber
bool m_putativeListElementHasParagraphNumber
Definition: WP6ContentListener.h:112
WPXContentListener
Definition: WPXContentListener.h:146
WP6ListLevel::m_isListElementOpenAtLevel
bool m_isListElementOpenAtLevel
Definition: WP6ContentListener.h:137
WP6ContentListener::headerFooterGroup
void headerFooterGroup(const unsigned char, const unsigned char, const unsigned short) override
Definition: WP6ContentListener.h:227
WP6ListLevel
Definition: WP6ContentListener.h:134
NORMAL
Definition: WP6ContentListener.h:43
WP6ContentParsingState::m_textAfterDisplayReference
librevenge::RVNGString m_textAfterDisplayReference
Definition: WP6ContentListener.h:92
WPXTableList
Definition: WPXTable.h:79
WPXContentListener.h
WP6StyleStateSequence
Definition: WP6ContentListener.h:54
WP6StyleStateSequence::getPreviousState
WP6StyleState getPreviousState() const
Definition: WP6ContentListener.h:70
WP6SubDocument
Definition: WP6SubDocument.h:33
WP6ContentListener::lineSpacingChange
void lineSpacingChange(const double lineSpacing) override
Definition: WP6ContentListener.h:193
WP6ListLevel::m_level
int m_level
Definition: WP6ContentListener.h:136
WP6StyleStateSequence::m_stateSequence
std::vector< WP6StyleState > m_stateSequence
Definition: WP6ContentListener.h:81
WP6ContentListener::justificationChange
void justificationChange(const unsigned char justification) override
Definition: WP6ContentListener.h:197
WP6OutlineDefinition::getListType
WPXNumberingType getListType(int level)
Definition: WP6ContentListener.h:147
WP6ContentParsingState::m_oldListLevel
unsigned char m_oldListLevel
Definition: WP6ContentListener.h:110
WPXFormOrientation
WPXFormOrientation
Definition: libwpd_internal.h:105
STYLE_END
Definition: WP6ContentListener.h:48
WP6OutlineDefinition
Definition: WP6ContentListener.h:140
WPXSubDocument
Definition: WPXSubDocument.h:34
WP6StyleStateSequence::setCurrentState
void setCurrentState(WP6StyleState state)
Definition: WP6ContentListener.h:61
WP6ContentParsingState::m_paragraphMarginBottomRelative
double m_paragraphMarginBottomRelative
Definition: WP6ContentListener.h:95
WP6ContentParsingState::m_numNestedNotes
unsigned m_numNestedNotes
Definition: WP6ContentListener.h:116
WPXVerticalAlignment
WPXVerticalAlignment
Definition: libwpd_internal.h:107
WP6ContentListener::m_parseState
std::unique_ptr< WP6ContentParsingState > m_parseState
Definition: WP6ContentListener.h:276
WP6ContentParsingState::m_currentOutlineHash
unsigned short m_currentOutlineHash
Definition: WP6ContentListener.h:109
WP6ContentParsingState::m_tableList
WPXTableList m_tableList
Definition: WP6ContentListener.h:103
WP6ContentListener::startDocument
void startDocument() override
Definition: WP6ContentListener.h:167
WP6_NUM_LIST_LEVELS
#define WP6_NUM_LIST_LEVELS
Definition: WP6FileStructure.h:36
WP6ContentParsingState::m_listLevelStack
std::stack< unsigned > m_listLevelStack
Definition: WP6ContentListener.h:107
WP6ContentParsingState::m_noteTextPID
unsigned m_noteTextPID
Definition: WP6ContentListener.h:115
WPXContentListener::endSubDocument
void endSubDocument()
Definition: WPXContentListener.cpp:180
WP6ContentParsingState::m_tempTabStops
std::vector< WPXTabStop > m_tempTabStops
Definition: WP6ContentListener.h:124
RGBSColor
Definition: libwpd_internal.h:166
WP6ContentListener::insertBreak
void insertBreak(const unsigned char breakType) override
Definition: WP6ContentListener.h:189
WP6ContentParsingState::m_textAfterNumber
librevenge::RVNGString m_textAfterNumber
Definition: WP6ContentListener.h:93
WP6ContentParsingState::m_leaderNumSpaces
unsigned char m_leaderNumSpaces
Definition: WP6ContentListener.h:123
WPXPageNumberPosition
WPXPageNumberPosition
Definition: libwpd_internal.h:97
WP6ContentParsingState::m_isLinkOpened
bool m_isLinkOpened
Definition: WP6ContentListener.h:120
WP6ContentParsingState::m_leaderCharacter
unsigned m_leaderCharacter
Definition: WP6ContentListener.h:122
WP6ContentListener::m_listDefinitions
std::map< unsigned, librevenge::RVNGPropertyList > m_listDefinitions
Definition: WP6ContentListener.h:279
WP6StyleStateSequence::getCurrentState
WP6StyleState getCurrentState() const
Definition: WP6ContentListener.h:66
STYLE_BODY
Definition: WP6ContentListener.h:48
BEGIN_BEFORE_NUMBERING
Definition: WP6ContentListener.h:44
WP6ContentParsingState::m_currentTable
WPXTable * m_currentTable
Definition: WP6ContentListener.h:104
WP6Listener.h
WPXContentListener::startDocument
void startDocument()
Definition: WPXContentListener.cpp:138
WP6ContentListener::startSubDocument
void startSubDocument() override
Definition: WP6ContentListener.h:171
WP6ContentListener
Definition: WP6ContentListener.h:161
WPXContentListener::lineSpacingChange
void lineSpacingChange(const double lineSpacing)
Definition: WPXContentListener.cpp:1296
WP6ContentParsingState::m_listTypeStack
std::stack< WP6ListType > m_listTypeStack
Definition: WP6ContentListener.h:108
WP6ContentParsingState::m_bodyText
librevenge::RVNGString m_bodyText
Definition: WP6ContentListener.h:88
WP6ContentListener::endSubDocument
void endSubDocument() override
Definition: WP6ContentListener.h:235
WP6ContentParsingState::m_numRemovedParagraphBreaks
unsigned m_numRemovedParagraphBreaks
Definition: WP6ContentListener.h:98
WP6ContentListener::suppressPageCharacteristics
void suppressPageCharacteristics(const unsigned char) override
Definition: WP6ContentListener.h:228
WP6StyleStateSequence::clear
void clear()
Definition: WP6ContentListener.h:74
WP6ContentListener::endDocument
void endDocument() override
Definition: WP6ContentListener.h:231
WP6ContentListener::pageMarginChange
void pageMarginChange(const unsigned char, const unsigned short) override
Definition: WP6ContentListener.h:208
WPD_NUM_ELEMENTS
#define WPD_NUM_ELEMENTS(array)
Definition: libwpd_internal.h:53
WPXNoteType
WPXNoteType
Definition: libwpd_internal.h:93
WP6ContentParsingState::m_isListReference
bool m_isListReference
Definition: WP6ContentListener.h:101
WP6ContentParsingState
Definition: WP6ContentListener.h:84