~ubuntu-branches/ubuntu/breezy/libwpd/breezy

« back to all changes in this revision

Viewing changes to src/conv/raw/RawListener.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Masayuki Hatta (mhatta)
  • Date: 2004-08-10 00:37:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040810003747-5i7g92h2v88z70zo
Tags: 0.7.2-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* libwpd
2
2
 * Copyright (C) 2002 William Lachance (william.lachance@sympatico.ca)
3
 
 * Copyright (C) 2002,2004 Marc Maurer (j.m.maurer@student.utwente.nl)
4
 
 *  
 
3
 * Copyright (C) 2002-2004 Marc Maurer (j.m.maurer@student.utwente.nl)
 
4
 *
5
5
 * This library is free software; you can redistribute it and/or
6
6
 * modify it under the terms of the GNU Lesser 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 <stdio.h>
27
27
#include "RawListener.h"
28
28
 
29
 
RawListenerImpl::RawListenerImpl() : 
30
 
        m_indent(0)
31
 
{
 
29
#define _U(M, L) \
 
30
        if (!m_printCallgraphScore) \
 
31
                        __iuprintf M; \
 
32
        else \
 
33
                m_callStack.push(L);
 
34
 
 
35
#define _D(M, L) \
 
36
        if (!m_printCallgraphScore) \
 
37
                        __idprintf M; \
 
38
        else \
 
39
        { \
 
40
                ListenerCallback lc = m_callStack.top(); \
 
41
                if (lc != L) \
 
42
                        m_callbackMisses++; \
 
43
                m_callStack.pop(); \
 
44
        }       
 
45
        
 
46
RawListenerImpl::RawListenerImpl(bool printCallgraphScore) :
 
47
        m_indent(0),
 
48
        m_callbackMisses(0),
 
49
        m_printCallgraphScore(printCallgraphScore)
 
50
{
 
51
}
 
52
 
 
53
RawListenerImpl::~RawListenerImpl()
 
54
{
 
55
        if (m_printCallgraphScore)
 
56
                printf("%d\n", m_callStack.size() + m_callbackMisses);
32
57
}
33
58
 
34
59
void RawListenerImpl::__iprintf(const char *format, ...)
35
60
{
 
61
        if (m_printCallgraphScore) return;
 
62
        
36
63
        va_list args;
37
 
        va_start(args, format);         
 
64
        va_start(args, format);
38
65
        for (int i=0; i<m_indent; i++)
39
66
                printf("  ");
40
67
        vprintf(format, args);
69
96
                                         const UCSString &abstract, const UCSString &descriptiveName,
70
97
                                         const UCSString &descriptiveType)
71
98
{
 
99
        UTF8String authorUTF8(author);
 
100
        UTF8String subjectUTF8(subject);
 
101
        UTF8String publisherUTF8(publisher);
 
102
        UTF8String categoryUTF8(category);
 
103
        UTF8String keywordsUTF8(keywords);
 
104
        UTF8String languageUTF8(language);
 
105
        UTF8String abstractUTF8(abstract);
 
106
        UTF8String descriptiveNameUTF8(descriptiveName);
 
107
        UTF8String descriptiveTypeUTF8(descriptiveType);
 
108
        __iprintf("setDocumentMetaData(author: %s, subject: %s, publisher: %s, category: %s, keywords: %s, language: %s, abstract: %s, descriptiveName: %s, descriptiveType: %s)\n",
 
109
                authorUTF8.getUTF8(), subjectUTF8.getUTF8(),
 
110
                publisherUTF8.getUTF8(), categoryUTF8.getUTF8(),
 
111
                keywordsUTF8.getUTF8(), languageUTF8.getUTF8(),
 
112
                abstractUTF8.getUTF8(), descriptiveNameUTF8.getUTF8(),
 
113
                descriptiveTypeUTF8.getUTF8()
 
114
        );
72
115
}
73
116
 
74
117
void RawListenerImpl::startDocument()
75
118
{
76
 
        __iuprintf("startDocument()\n");
 
119
        _U(("startDocument()\n"), LC_START_DOCUMENT);
77
120
}
78
121
 
79
122
void RawListenerImpl::endDocument()
80
123
{
81
 
        __idprintf("endDocument()\n");
 
124
        _D(("endDocument()\n"), 
 
125
                LC_START_DOCUMENT);
82
126
}
83
127
 
84
128
void RawListenerImpl::openPageSpan(const int span, const bool isLastPageSpan,
85
129
                                  const float marginLeft, const float marginRight,
86
130
                                  const float marginTop, const float marginBottom)
87
131
{
88
 
        __iuprintf("openPageSpan(TODO: add args)\n");
 
132
        _U(("openPageSpan(span: %d, isLastPageSpan: %s, marginLeft: %.4f, marginRight: %.4f, marginTop: %.4f, marginBottom: %.4f\n",
 
133
                        span, (isLastPageSpan ? "true" : "false"), marginLeft, marginRight, marginTop, marginBottom),
 
134
                LC_OPEN_PAGE_SPAN);
89
135
}
90
 
                                                 
 
136
 
91
137
void RawListenerImpl::closePageSpan()
92
138
{
93
 
        __idprintf("closePageSpan()\n");
 
139
        _D(("closePageSpan()\n"),
 
140
                LC_OPEN_PAGE_SPAN);
94
141
}
95
 
        
 
142
 
96
143
void RawListenerImpl::openHeaderFooter(const WPXHeaderFooterType headerFooterType, const WPXHeaderFooterOccurence headerFooterOccurence)
97
144
{
98
 
        __iuprintf("openHeaderFooter(TODO: add args)\n");
 
145
        _U(("openHeaderFooter(headerFooterType: %d, headerFooterOccurence: %d)\n",
 
146
                headerFooterType, headerFooterOccurence),
 
147
                LC_OPEN_HEADER_FOOTER);
99
148
}
100
149
 
101
150
void RawListenerImpl::closeHeaderFooter(const WPXHeaderFooterType headerFooterType, const WPXHeaderFooterOccurence headerFooterOccurence)
102
151
{
103
 
        __idprintf("closeHeaderFooter(TODO: add args)\n");
 
152
        _D(("closeHeaderFooter(headerFooterType: %d, headerFooterOccurence: %d)\n",
 
153
                        headerFooterType, headerFooterOccurence),
 
154
                LC_OPEN_HEADER_FOOTER);
104
155
}
105
156
 
106
157
void RawListenerImpl::openParagraph(const guint8 paragraphJustification, const guint32 textAttributeBits,
107
 
                                   const float marginLeftOffset, const float marginRightOffset,
108
 
                                   const gchar *fontName, const float fontSize, 
109
 
                                   const float lineSpacing, 
110
 
                                   const bool isColumnBreak, const bool isPageBreak)
 
158
                                    const float marginLeftOffset, const float marginRightOffset,
 
159
                                    const gchar *fontName, const float fontSize, 
 
160
                                    const float lineSpacing, 
 
161
                                    const bool isColumnBreak, const bool isPageBreak)
