- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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