~ubuntu-branches/ubuntu/vivid/fbreader/vivid-proposed

« back to all changes in this revision

Viewing changes to fbreader/src/formats/xhtml/XHTMLReader.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Eugene V. Lyubimkin
  • Date: 2008-06-17 23:01:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617230153-a16c45tq69j8geru
Tags: 0.8.17-11
* debian/control:
  - Enhanced all ZLibrary descriptions, not the main one.
  - Done some renaming to use canonical names of libraries and toolkits in
    decriptions, as suggested by developers-reference:
    'qt' -> 'Qt', 'gtk' -> 'GTK+', 'zlibrary' -> 'ZLibrary'.
  - Bump 'Depends' on quilt to (>= 0.24).
* debian/rules:
  - Included quilt makefile instead of quilt makefile instead
    of copy&paste'ing it.
* debian/fbreader.links:
  - Added this file to relay on dh_link's work instead of using 'ln -sf'
    directly in the debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
XHTMLTagAction::~XHTMLTagAction() {
35
35
}
36
36
 
 
37
BookReader &XHTMLTagAction::bookReader(XHTMLReader &reader) {
 
38
        return reader.myModelReader;
 
39
}
 
40
 
 
41
const std::string &XHTMLTagAction::pathPrefix(XHTMLReader &reader) {
 
42
        return reader.myPathPrefix;
 
43
}
 
44
 
37
45
class XHTMLTagParagraphAction : public XHTMLTagAction {
38
46
 
39
47
public:
109
117
};
110
118
 
111
119
void XHTMLTagParagraphAction::doAtStart(XHTMLReader &reader, const char**) {
112
 
        reader.myModelReader.beginParagraph();
 
120
        bookReader(reader).beginParagraph();
113
121
}
114
122
 
115
123
void XHTMLTagParagraphAction::doAtEnd(XHTMLReader &reader) {
116
 
        reader.myModelReader.endParagraph();
 
124
        bookReader(reader).endParagraph();
117
125
}
118
126
 
119
127
void XHTMLTagRestartParagraphAction::doAtStart(XHTMLReader &reader, const char**) {
120
 
        reader.myModelReader.endParagraph();
121
 
        reader.myModelReader.beginParagraph();
 
128
        bookReader(reader).endParagraph();
 
129
        bookReader(reader).beginParagraph();
122
130
}
123
131
 
124
132
void XHTMLTagRestartParagraphAction::doAtEnd(XHTMLReader&) {
125
133
}
126
134
 
127
135
void XHTMLTagItemAction::doAtStart(XHTMLReader &reader, const char**) {
128
 
        reader.myModelReader.endParagraph();
 
136
        bookReader(reader).endParagraph();
129
137
        // TODO: increase left indent
130
 
        reader.myModelReader.beginParagraph();
 
138
        bookReader(reader).beginParagraph();
131
139
        // TODO: replace bullet sign by number inside OL tag
132
140
        const std::string bullet = "\xE2\x80\xA2\xC0\xA0";
133
 
        reader.myModelReader.addData(bullet);
 
141
        bookReader(reader).addData(bullet);
134
142
}
135
143
 
136
144
void XHTMLTagItemAction::doAtEnd(XHTMLReader &reader) {
137
 
        reader.myModelReader.endParagraph();
 
145
        bookReader(reader).endParagraph();
138
146
}
139
147
 
140
148
XHTMLTagImageAction::XHTMLTagImageAction(const std::string &nameAttribute) : myNameAttribute(nameAttribute) {
143
151
void XHTMLTagImageAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
144
152
        const char *fileName = reader.attributeValue(xmlattributes, myNameAttribute.c_str());
145
153
        if (fileName != 0) {
146
 
                bool flag = reader.myModelReader.paragraphIsOpen();
 
154
                bool flag = bookReader(reader).paragraphIsOpen();
147
155
                if (flag) {
148
 
                        reader.myModelReader.endParagraph();
 
156
                        bookReader(reader).endParagraph();
149
157
                }
150
158
                if ((strlen(fileName) > 2) && strncmp(fileName, "./", 2) == 0) {
151
159
                        fileName +=2;
152
160
                }
153
 
                reader.myModelReader.addImageReference(fileName);
154
 
                reader.myModelReader.addImage(fileName, new ZLFileImage("image/auto", reader.myPathPrefix + fileName, 0));
 
161
                const std::string fullfileName = pathPrefix(reader) + fileName;
 
162
                bookReader(reader).addImageReference(fullfileName);
 
163
                bookReader(reader).addImage(fullfileName, new ZLFileImage("image/auto", fullfileName, 0));
155
164
                if (flag) {
156
 
                        reader.myModelReader.beginParagraph();
 
165
                        bookReader(reader).beginParagraph();
157
166
                }
158
167
        }
159
168
}
165
174
}
166
175
 
167
176
void XHTMLTagControlAction::doAtStart(XHTMLReader &reader, const char**) {
168
 
        reader.myModelReader.pushKind(myControl);
169
 
        reader.myModelReader.addControl(myControl, true);
 
177
        bookReader(reader).pushKind(myControl);
 
178
        bookReader(reader).addControl(myControl, true);
170
179
}
171
180
 