111
162
{
112
 
        __iuprintf("openParagraph(TODO: add args)\n");
 
163
        _U(("openParagraph(paragraphJustification: %d, textAttributeBits: %d, marginLeftOffset: %.4f, marginRightOffset: %.4f, fontName: %s, fontSize: %.4f, lineSpacing: %.4f, isColumnBreak: %s, isPageBreak: %s)\n",
 
164
            paragraphJustification, textAttributeBits,
 
165
            marginLeftOffset, marginRightOffset, 
 
166
            fontName, fontSize,
 
167
            lineSpacing, (isColumnBreak ? "true" : "false"), (isPageBreak ? "true" : "false")),
 
168
           LC_OPEN_PARAGRAPH);
113
169
}
114
 
        
 
170
 
115
171
void RawListenerImpl::closeParagraph()
116
172
{
117
 
        __idprintf("closeParagraph()\n");
 
173
        _D(("closeParagraph()\n"),
 
174
                LC_OPEN_PARAGRAPH);
118
175
}
119
 
        
 
176
 
120
177
void RawListenerImpl::openSpan(const guint32 textAttributeBits, const gchar *fontName, const float fontSize)
121
178
{
122
 
        __iuprintf("openSpan(textAttributeBits: %u, fontName: %s, fontSize: %.4f)\n", textAttributeBits, fontName, fontSize);
 
179
        _U(("openSpan(textAttributeBits: %u, fontName: %s, fontSize: %.4f\n",
 
180
            textAttributeBits, fontName, fontSize), LC_OPEN_SPAN);
123
181
}
124
 
        
 
