gui
[lbook_fbreader.git] / fbreader / src / formats / docbook / DocBookBookReader.cpp
blob4fd8cdc7272bba86a5b0d3a7a4abf62900544368
1 /*
2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include <ZLInputStream.h>
22 #include "DocBookBookReader.h"
24 #include "../../bookmodel/BookModel.h"
25 #include "../../model/Paragraph.h"
27 DocBookBookReader::DocBookBookReader(BookModel &model) : BookReader(model) {
28 setMainTextModel();
30 myReadText = false;
33 void DocBookBookReader::characterDataHandler(const char *text, int len) {
34 addDataToBuffer(text, len);
37 void DocBookBookReader::startElementHandler(int tag, const char **) {
38 switch (tag) {
39 case _SECT1:
40 myReadText = true;
41 pushKind(REGULAR);
42 beginContentsParagraph();
43 break;
44 case _PARA:
45 if (myReadText) {
46 beginParagraph();
48 break;
49 case _TITLE:
50 enterTitle();
51 pushKind(SECTION_TITLE);
52 if (myReadText) {
53 beginParagraph();
55 break;
56 case _EMPHASIS:
57 addControl(EMPHASIS, true);
58 break;
59 case _CITETITLE:
60 addControl(CITE, true);
61 break;
62 case _ULINK:
63 case _EMAIL:
64 addControl(CODE, true);
65 break;
66 case _BLOCKQUOTE:
67 pushKind(STRONG);
68 break;
69 default:
70 break;
74 void DocBookBookReader::endElementHandler(int tag) {
75 switch (tag) {
76 case _SECT1:
77 myReadText = false;
78 popKind();
79 endContentsParagraph();
80 insertEndOfSectionParagraph();
81 break;
82 case _PARA:
83 endParagraph();
84 break;
85 case _TITLE:
86 endParagraph();
87 popKind();
88 endContentsParagraph();
89 exitTitle();
90 break;
91 case _EMPHASIS:
92 addControl(EMPHASIS, false);
93 break;
94 case _CITETITLE:
95 addControl(CITE, false);
96 break;
97 case _ULINK:
98 case _EMAIL:
99 addControl(CODE, false);
100 break;
101 case _BLOCKQUOTE:
102 popKind();
103 break;
104 default:
105 break;
109 void DocBookBookReader::readBook(shared_ptr<ZLInputStream> stream) {
110 readDocument(stream);