1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
* Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef __MOBIPOCKETHTMLBOOKREADER_H__
#define __MOBIPOCKETHTMLBOOKREADER_H__
#include <set>
#include "../html/HtmlBookReader.h"
class MobipocketHtmlBookReader : public HtmlBookReader {
public:
MobipocketHtmlBookReader(const ZLFile &file, BookModel &model, const PlainTextFormat &format, const std::string &encoding);
void readDocument(ZLInputStream &stream);
private:
void startDocumentHandler();
bool tagHandler(const HtmlTag &tag);
bool characterDataHandler(const char *text, std::size_t len, bool convert);
shared_ptr<HtmlTagAction> createAction(const std::string &tag);
public:
class TOCReader {
public:
TOCReader(MobipocketHtmlBookReader &reader);
void reset();
void addReference(std::size_t position, const std::string &text);
void setStartOffset(std::size_t position);
void setEndOffset(std::size_t position);
bool rangeContainsPosition(std::size_t position);
void startReadEntry(std::size_t position);
void endReadEntry();
void appendText(const char *text, std::size_t len);
const std::map<std::size_t,std::string> &entries() const;
private:
MobipocketHtmlBookReader &myReader;
std::map<std::size_t,std::string> myEntries;
bool myIsActive;
std::size_t myStartOffset;
std::size_t myEndOffset;
std::size_t myCurrentReference;
std::string myCurrentEntryText;
};
private:
int myImageCounter;
const std::string myFileName;
std::vector<std::pair<std::size_t,std::size_t> > myPositionToParagraphMap;
std::set<std::size_t> myFileposReferences;
bool myInsideGuide;
TOCReader myTocReader;
friend class MobipocketHtmlImageTagAction;
friend class MobipocketHtmlHrefTagAction;
friend class MobipocketHtmlGuideTagAction;
friend class MobipocketHtmlReferenceTagAction;
friend class MobipocketHtmlPagebreakTagAction;
friend class TOCReader;
};
#endif /* __MOBIPOCKETHTMLBOOKREADER_H__ */
|