182
 
125
183
void RawListenerImpl::closeSpan()
126
184
{
127
 
        __idprintf("closeSpan()\n");
 
185
        _D(("closeSpan()\n"),
 
186
                LC_OPEN_SPAN);
128
187
}
129
 
        
 
188
 
130
189
void RawListenerImpl::openSection(const unsigned int numColumns, const float spaceAfter)
131
190
{
132
 
        __iuprintf("openSection(numColumns: %u, spaceAfter: %.4f)\n", numColumns, spaceAfter);
 
191
        _U(("openSection(numColumns: %u, spaceAfter: %.4f)\n", numColumns, spaceAfter),
 
192
                LC_OPEN_SECTION);
133
193
}
134
 
        
 
194
 
135
195
void RawListenerImpl::closeSection()
136
196
{
137
 
        __idprintf("closeSection()\n");
 
197
        _D(("closeSection()\n"),
 
198
                LC_OPEN_SECTION);
138
199
}
139
200
 
140
201
void RawListenerImpl::insertTab()
144
205
 
145
206
void RawListenerImpl::insertText(const UCSString &text)
146
207
{
 
208
        UTF8String textUTF8(text);
 
209
        __iprintf("insertText(text: %s)\n", textUTF8.getUTF8());
147
210
}
148
 
        
 
211
 
149
212
void RawListenerImpl::insertLineBreak()
150
213
{
151
214
        __iprintf("insertLineBreak()\n");
152
215
}
153
216
 
154
 
