~ubuntu-branches/ubuntu/saucy/libwpd/saucy

« back to all changes in this revision

Viewing changes to src/lib/WP42Parser.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2011-11-29 23:31:13 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20111129233113-xdtwca9h0y6wdxst
Tags: 0.9.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
1
2
/* libwpd
2
3
 * Copyright (C) 2003 William Lachance (wrlach@gmail.com)
3
4
 * Copyright (C) 2003 Marc Maurer (uwog@uwog.net)
65
66
 
66
67
                if (readVal < (uint8_t)0x20)
67
68
                {
68
 
                        WPD_DEBUG_MSG(("Offset: %i, Handling Control Character 0x%2x\n", (unsigned int)input->tell(), readVal));                        
 
69
                        WPD_DEBUG_MSG(("Offset: %i, Handling Control Character 0x%2x\n", (unsigned int)input->tell(), readVal));
69
70
 
70
71
                        switch (readVal)
71
72
                        {
72
 
                                case 0x09: // tab
73
 
                                        listener->insertTab(0, 0.0);
74
 
                                        break;
75
 
                                case 0x0A: // hard new line
76
 
                                        listener->insertEOL();
77
 
                                        break;
78
 
                                case 0x0B: // soft new page
79
 
                                        listener->insertBreak(WPX_SOFT_PAGE_BREAK);
80
 
                                        break;
81
 
                                case 0x0C: // hard new page
82
 
                                        listener->insertBreak(WPX_PAGE_BREAK);
83
 
                                        break;
84
 
                                case 0x0D: // soft new line
85
 
                                        listener->insertCharacter(' ');
86
 
                                        break;
87
 
                                default:
88
 
                                        // unsupported or undocumented token, ignore
89
 
                                        break;
 
73
                        case 0x09: // tab
 
74
                                listener->insertTab(0, 0.0);
 
75
                                break;
 
76
                        case 0x0A: // hard new line
 
77
                                listener->insertEOL();
 
78
                                break;
 
79
                        case 0x0B: // soft new page
 
80
                                listener->insertBreak(WPX_SOFT_PAGE_BREAK);
 
81
                                break;
 
82
                        case 0x0C: // hard new page
 
83
                                listener->insertBreak(WPX_PAGE_BREAK);
 
84
                                break;
 
85
                        case 0x0D: // soft new line
 
86
                                listener->insertCharacter(' ');
 
87
                                break;
 
88
                        default:
 
89
                                // unsupported or undocumented token, ignore
 
90
                                break;
90
91
                        }
91
92
                }
92
93
                else if (readVal >= (uint8_t)0x20 && readVal <= (uint8_t)0x7F)
93
94
                {
94
 
                        WPD_DEBUG_MSG(("Offset: %i, Handling Ascii Character 0x%2x\n", (unsigned int)input->tell(), readVal));                  
 
95
                        WPD_DEBUG_MSG(("Offset: %i, Handling Ascii Character 0x%2x\n", (unsigned int)input->tell(), readVal));
95
96
 
96
97
                        // normal ASCII characters
97
98
                        listener->insertCharacter( readVal );
98
99
                }
99
100
                else if (readVal >= (uint8_t)0x80 && readVal <= (uint8_t)0xBF)
100
101
                {
101
 
                        WPD_DEBUG_MSG(("Offset: %i, Handling Single Character Function 0x%2x\n", (unsigned int)input->tell(), readVal));                        
 
102
                        WPD_DEBUG_MSG(("Offset: %i, Handling Single Character Function 0x%2x\n", (unsigned int)input->tell(), readVal));
102
103
 
103
104
                        // single character function codes
104
105
                        switch (readVal)
105
106
                        {
106
 
                                case 0x92:
107
 
                                        listener->attributeChange(true, WP42_ATTRIBUTE_STRIKE_OUT);
108
 
                                        break;
109
 
                                case 0x93:
110
 
                                        listener->attributeChange(false, WP42_ATTRIBUTE_STRIKE_OUT);
111
 
                                        break;
112
 
                                case 0x94:
113
 
                                        listener->attributeChange(true, WP42_ATTRIBUTE_UNDERLINE);
114
 
                                        break;
115
 
                                case 0x95:
116
 
                                        listener->attributeChange(false, WP42_ATTRIBUTE_UNDERLINE);
117
 
                                        break;
118
 
 
119
 
                                case 0x90:
120
 
                                        listener->attributeChange(true, WP42_ATTRIBUTE_REDLINE);
121
 
                                        break;
122
 
                                case 0x91:
123
 
                                        listener->attributeChange(false, WP42_ATTRIBUTE_REDLINE);
124
 
                                        break;
125
 
 
126
 
                                case 0x9C:
127
 
                                        listener->attributeChange(false, WP42_ATTRIBUTE_BOLD);
128
 
                                        break;
129
 
                                case 0x9D:
130
 
                                        listener->attributeChange(true, WP42_ATTRIBUTE_BOLD);
131
 
                                        break;
132
 
 
133
 
                                case 0xB2:
134
 
                                        listener->attributeChange(true, WP42_ATTRIBUTE_ITALICS);
135
 
                                        break;
136
 
                                case 0xB3:
137
 
                                        listener->attributeChange(false, WP42_ATTRIBUTE_ITALICS);
138
 
                                        break;
139
 
                                case 0xB4:
140
 
                                        listener->attributeChange(true, WP42_ATTRIBUTE_SHADOW);
141
 
                                        break;
142
 
                                case 0xB5:
143
 
                                        listener->attributeChange(false, WP42_ATTRIBUTE_SHADOW);
144
 
                                        break;
145
 
 
146
 
                                default:
147
 
                                        // unsupported or undocumented token, ignore
148
 
                                        break;
 
107
                        case 0x92:
 
108
                                listener->attributeChange(true, WP42_ATTRIBUTE_STRIKE_OUT);
 
109
                                break;
 
110
                        case 0x93:
 
111
                                listener->attributeChange(false, WP42_ATTRIBUTE_STRIKE_OUT);
 
112
                                break;
 
113
                        case 0x94:
 
114
                                listener->attributeChange(true, WP42_ATTRIBUTE_UNDERLINE);
 
115
                                break;
 
116
                        case 0x95:
 
117
                                listener->attributeChange(false, WP42_ATTRIBUTE_UNDERLINE);
 
118
                                break;
 
119
 
 
120
                        case 0x90:
 
121
                                listener->attributeChange(true, WP42_ATTRIBUTE_REDLINE);
 
122
                                break;
 
123
                        case 0x91:
 
124
                                listener->attributeChange(false, WP42_ATTRIBUTE_REDLINE);
 
125
                                break;
 
126
 
 
127
                        case 0x9C:
 
128
                                listener->attributeChange(false, WP42_ATTRIBUTE_BOLD);
 
129
                                break;
 
130
                        case 0x9D:
 
131
                                listener->attributeChange(true, WP42_ATTRIBUTE_BOLD);
 
132
                                break;
 
133
 
 
134
                        case 0xB2:
 
135
                                listener->attributeChange(true, WP42_ATTRIBUTE_ITALICS);
 
136
                                break;
 
137
                        case 0xB3:
 
138
                                listener->attributeChange(false, WP42_ATTRIBUTE_ITALICS);
 
139
                                break;
 
140
                        case 0xB4:
 
141
                                listener->attributeChange(true, WP42_ATTRIBUTE_SHADOW);
 
142
                                break;
 
143
                        case 0xB5:
 
144
                                listener->attributeChange(false, WP42_ATTRIBUTE_SHADOW);
 
145
                                break;
 
146
 
 
147
                        default:
 
148
                                // unsupported or undocumented token, ignore
 
149
                                break;
149
150
                        }
150
151
                }
151
152
                else if (readVal >= (uint8_t)0xC0 && readVal <= (uint8_t)0xFE)
167
168
        WPXInputStream *input = getInput();
168
169
        WPXEncryption *encryption = getEncryption();
169
170
        std::list<WPXPageSpan> pageList;
170
 
        std::vector<WP42SubDocument *> subDocuments;    
171
 
        
 
171
        std::vector<WP42SubDocument *> subDocuments;
 
172
 
172
173
        try
173
 
        {
 
174
        {
174
175
                // do a "first-pass" parse of the document
175
176
                // gather table border information, page properties (per-page)
176
177
                WP42StylesListener stylesListener(pageList, subDocuments);
220
221
}
221
222
 
222
223
void WP42Parser::parseSubDocument(WPXDocumentInterface *documentInterface)
223
 
{       
 
224
{
224
225
        std::list<WPXPageSpan> pageList;
225
 
        std::vector<WP42SubDocument *> subDocuments;    
 
226
        std::vector<WP42SubDocument *> subDocuments;
226
227
 
227
228
        WPXInputStream *input = getInput();
228
229
 
229
230
        try
230
 
        {
 
231
        {
231
232
                WP42StylesListener stylesListener(pageList, subDocuments);
232
233
                stylesListener.startSubDocument();
233
234
                parseDocument(input, 0, &stylesListener);
234
235
                stylesListener.endSubDocument();
235
 
                
 
236
 
236
237
                WP42ContentListener listener(pageList, subDocuments, documentInterface);
237
238
                listener.startSubDocument();
238
239
                parseDocument(input, 0, &listener);
250
251
                throw FileException();
251
252
        }
252
253
}
 
254
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */