gui
[lbook_fbreader.git] / fbreader / src / formats / pdb / MobipocketHtmlBookReader.h
blob2b4090a9d64bb73ac15d971dde33aa09c84b1ac5
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 #ifndef __MOBIPOCKETHTMLBOOKREADER_H__
21 #define __MOBIPOCKETHTMLBOOKREADER_H__
23 #include <set>
25 #include "../html/HtmlBookReader.h"
27 class MobipocketHtmlBookReader : public HtmlBookReader {
29 public:
30 MobipocketHtmlBookReader(const std::string &fileName, BookModel &model, const PlainTextFormat &format, const std::string &encoding);
31 void readDocument(ZLInputStream &stream);
33 private:
34 void startDocumentHandler();
35 bool tagHandler(const HtmlTag &tag);
36 bool characterDataHandler(const char *text, int len, bool convert);
37 shared_ptr<HtmlTagAction> createAction(const std::string &tag);
39 public:
40 class TOCReader {
42 public:
43 TOCReader(MobipocketHtmlBookReader &reader);
44 void reset();
46 void addReference(size_t position, const std::string &text);
48 void setStartOffset(size_t position);
49 void setEndOffset(size_t position);
51 bool rangeContainsPosition(size_t position);
53 void startReadEntry(size_t position);
54 void endReadEntry();
55 void appendText(const char *text, size_t len);
57 const std::map<size_t,std::string> &entries() const;
59 private:
60 MobipocketHtmlBookReader &myReader;
62 std::map<size_t,std::string> myEntries;
64 bool myIsActive;
65 size_t myStartOffset;
66 size_t myEndOffset;
68 size_t myCurrentReference;
69 std::string myCurrentEntryText;
72 private:
73 int myImageCounter;
74 const std::string myFileName;
76 std::vector<std::pair<size_t,size_t> > myPositionToParagraphMap;
77 std::set<size_t> myFileposReferences;
78 bool myInsideGuide;
79 TOCReader myTocReader;
81 friend class MobipocketHtmlImageTagAction;
82 friend class MobipocketHtmlHrefTagAction;
83 friend class MobipocketHtmlGuideTagAction;
84 friend class MobipocketHtmlReferenceTagAction;
85 friend class TOCReader;
88 #endif /* __MOBIPOCKETHTMLBOOKREADER_H__ */