2
2
* Copyright (C) 2003 William Lachance (william.lachance@sympatico.ca)
3
3
* Copyright (C) 2003 Marc Maurer (j.m.maurer@student.utwente.nl)
5
5
* This library is free software; you can redistribute it and/or
6
6
* modify it under the terms of the GNU Library General Public
7
7
* License as published by the Free Software Foundation; either
19
19
* For further information visit http://libwpd.sourceforge.net
22
/* "This product is not manufactured, approved, or supported by
22
/* "This product is not manufactured, approved, or supported by
23
23
* Corel Corporation or Corel Corporation Limited."
26
26
#include "WP5HLListener.h"
27
27
#include "WP5FileStructure.h"
28
#include "WPXFileStructure.h"
29
#include "libwpd_internal.h"
29
31
_WP5ParsingState::_WP5ParsingState()
33
35
_WP5ParsingState::~_WP5ParsingState()
37
WP5HLListener::WP5HLListener(vector<WPXPageSpan *> *pageList, WPXHLListenerImpl *listenerImpl) :
39
WP5HLListener::WP5HLListener(std::vector<WPXPageSpan *> *pageList, WPXHLListenerImpl *listenerImpl) :
38
40
WPXHLListener(pageList, listenerImpl),
40
42
m_parseState(new WP5ParsingState)
42
44
m_textBuffer.clear();
47
WP5HLListener::~WP5HLListener()
45
53
/****************************************
46
54
public 'HLListenerImpl' functions
47
55
*****************************************/
49
void WP5HLListener::insertCharacter(const guint16 character)
57
void WP5HLListener::insertCharacter(const uint16_t character)
51
m_textBuffer.append(character);
59
appendUCS4(m_textBuffer, (uint32_t)character);
54
void WP5HLListener::insertTab(const guint8 tabType, const float tabPosition)
62
void WP5HLListener::insertTab(const uint8_t tabType, const float tabPosition)
57
65
m_listenerImpl->insertTab();
75
83
// corner case: document contains no end of lines
76
84
/*else*/ if (!m_ps->m_isParagraphOpened && !m_ps->m_isParagraphClosed)
80
88
// NORMAL(ish) case document ends either inside a paragraph or outside of one,
81
89
// but not inside an object
98
106
public 'parser' functions
99
107
*****************************************/
101
void WP5HLListener::attributeChange(const bool isOn, const guint8 attribute)
109
void WP5HLListener::attributeChange(const bool isOn, const uint8_t attribute)
104
112
// flush everything which came before this change
107
guint32 textAttributeBit = 0;
115
uint32_t textAttributeBit = 0;
109
117
// FIXME: handle all the possible attribute bits
110
118
switch (attribute)
120
case WP5_ATTRIBUTE_EXTRA_LARGE:
121
textAttributeBit = WPX_EXTRA_LARGE_BIT;
123
case WP5_ATTRIBUTE_VERY_LARGE:
124
textAttributeBit = WPX_VERY_LARGE_BIT;
126
case WP5_ATTRIBUTE_LARGE:
127
textAttributeBit = WPX_LARGE_BIT;
129
case WP5_ATTRIBUTE_SMALL_PRINT:
130
textAttributeBit = WPX_SMALL_PRINT_BIT;
132
case WP5_ATTRIBUTE_FINE_PRINT:
133
textAttributeBit = WPX_FINE_PRINT_BIT;
135
case WP5_ATTRIBUTE_SUPERSCRIPT:
136
textAttributeBit = WPX_SUPERSCRIPT_BIT;
112
138
case WP5_ATTRIBUTE_SUBSCRIPT:
113
139
textAttributeBit = WPX_SUBSCRIPT_BIT;
115
case WP5_ATTRIBUTE_SUPERSCRIPT:
116
textAttributeBit = WPX_SUPERSCRIPT_BIT;
118
141
case WP5_ATTRIBUTE_OUTLINE:
119
142
textAttributeBit = WPX_OUTLINE_BIT;
139
162
case WP5_ATTRIBUTE_UNDERLINE:
140
163
textAttributeBit = WPX_UNDERLINE_BIT;
165
case WP5_ATTRIBUTE_SMALL_CAPS:
166
textAttributeBit = WPX_SMALL_CAPS_BIT;
145
171
m_ps->m_textAttributeBits |= textAttributeBit;
147
173
m_ps->m_textAttributeBits ^= textAttributeBit;
149
175
m_ps->m_textAttributesChanged = true;
178
void WP5HLListener::marginChange(uint8_t side, uint16_t margin)
182
float marginInch = (float)((double)margin/ (double)WPX_NUM_WPUS_PER_INCH);
183
bool marginChanged = false;
188
m_ps->m_leftMarginByPageMarginChange = marginInch - m_ps->m_pageMarginLeft;
189
m_ps->m_paragraphMarginLeft = m_ps->m_leftMarginByPageMarginChange
190
+ m_ps->m_leftMarginByParagraphMarginChange
191
+ m_ps->m_leftMarginByTabs;
194
m_ps->m_rightMarginByPageMarginChange = marginInch - m_ps->m_pageMarginRight;
195
m_ps->m_paragraphMarginRight = m_ps->m_rightMarginByPageMarginChange
196
+ m_ps->m_rightMarginByParagraphMarginChange
197
+ m_ps->m_rightMarginByTabs;
152
204
/****************************************
153
205
private functions
154
206
*****************************************/
158
210
// create a new section, and a new paragraph, if our section attributes have changed and we have inserted
159
211
// something into the document (or we have forced a break, which assumes the same condition)
160
if (m_ps->m_sectionAttributesChanged && (m_textBuffer.getLen() > 0 || m_ps->m_numDeferredParagraphBreaks > 0 /*|| fakeText*/))
212
if (m_ps->m_sectionAttributesChanged && (m_textBuffer.len() > 0 || m_ps->m_numDeferredParagraphBreaks > 0/* || fakeText*/))
164
216
_openParagraph();
167
219
if (m_ps->m_numDeferredParagraphBreaks > 0)
169
221
if (!m_ps->m_isParagraphOpened //&&
172
224
m_ps->m_numDeferredParagraphBreaks++;
174
while (m_ps->m_numDeferredParagraphBreaks > 1)
226
while (m_ps->m_numDeferredParagraphBreaks > 1)
177
229
m_ps->m_numDeferredParagraphBreaks = 0; // compensate for this by requiring a paragraph to be opened
179
else if (m_ps->m_textAttributesChanged && m_textBuffer.getLen())
231
else if (m_ps->m_textAttributesChanged && m_textBuffer.len())
182
234
m_ps->m_textAttributesChanged = false;
185
if (m_textBuffer.getLen())
237
if (m_textBuffer.len())
187
239
if (!m_ps->m_isParagraphOpened)
189
241
_openParagraph();
193
245
m_listenerImpl->insertText(m_textBuffer);
194
246
m_textBuffer.clear();
198
void WP5HLListener::_openParagraph()
201
/*guint8 paragraphJustification;
202
(m_parseState->m_tempParagraphJustification != 0) ? paragraphJustification = m_parseState->m_tempParagraphJustification :
203
paragraphJustification = m_parseState->m_paragraphJustification;
204
m_parseState->m_tempParagraphJustification = 0;
206
m_listenerImpl->openParagraph(0, m_ps->m_textAttributeBits,
207
m_ps->m_paragraphMarginLeft, m_ps->m_paragraphMarginRight,
208
m_ps->m_fontName->str, m_ps->m_fontSize,
210
m_ps->m_isParagraphColumnBreak, m_ps->m_isParagraphPageBreak);
211
if (m_ps->m_numDeferredParagraphBreaks > 0)
212
m_ps->m_numDeferredParagraphBreaks--;
214
m_ps->m_isParagraphColumnBreak = false;
215
m_ps->m_isParagraphPageBreak = false;
216
m_ps->m_isParagraphOpened = true;