34
34
XHTMLTagAction::~XHTMLTagAction() {
37
BookReader &XHTMLTagAction::bookReader(XHTMLReader &reader) {
38
return reader.myModelReader;
41
const std::string &XHTMLTagAction::pathPrefix(XHTMLReader &reader) {
42
return reader.myPathPrefix;
37
45
class XHTMLTagParagraphAction : public XHTMLTagAction {
111
119
void XHTMLTagParagraphAction::doAtStart(XHTMLReader &reader, const char**) {
112
reader.myModelReader.beginParagraph();
120
bookReader(reader).beginParagraph();
115
123
void XHTMLTagParagraphAction::doAtEnd(XHTMLReader &reader) {
116
reader.myModelReader.endParagraph();
124
bookReader(reader).endParagraph();
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();
124
132
void XHTMLTagRestartParagraphAction::doAtEnd(XHTMLReader&) {
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);
136
144
void XHTMLTagItemAction::doAtEnd(XHTMLReader &reader) {
137
reader.myModelReader.endParagraph();
145
bookReader(reader).endParagraph();
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();
148
reader.myModelReader.endParagraph();
156
bookReader(reader).endParagraph();
150
158
if ((strlen(fileName) > 2) && strncmp(fileName, "./", 2) == 0) {
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));
156
reader.myModelReader.beginParagraph();
165
bookReader(reader).beginParagraph();
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);
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();
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);
185
194
myHyperlinkStack.push(REGULAR);
187
196
const char *name = reader.attributeValue(xmlattributes, "name");
189
reader.myModelReader.addHyperlinkLabel(reader.myReferenceName + "#" + name);
198
bookReader(reader).addHyperlinkLabel(reader.myReferenceName + "#" + name);
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);
198
207
myHyperlinkStack.pop();
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();
208
reader.myModelReader.pushKind(myControl);
209
reader.myModelReader.beginParagraph();
217
bookReader(reader).pushKind(myControl);
218
bookReader(reader).beginParagraph();
212
221
void XHTMLTagParagraphWithControlAction::doAtEnd(XHTMLReader &reader) {
213
reader.myModelReader.endParagraph();
214
reader.myModelReader.popKind();
222
bookReader(reader).endParagraph();
223
bookReader(reader).popKind();
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);
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;
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;
233
244
void XHTMLReader::fillTagTable() {
321
332
return readDocument(pathPrefix + fileName);
335
bool XHTMLReader::readFile(const std::string &pathPrefix, shared_ptr<ZLInputStream> stream, const std::string &referenceName) {
336
myModelReader.addHyperlinkLabel(referenceName);
340
myPathPrefix = pathPrefix;
341
myReferenceName = referenceName;
343
myPreformatted = false;
345
return readDocument(stream);
325
348
void XHTMLReader::startElementHandler(const char *tag, const char **attributes) {
326
349
static const std::string HASH = "#";