void RawListenerImpl::defineOrderedListLevel(const int listID, const guint16 listLevel, const WPXNumberingType listType, 
 
217
void RawListenerImpl::defineOrderedListLevel(const int listID, const guint16 listLevel, const WPXNumberingType listType,
155
218
                                            const UCSString &textBeforeNumber, const UCSString &textAfterNumber,
156
219
                                            const int startingNumber)
157
220
{
 
221
        UTF8String textBeforeNumberUTF8(textBeforeNumber);
 
222
        UTF8String textAfterNumberUTF8(textAfterNumber);
 
223
        __iprintf("defineOrderedListLevel(listID: %d, listLevel: %d, listType: %d, textBeforeNumber: %s, textAfterNumber: %s, startingNumber: %d)\n",
 
224
                listID, listLevel, listType,
 
225
                textBeforeNumberUTF8.getUTF8(), textAfterNumberUTF8.getUTF8(),
 
226
                startingNumber);
158
227
}
159
 
                                                
 
228
 
160
229
void RawListenerImpl::defineUnorderedListLevel(const int listID, const guint16 listLevel, const UCSString &bullet)
161
230
{
 
231
        UTF8String bulletUTF8(bullet);
 
232
        __iprintf("defineUnorderedListLevel(listID: %d, listLevel: %d, bullet: %s)\n", listID, listLevel, bulletUTF8.getUTF8());
162
233
}
163
234
 
164
235
void RawListenerImpl::openOrderedListLevel(const int listID)
165
236
{
 
237
        _U(("openOrderedListLevel(listID: %d)\n", listID),
 
238
                LC_OPEN_ORDERED_LIST_LEVEL);
166
239
}
167
240
 
168
241
void RawListenerImpl::openUnorderedListLevel(const int listID)
169
242
{
 
243
        _U(("openUnorderedListLevel(listID: %d)\n", listID),
 
244
                LC_OPEN_UNORDERED_LIST_LEVEL);
170
245
}
171
246
 
172
247
void RawListenerImpl::closeOrderedListLevel()
173
248
{
 
249
        _D(("closeOrderedListLevel()\n"),
 
250
                LC_OPEN_ORDERED_LIST_LEVEL);
174
251
}
175
252
 
176
253
void RawListenerImpl::closeUnorderedListLevel()
177
254
{
 
255
        _D(("closeUnorderedListLevel()\n"),
 
256
                LC_OPEN_UNORDERED_LIST_LEVEL);
178
257
}
179
258
 
180
259
void RawListenerImpl::openListElement(const guint8 paragraphJustification, const guint32 textAttributeBits,
182
261
                                     const gchar *fontName, const float fontSize, 
183
262
                                     const float lineSpacing)
184
263
{
 
264
        _U(("openListElement(paragraphJustification: %d, textAttributeBits: %d, marginLeftOffset: %.4f, marginRightOffset: %.4f, fontName: %s, fontSize: %.4f, lineSpacing: %.4f)\n",
 
265
            paragraphJustification, textAttributeBits,
 
266
            marginLeftOffset, marginRightOffset, 
 
267
            fontName, fontSize,
 
268
            lineSpacing),
 
269
           LC_OPEN_LIST_ELEMENT);
185
270
}
186
 
                                         
 
271
 
187
272
void RawListenerImpl::closeListElement()
188
273
{
 
274
        _D(("closeListElement()\n"),
 
275
                LC_OPEN_LIST_ELEMENT);
189
276
}
190
 
        
 
277
 
191
278
void RawListenerImpl::openFootnote(int number)
192
279
{
193
 
        __iuprintf("openFootnote(number: %d)\n", number);
 
280
        _U(("openFootnote(number: %d)\n", number),
 
281
                LC_OPEN_FOOTNOTE);
194
282
}
195
283
 
196
284
void RawListenerImpl::closeFootnote()
197
285
{
198
 
        __idprintf("closeFootnote()\n");
 
286
        _D(("closeFootnote()\n"),
 
287
                LC_OPEN_FOOTNOTE);
199
288
}
200
289
 
201
290
void RawListenerImpl::openEndnote(int number)
202
291
{
203
 
        __iuprintf("openEndnote(number: %d)\n", number);
 
292
        _U(("openEndnote(number: %d)\n", number),
 
293
                LC_OPEN_ENDNOTE);
204
294
}
205
295
 
206
296
void RawListenerImpl::closeEndnote()
207
297
{
208
 
        __idprintf("closeEndnote()\n");
 
298
        _D(("closeEndnote()\n"),
 
299
                LC_OPEN_ENDNOTE);
209
300
}
210
301
 
211
 
void RawListenerImpl::openTable(const guint8 tablePositionBits, 
 
302
void RawListenerImpl::openTable(const guint8 tablePositionBits,
212
303
                               const float marginLeftOffset, const float marginRightOffset,
213
304
                               const float leftOffset, const vector < WPXColumnDefinition > &columns)
214
305
{
 
306
        _U(("openTable(tablePositionBits: %d, marginLeftOffset: %.4f, marginRightOffset: %.4f, leftOffset: %.4f, TODO: columns defs.)\n",
 
307
                        tablePositionBits, marginLeftOffset, marginRightOffset, leftOffset),
 
308
                LC_OPEN_TABLE);
215
309
}
216
 
                                   
 
310
 
217
311
void RawListenerImpl::openTableRow()
218
312
{
 
313
        _U(("openTableRow()\n"),
 
314
                LC_OPEN_TABLE_ROW);
219
315
}
220
316
 
221
317
void RawListenerImpl::closeTableRow()
222
318
{
 
319
        _D(("closeTableRow()\n"),
 
320
                LC_OPEN_TABLE_ROW);
223
321
}
224
322
 
225
 
void RawListenerImpl::openTableCell(const guint32 col, const guint32 row, const guint32 colSpan, const guint32 rowSpan, 
226
 
                                   const guint8 borderBits, 
 
323
void RawListenerImpl::openTableCell(const guint32 col, const guint32 row, const guint32 colSpan, const guint32 rowSpan,
 
324
                                   const guint8 borderBits,
227
325
                                   const RGBSColor * cellFgColor, const RGBSColor * cellBgColor)
228
326
{
 
327
        _U(("openTableCell(col: %d, row: %d, colSpan: %d, rowSpan: %d, borderBits: %d, cellFgColor: #%02x%02x%02x s:%02x, cellBgColor: #%02x%02x%02x s:%02x)\n",
 
328
                        col, row, colSpan, rowSpan,
 
329
                        borderBits,
 
330
                        // The saturation cannot ever be more that 0x64. It it is, cellFgColor or cellBgColor is NULL
 
331
                        (cellFgColor?cellFgColor->m_r:0xff), (cellFgColor?cellFgColor->m_g:0xff), (cellFgColor?cellFgColor->m_b:0xff), (cellFgColor?cellFgColor->m_s:0xff),
 
332
                        (cellBgColor?cellBgColor->m_r:0xff), (cellBgColor?cellBgColor->m_g:0xff), (cellBgColor?cellBgColor->m_b:0xff), (cellBgColor?cellBgColor->m_s:0xff)),
 
333
                LC_OPEN_TABLE_CELL);
229
334
}
230
335
 
231
336
void RawListenerImpl::closeTableCell()
232
337
{
 
338
        _D(("closeTableCell()\n"),
 
339
                LC_OPEN_TABLE_CELL);
233
340
}
234
341
 
235
342
void RawListenerImpl::insertCoveredTableCell(const guint32 col, const guint32 row)
236
343
{
 
344
        __iprintf("insertCoveredTableCell(col: %d, row: %d)\n", col, row);
237
345
}
238
 
        
 
346
 
239
347
void RawListenerImpl::closeTable()
240
348
{
241
 
}
242
 
 
243
 
/*
244
 
void RawListener::insertCharacter(const guint16 character)
245
 
{
246
 
        if (!m_isUndoOn) {
247
 
                // first convert from ucs2 to ucs4
248
 
                gunichar characterUCS4 = (gunichar) character;
249
 
                
250
 
                // then convert from ucs4 to utf8 and write it
251
 
                gchar *characterUTF8 = g_ucs4_to_utf8(&characterUCS4, 1, NULL, NULL, NULL); // TODO: handle errors
252
 
                printf("%s", characterUTF8);
253
 
                
254
 
                // clean up our mess
255
 
                g_free(characterUTF8);
256
 
        }
257
 
}
258
 
 
259
 
void RawListener::undoChange(const guint8 undoType, const guint16 undoLevel)
260
 
{
261
 
        if (undoType == WP6_UNDO_GROUP_INVALID_TEXT_START) {
262
 
                //printf("<UNDO ON>");
263
 
                m_isUndoOn = true;
264
 
        }
265
 
        else if (undoType == WP6_UNDO_GROUP_INVALID_TEXT_END) {
266
 
                //printf("<UNDO OFF>");
267
 
                m_isUndoOn = false;
268
 
        }
269
 
}
270
 
 
271
 
void RawListener::lineSpacingChange(const float lineSpacing)
272
 
{
273
 
        printf("<line-spacing:%i>", lineSpacing);
274
 
 
275
 
}
276
 
 
277
 
void RawListener::justificationChange(const guint8 justification)
278
 
{
279
 
        printf("<justification:%i>", justification);
280
 
 
281
 
}
282
 
 
283
 
void RawListener::insertTab(const guint8 tabType)
284
 
{
285
 
        if (!m_isUndoOn) {
286
 
                printf("<TAB: %i>", tabType);
287
 
        }
288
 
}
289
 
 
290
 
void RawListener::insertEOL()
291
 
{
292
 
        if (!m_isUndoOn) {
293
 
                printf("<EOL>\n");
294
 
        }
295
 
}
296
 
 
297
 
void RawListener::insertBreak(const guint8 breakType)
298
 
{
299
 
        switch(breakType)
300
 
        {
301
 
        case WPX_PAGE_BREAK:
302
 
                printf("\n<HARD PAGE BREAK>\n");
303
 
                break;
304
 
        case WPX_SOFT_PAGE_BREAK:
305
 
                printf("\n<SOFT PAGE BREAK>\n");
306
 
                break;
307
 
        case WPX_COLUMN_BREAK:
308
 
                printf("\n<COLUMN BREAK>\n");
309
 
                break;
310
 
        }
311
 
}
312
 
 
313
 
void RawListener::setDate(const guint16 year, const guint8 month, const guint8 day, 
314
 
                          const guint8 hour, const guint8 minute, const guint8 second,
315
 
                          const guint8 dayOfWeek, const guint8 timeZone, const guint8 unused)
316
 
{
317
 
        printf("<DATE SET year: %i month: %i day: %i hour: %i minute: %i second: %i dayOfWeek: %i timeZone: %i unused: %i>\n");
318
 
}
319
 
void RawListener::setExtendedInformation(const guint16 type, const UCSString &data)
320
 
{
321
 
        UTF8String tempUTF8(data);
322
 
        printf("<EXTENDED INFO type: %i data: %s>\n", type, tempUTF8.getUTF8());
323
 
        
324
 
}
325
 
void RawListener::updateOutlineDefinition(const WP6OutlineLocation outlineLocation, const guint16 outlineHash, 
326
 
                                          const guint8 *numberingMethods, const guint8 tabBehaviourFlag)
327
 
{
328
 
        if (!m_isUndoOn) {
329
 
                printf("<UPDATE OUTLINE DEFINITION (outlineHash:%i, numbering-methods:.., tab-behaviour-flag:%i)>\n", 
330
 
                       outlineHash, tabBehaviourFlag);
331
 
        }       
332
 
}
333
 
 
334
 
void RawListener::paragraphNumberOn(const guint16 outlineHash, const guint8 level, const guint8 flag)
335
 
{
336
 
        if (!m_isUndoOn) {
337
 
                printf("<PARAGRAPH NUMBER ON (outlineHash:%i, level:%i, flag:%i)>", 
338
 
                       outlineHash, level, flag);
339
 
        }       
340
 
}
341
 
 
342
 
void RawListener::paragraphNumberOff()
343
 
{
344
 
        if (!m_isUndoOn) {
345
 
                printf("<PARAGRAPH NUMBER OFF>");
346
 
        }       
347
 
}
348
 
 
349
 
void RawListener::displayNumberReferenceGroupOn(const guint8 subGroup, const guint8 level)
350
 
{
351
 
        if (!m_isUndoOn) {
352
 
                printf("<DISPLAY NUMBER REF ON (subgroup:%i, level:%i)>", subGroup, level);
353
 
        }       
354
 
}
355
 
 
356
 
void RawListener::displayNumberReferenceGroupOff(const guint8 subGroup)
357
 
{
358
 
        if (!m_isUndoOn) {
359
 
                printf("<DISPLAY NUMBER REF OFF (subgroup:%i)>", subGroup);
360
 
        }       
361
 
}
362
 
 
363
 
void RawListener::styleGroupOn(const guint8 subGroup)
364
 
{
365
 
        if (!m_isUndoOn) {
366
 
                printf("<STYLE GROUP ON (subgroup:%i)>", subGroup);
367
 
        }       
368
 
}
369
 
 
370
 
void RawListener::styleGroupOff(const guint8 subGroup)
371
 
{
372
 
        if (!m_isUndoOn) {
373
 
                printf("<STYLE GROUP OFF (subgroup:%i)>", subGroup);
374
 
        }       
375
 
}
376
 
 
377
 
void RawListener::suppressPageCharacteristics(const guint8 suppressCode)
378
 
{
379
 
        if (!m_isUndoOn) {
380
 
                printf("<SUPPRESS PAGE CHARACTERISTICS (suppressCode: %i)>", suppressCode);
381
 
        }       
382
 
}
383
 
 
384
 
void RawListener::insertCell(const guint8 colSpan, const guint8 rowSpan, const bool boundFromLeft, const bool boundFromAbove, 
385
 
                             const guint8 borderBits, const RGBSColor * cellFgColor, const RGBSColor * cellBgColor)
386
 
{
387
 
        if (!m_isUndoOn) {
388
 
                printf("<INSERT CELL (colSpan: %i, rowSpan: %i, borderBits: %x)>", colSpan, rowSpan, borderBits);
389
 
        }               
390
 
}
391
 
*/
 
349
        _D(("closeTable()\n"),
 
350
                LC_OPEN_TABLE);
 
351
}