172
181
void XHTMLTagControlAction::doAtEnd(XHTMLReader &reader) {
173
 
        reader.myModelReader.addControl(myControl, false);
174
 
        reader.myModelReader.popKind();
 
182
        bookReader(reader).addControl(myControl, false);
 
183
        bookReader(reader).popKind();
175
184
}
176
185
 
177
186
void XHTMLTagHyperlinkAction::doAtStart(XHTMLReader &reader, const char **xmlattributes) {
180
189
                const std::string link = (*href == '#') ? (reader.myReferenceName + href) : href;
181
190
                FBTextKind hyperlinkType = MiscUtil::isReference(link) ? EXTERNAL_HYPERLINK : INTERNAL_HYPERLINK;
182
191
                myHyperlinkStack.push(hyperlinkType);
183
 
                reader.myModelReader.addHyperlinkControl(hyperlinkType, link);
 
192
                bookReader(reader).addHyperlinkControl(hyperlinkType, link);
184
193
        } else {
185
194
                myHyperlinkStack.push(REGULAR);
186
195
        }
187
196
        const char *name = reader.attributeValue(xmlattributes, "name");
188
197
        if (name != 0) {
189
 
                reader.myModelReader.addHyperlinkLabel(reader.myReferenceName + "#" + name);
 
198
                bookReader(reader).addHyperlinkLabel(reader.myReferenceName + "#" + name);
190
199
        }
191
200
}
192
201
 
193
202
void XHTMLTagHyperlinkAction::doAtEnd(XHTMLReader &reader) {
194
203
        FBTextKind kind = myHyperlinkStack.top();
195
204
        if (kind != REGULAR) {
196
 
                reader.myModelReader.addControl(kind, false);
 
205
                bookReader(reader).addControl(kind, false);
197
206
        }
198
207
        myHyperlinkStack.pop();
199
208
}
202
211
}
203
212
 
204
213
void XHTMLTagParagraphWithControlAction::doAtStart(XHTMLReader &reader, const char**) {
205
 
        if ((myControl == TITLE) && (reader.myModelReader.model().bookTextModel()->paragraphsNumber() > 1)) {
206
 
                reader.myModelReader.insertEndOfSectionParagraph();
 
214
        if ((myControl == TITLE) && (bookReader(reader).model().bookTextModel()->paragraphsNumber() > 1)) {
 
215
                bookReader(reader).insertEndOfSectionParagraph();
207
216
        }
208
 
        reader.myModelReader.pushKind(myControl);
209
 
        reader.myModelReader.beginParagraph();
 
217
        bookReader(reader).pushKind(myControl);
 
218
        bookReader(reader).beginParagraph();
210
219
}
211
220
 
212
221
void XHTMLTagParagraphWithControlAction::doAtEnd(XHTMLReader &reader) {
213
 
        reader.myModelReader.endParagraph();
214
 
        reader.myModelReader.popKind();
 
222
        bookReader(reader).endParagraph();
 
223
        bookReader(reader).popKind();
215
224
}
216
225
 
217
226
void XHTMLTagPreAction::doAtStart(XHTMLReader &reader, const char**) {
218
227
        reader.myPreformatted = true;
219
 
        reader.myModelReader.beginParagraph();
220
 
        reader.myModelReader.addControl(CODE, true);
 
228
        bookReader(reader).beginParagraph();
 
229
        bookReader(reader).addControl(CODE, true);
221
230
}
222
231
 
223
232
void XHTMLTagPreAction::doAtEnd(XHTMLReader &reader) {
224
 
        reader.myModelReader.addControl(CODE, false);
225
 
        reader.myModelReader.endParagraph();
 
233
        bookReader(reader).addControl(CODE, false);
 
234
        bookReader(reader).endParagraph();
226
235
        reader.myPreformatted = false;
227
236
}
228
237
 
229
 
void XHTMLReader::addAction(const std::string &tag, XHTMLTagAction *action) {
230
 
        ourTagActions.insert(std::pair<std::string,XHTMLTagAction*>(tag,action));
 
238
XHTMLTagAction *XHTMLReader::addAction(const std::string &tag, XHTMLTagAction *action) {
 
239
        XHTMLTagAction *old = ourTagActions[tag];
 
240
        ourTagActions[tag] = action;
 
241
        return old;
231
242
}
232
243
 
233
244
void XHTMLReader::fillTagTable() {
321
332
        return readDocument(pathPrefix + fileName);
322
333
}
323
334
 
 
335
bool XHTMLReader::readFile(const std::string &pathPrefix, shared_ptr<ZLInputStream> stream, const std::string &referenceName) {
 
336
        myModelReader.addHyperlinkLabel(referenceName);
 
337
 
 
338
        fillTagTable();
 
339
 
 
340
        myPathPrefix = pathPrefix;
 
341
        myReferenceName = referenceName;
 
342
 
 
343
        myPreformatted = false;
 
344
 
 
345
        return readDocument(stream);
 
346
}
324
347
 
325
348
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
326
349
        static const std::string HASH = "#";