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
20 #ifndef __MOBIPOCKETHTMLBOOKREADER_H__
21 #define __MOBIPOCKETHTMLBOOKREADER_H__
25 #include "../html/HtmlBookReader.h"
27 class MobipocketHtmlBookReader
: public HtmlBookReader
{
30 MobipocketHtmlBookReader(const std::string
&fileName
, BookModel
&model
, const PlainTextFormat
&format
, const std::string
&encoding
);
31 void readDocument(ZLInputStream
&stream
);
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
);
43 TOCReader(MobipocketHtmlBookReader
&reader
);
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
);
55 void appendText(const char *text
, size_t len
);
57 const std::map
<size_t,std::string
> &entries() const;
60 MobipocketHtmlBookReader
&myReader
;
62 std::map
<size_t,std::string
> myEntries
;
68 size_t myCurrentReference
;
69 std::string myCurrentEntryText
;
74 const std::string myFileName
;
76 std::vector
<std::pair
<size_t,size_t> > myPositionToParagraphMap
;
77 std::set
<size_t> myFileposReferences
;
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__ */