~ubuntu-branches/ubuntu/edgy/libwpd/edgy-security

« back to all changes in this revision

Viewing changes to src/lib/WP5HLListener.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2005-07-03 20:55:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050703205549-t8o91w9rgd7yb3qf
Tags: 0.8.2-2
* C++ ABI transition
  - rename libwpd8 / libwpd-stream8 to ...8c2 and replace/conflict (with)
    the old library. Change debian/rules, *.files and .shlibs for the new
    package names

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libwpd
2
2
 * Copyright (C) 2003 William Lachance (william.lachance@sympatico.ca)
3
3
 * Copyright (C) 2003 Marc Maurer (j.m.maurer@student.utwente.nl)
4
 
 *  
 
4
 *
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
20
20
 */
21
21
 
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."
24
24
 */
25
25
 
26
26
#include "WP5HLListener.h"
27
27
#include "WP5FileStructure.h"
 
28
#include "WPXFileStructure.h"
 
29
#include "libwpd_internal.h"
28
30
 
29
31
_WP5ParsingState::_WP5ParsingState()
30
32
{
31
33
}
32
34
 
33
35
_WP5ParsingState::~_WP5ParsingState()
34
 
{       
 
36
{
35
37
}
36
38
 
37
 
WP5HLListener::WP5HLListener(vector<WPXPageSpan *> *pageList, WPXHLListenerImpl *listenerImpl) :
 
39
WP5HLListener::WP5HLListener(std::vector<WPXPageSpan *> *pageList, WPXHLListenerImpl *listenerImpl) :
38
40
        WPXHLListener(pageList, listenerImpl),
39
41
        WP5LLListener(),
40
42
        m_parseState(new WP5ParsingState)
42
44
        m_textBuffer.clear();
43
45
}
44
46
 
 
47
WP5HLListener::~WP5HLListener() 
 
48
{
 
49
        delete m_parseState;
 
50
}
 
51
 
 
52
 
45
53
/****************************************
46
54
 public 'HLListenerImpl' functions
47
55
*****************************************/
48
56
 
49
 
void WP5HLListener::insertCharacter(const guint16 character)
 
57
void WP5HLListener::insertCharacter(const uint16_t character)
50
58
{
51
 
        m_textBuffer.append(character);
 
59
        appendUCS4(m_textBuffer, (uint32_t)character);
52
60
}
53
61
 
54
 
void WP5HLListener::insertTab(const guint8 tabType, const float tabPosition)
 
62
void WP5HLListener::insertTab(const uint8_t tabType, const float tabPosition)
55
63
{
56
64
        _flushText();
57
65
        m_listenerImpl->insertTab();
60
68
void WP5HLListener::insertEOL()
61
69
{
62
70
        _flushText();
63
 
        m_ps->m_numDeferredParagraphBreaks++;   
 
71
        m_ps->m_numDeferredParagraphBreaks++;
64
72
}
65
73
 
66
74
void WP5HLListener::endDocument()
75
83
        // corner case: document contains no end of lines
76
84
        /*else*/ if (!m_ps->m_isParagraphOpened && !m_ps->m_isParagraphClosed)
77
85
        {
78
 
                _flushText();       
 
86
                _flushText();
79
87
        }
80
88
        // NORMAL(ish) case document ends either inside a paragraph or outside of one,
81
89
        // but not inside an object
83
91
        {
84
92
                _flushText();
85
93
        }
86
 
        
 
94
 
87
95
        // the only other possibility is a logical contradiction: a paragraph
88
96
        // may not be opened and closed at the same time
89
97
 
98
106
 public 'parser' functions
99
107
*****************************************/
100
108
 
101
 
void WP5HLListener::attributeChange(const bool isOn, const guint8 attribute)
 
109
void WP5HLListener::attributeChange(const bool isOn, const uint8_t attribute)
102
110
{
103
 
        
 
111
 
104
112
        // flush everything which came before this change
105
113
        _flushText();
106
 
        
107
 
        guint32 textAttributeBit = 0;
108
 
        
 
114
 
 
115
        uint32_t textAttributeBit = 0;
 
116
 
109
117
        // FIXME: handle all the possible attribute bits
110
118
        switch (attribute)
111
119
        {
 
120
                case WP5_ATTRIBUTE_EXTRA_LARGE:
 
121
                        textAttributeBit = WPX_EXTRA_LARGE_BIT;
 
122
                        break;
 
123
                case WP5_ATTRIBUTE_VERY_LARGE:
 
124
                        textAttributeBit = WPX_VERY_LARGE_BIT;
 
125
                        break;
 
126
                case WP5_ATTRIBUTE_LARGE:
 
127
                        textAttributeBit = WPX_LARGE_BIT;
 
128
                        break;
 
129
                case WP5_ATTRIBUTE_SMALL_PRINT:
 
130
                        textAttributeBit = WPX_SMALL_PRINT_BIT;
 
131
                        break;
 
132
                case WP5_ATTRIBUTE_FINE_PRINT:
 
133
                        textAttributeBit = WPX_FINE_PRINT_BIT;
 
134
                        break;          
 
135
                case WP5_ATTRIBUTE_SUPERSCRIPT:
 
136
                        textAttributeBit = WPX_SUPERSCRIPT_BIT;
 
137
                        break;
112
138
                case WP5_ATTRIBUTE_SUBSCRIPT:
113
139
                        textAttributeBit = WPX_SUBSCRIPT_BIT;
114
140
                        break;
115
 
                case WP5_ATTRIBUTE_SUPERSCRIPT:
116
 
                        textAttributeBit = WPX_SUPERSCRIPT_BIT;
117
 
                        break;
118
141
                case WP5_ATTRIBUTE_OUTLINE:
119
142
                        textAttributeBit = WPX_OUTLINE_BIT;
120
143
                        break;
129
152
                        break;
130
153
                case WP5_ATTRIBUTE_DOUBLE_UNDERLINE:
131
154
                        textAttributeBit = WPX_DOUBLE_UNDERLINE_BIT;
132
 
                        break;          
 
155
                        break;
133
156
                case WP5_ATTRIBUTE_BOLD:
134
157
                        textAttributeBit = WPX_BOLD_BIT;
135
158
                        break;
139
162
                case WP5_ATTRIBUTE_UNDERLINE:
140
163
                        textAttributeBit = WPX_UNDERLINE_BIT;
141
164
                        break;
 
165
                case WP5_ATTRIBUTE_SMALL_CAPS:
 
166
                        textAttributeBit = WPX_SMALL_CAPS_BIT;
 
167
                        break;
142
168
        }
143
 
        
144
 
        if (isOn) 
 
169
 
 
170
        if (isOn)
145
171
                m_ps->m_textAttributeBits |= textAttributeBit;
146
172
        else
147
173
                m_ps->m_textAttributeBits ^= textAttributeBit;
149
175
        m_ps->m_textAttributesChanged = true;
150
176
}
151
177
 
 
178
void WP5HLListener::marginChange(uint8_t side, uint16_t margin)
 
179
{
 
180
        //if (!isUndoOn())
 
181
        //{
 
182
                float marginInch = (float)((double)margin/ (double)WPX_NUM_WPUS_PER_INCH);
 
183
                bool marginChanged = false;
 
184
 
 
185
                switch(side)
 
186
                {
 
187
                case WPX_LEFT:
 
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;
 
192
                        break;
 
193
                case WPX_RIGHT:
 
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;
 
198
                        break;
 
199
                }
 
200
        //}
 
201
}
 
202
 
 
203
 
152
204
/****************************************
153
205
 private functions
154
206
*****************************************/
157
209
{
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*/))
161
213
        {
162
214
                _openSection();
163
215
                //if (fakeText)
164
216
                        _openParagraph();
165
 
        }       
166
 
        
 
217
        }
 
218
 
167
219
        if (m_ps->m_numDeferredParagraphBreaks > 0)
168
220
        {
169
221
                if (!m_ps->m_isParagraphOpened //&&
171
223
                )
172
224
                        m_ps->m_numDeferredParagraphBreaks++;
173
225
 
174
 
                while (m_ps->m_numDeferredParagraphBreaks > 1) 
175
 
                        _openParagraph();                       
176
 
                _closeParagraph(); 
 
226
                while (m_ps->m_numDeferredParagraphBreaks > 1)
 
227
                        _openParagraph();
 
228
                _closeParagraph();
177
229
                m_ps->m_numDeferredParagraphBreaks = 0; // compensate for this by requiring a paragraph to be opened
178
230
        }
179
 
        else if (m_ps->m_textAttributesChanged && m_textBuffer.getLen())
 
231
        else if (m_ps->m_textAttributesChanged && m_textBuffer.len())
180
232
        {
181
233
                _openSpan();
182
234
                m_ps->m_textAttributesChanged = false;
183
235
        }
184
 
        
185
 
        if (m_textBuffer.getLen())
 
236
 
 
237
        if (m_textBuffer.len())
186
238
        {
187
239
                if (!m_ps->m_isParagraphOpened)
188
240
                {
189
241
                        _openParagraph();
190
242
                        _openSpan();
191
243
                }
192
 
                
 
244
 
193
245
                m_listenerImpl->insertText(m_textBuffer);
194
246
                m_textBuffer.clear();
195
247
        }
196
248
}
197
 
 
198
 
void WP5HLListener::_openParagraph()
199
 
{
200
 
        _closeParagraph();
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;
205
 
        */
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, 
209
 
                                      1.0f, 
210
 
                                      m_ps->m_isParagraphColumnBreak, m_ps->m_isParagraphPageBreak);
211
 
        if (m_ps->m_numDeferredParagraphBreaks > 0) 
212
 
                m_ps->m_numDeferredParagraphBreaks--;
213
 
 
214
 
        m_ps->m_isParagraphColumnBreak = false; 
215
 
        m_ps->m_isParagraphPageBreak = false;
216
 
        m_ps->m_isParagraphOpened = true;
217
 
}