LRFParser.h Source File documentation

LRFParser.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libe-book project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifndef LRFPARSER_H_INCLUDED
11 #define LRFPARSER_H_INCLUDED
12
13 #include <vector>
14 #include <map>
15
16 #include "LRFCollector.h"
17
18
19 namespace libebook
20 {
21
22 struct LRFHeader;
23
24 class LRFParser
25 {
26 // disable copying
27 LRFParser(const LRFParser &other);
28 LRFParser &operator=(const LRFParser &other);
29
30 enum ObjectType
31 {
32 OBJECT_TYPE_UNSPECIFIED = 0x0,
33 OBJECT_TYPE_PAGE_TREE = 0x1,
34 OBJECT_TYPE_PAGE = 0x2,
35 OBJECT_TYPE_HEADER = 0x3,
36 OBJECT_TYPE_FOOTER = 0x4,
37 OBJECT_TYPE_PAGE_ATR = 0x5,
38 OBJECT_TYPE_BLOCK = 0x6,
39 OBJECT_TYPE_BLOCK_ATR = 0x7,
40 OBJECT_TYPE_MINI_PAGE = 0x8,
41 OBJECT_TYPE_BLOCK_LIST = 0x9,
42 OBJECT_TYPE_TEXT = 0xa,
43 OBJECT_TYPE_TEXT_ATR = 0xb,
44 OBJECT_TYPE_IMAGE = 0xc,
45 OBJECT_TYPE_CANVAS = 0xd,
46 OBJECT_TYPE_PARAGRAPH_ATR = 0xe,
47 OBJECT_TYPE_IMAGE_STREAM = 0x11,
48 OBJECT_TYPE_IMPORT = 0x12,
49 OBJECT_TYPE_BUTTON = 0x13,
50 OBJECT_TYPE_WINDOW = 0x14,
51 OBJECT_TYPE_POP_UP_WIN = 0x15,
52 OBJECT_TYPE_SOUND = 0x16,
53 OBJECT_TYPE_PLANE_STREAM = 0x17,
54 OBJECT_TYPE_FONT = 0x19,
55 OBJECT_TYPE_OBJECT_INFO = 0x1a,
56 OBJECT_TYPE_BOOK_ATR = 0x1c,
57 OBJECT_TYPE_SIMPLE_TEXT = 0x1d,
58 OBJECT_TYPE_TOC = 0x1e
59 };
60
61 struct LRFIndexEntry
62 {
63 unsigned offset;
64 unsigned size;
65 bool reading;
66 bool read;
67 };
68
69 typedef std::map<unsigned, LRFIndexEntry> ObjectIndex_t;
70 typedef std::vector<unsigned> ToC_t;
71
72 public:
73 LRFParser(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document);
74 ~LRFParser();
75
76 bool parse();
77
78 static bool isSupported(librevenge::RVNGInputStream *input);
79
80 private:
81 void readHeader();
82 void readMetadata();
83 void readThumbnail();
84 void readObjectIndex();
85
86 void readObject(unsigned id, unsigned type = OBJECT_TYPE_UNSPECIFIED);
87
88 void readPageTreeObject(librevenge::RVNGInputStream *object);
89 void readPageObject(librevenge::RVNGInputStream *object);
90 void readFooterObject(librevenge::RVNGInputStream *object);
91 void readHeaderObject(librevenge::RVNGInputStream *object);
92 void readPageAtrObject(librevenge::RVNGInputStream *object, unsigned id);
93 void readBlockObject(librevenge::RVNGInputStream *object, unsigned id);
94 void readBlockAtrObject(librevenge::RVNGInputStream *object, unsigned id);
95 void readMiniPageObject(librevenge::RVNGInputStream *object);
96 void readBlockListObject(librevenge::RVNGInputStream *object);
97 void readTextObject(librevenge::RVNGInputStream *object);
98 void readTextAtrObject(librevenge::RVNGInputStream *object, unsigned id);
99 void readImageObject(librevenge::RVNGInputStream *object, unsigned id);
100 void readCanvasObject(librevenge::RVNGInputStream *object);
101 void readParagraphAtrObject(librevenge::RVNGInputStream *object, unsigned id);
102 void readImageStreamObject(librevenge::RVNGInputStream *object, unsigned id);
103 void readImportObject(librevenge::RVNGInputStream *object);
104 void readButtonObject(librevenge::RVNGInputStream *object);
105 void readWindowObject(librevenge::RVNGInputStream *object);
106 void readPopUpWinObject(librevenge::RVNGInputStream *object);
107 void readSoundObject(librevenge::RVNGInputStream *object);
108 void readPlaneStreamObject(librevenge::RVNGInputStream *object);
109 void readFontObject(librevenge::RVNGInputStream *object);
110 void readObjectInfoObject(librevenge::RVNGInputStream *object);
111 void readBookAtrObject(librevenge::RVNGInputStream *object);
112 void readSimpleTextObject(librevenge::RVNGInputStream *object);
113 void readTOCObject(librevenge::RVNGInputStream *object);
114
115 void readToCStream(librevenge::RVNGInputStream *input);
116
117 bool readAttribute(unsigned tag, librevenge::RVNGInputStream *input, LRFAttributes &attributes);
118
119 void skipUnhandledTag(unsigned tag, librevenge::RVNGInputStream *input, const char *objectType);
120
121 bool isObjectRead(unsigned id) const;
122
123 double toInches(unsigned px) const;
124
125 private:
126 LRFCollector m_collector;
127 librevenge::RVNGInputStream *m_input;
128 LRFHeader *m_header;
129 ObjectIndex_t m_objectIndex;
130 unsigned m_pageTree;
131 ToC_t m_toc;
132 };
133
134 } // namespace libebook
135
136 #endif // LRFPARSER_H_INCLUDED
137 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libebook::LRFParser::OBJECT_TYPE_TEXT
Definition: LRFParser.h:42
libebook::LRFAttributes
Definition: LRFTypes.h:108
libebook::LRFParser::LRFParser
LRFParser(const LRFParser &other)
libebook::LRFParser::readObject
void readObject(unsigned id, unsigned type=OBJECT_TYPE_UNSPECIFIED)
Definition: LRFParser.cpp:383
libebook::LRFParser::readPageObject
void readPageObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:553
libebook::LRFParser::OBJECT_TYPE_BLOCK_ATR
Definition: LRFParser.h:39
libebook::LRFParser::readObjectIndex
void readObjectIndex()
Definition: LRFParser.cpp:367
libebook::LRFParser::OBJECT_TYPE_PLANE_STREAM
Definition: LRFParser.h:53
libebook::LRFParser::OBJECT_TYPE_IMAGE
Definition: LRFParser.h:44
libebook::LRFParser::operator=
LRFParser & operator=(const LRFParser &other)
libebook::LRFParser::readThumbnail
void readThumbnail()
Definition: LRFParser.cpp:362
libebook::LRFParser::OBJECT_TYPE_TEXT_ATR
Definition: LRFParser.h:43
libebook::LRFParser::ObjectType
ObjectType
Definition: LRFParser.h:30
libebook::LRFParser::parse
bool parse()
Definition: LRFParser.cpp:283
libebook::LRFParser::readObjectInfoObject
void readObjectInfoObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1069
libebook::LRFParser::m_input
librevenge::RVNGInputStream * m_input
Definition: LRFParser.h:127
libebook::LRFParser::~LRFParser
~LRFParser()
Definition: LRFParser.cpp:278
libebook::LRFParser::OBJECT_TYPE_UNSPECIFIED
Definition: LRFParser.h:32
libebook::LRFParser::OBJECT_TYPE_POP_UP_WIN
Definition: LRFParser.h:51
libebook::LRFParser::readTextAtrObject
void readTextAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: LRFParser.cpp:894
libebook::LRFParser::readFooterObject
void readFooterObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:630
libebook::LRFParser::OBJECT_TYPE_TOC
Definition: LRFParser.h:58
libebook::LRFParser::OBJECT_TYPE_IMPORT
Definition: LRFParser.h:48
libebook::LRFParser::readHeader
void readHeader()
Definition: LRFParser.cpp:308
libebook::LRFParser::readAttribute
bool readAttribute(unsigned tag, librevenge::RVNGInputStream *input, LRFAttributes &attributes)
Definition: LRFParser.cpp:1189
type
EBOOKDocument::Type type
Definition: EBOOKDocument.cpp:328
libebook::LRFParser::ObjectIndex_t
std::map< unsigned, LRFIndexEntry > ObjectIndex_t
Definition: LRFParser.h:69
libebook::LRFParser::readBlockAtrObject
void readBlockAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: LRFParser.cpp:729
libebook::LRFCollector
Definition: LRFCollector.h:22
libebook::LRFParser::readBlockListObject
void readBlockListObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:750
libebook::LRFParser::OBJECT_TYPE_SOUND
Definition: LRFParser.h:52
libebook::LRFParser::readParagraphAtrObject
void readParagraphAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: LRFParser.cpp:950
libebook::LRFParser::OBJECT_TYPE_PARAGRAPH_ATR
Definition: LRFParser.h:46
libebook::LRFParser::readHeaderObject
void readHeaderObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:637
libebook::LRFParser::readButtonObject
void readButtonObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1027
libebook::LRFParser::OBJECT_TYPE_IMAGE_STREAM
Definition: LRFParser.h:47
libebook::LRFParser::OBJECT_TYPE_BUTTON
Definition: LRFParser.h:49
libebook::LRFParser::LRFIndexEntry::read
bool read
Definition: LRFParser.h:66
libebook::LRFParser::m_collector
LRFCollector m_collector
Definition: LRFParser.h:126
libebook::LRFParser::m_pageTree
unsigned m_pageTree
Definition: LRFParser.h:130
libebook::LRFParser::readTextObject
void readTextObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:757
libebook::LRFParser::OBJECT_TYPE_HEADER
Definition: LRFParser.h:35
libebook::LRFParser::readSimpleTextObject
void readSimpleTextObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1105
libebook::LRFParser::readSoundObject
void readSoundObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1048
libebook::LRFParser::OBJECT_TYPE_BLOCK
Definition: LRFParser.h:38
libebook::LRFParser::LRFIndexEntry::reading
bool reading
Definition: LRFParser.h:65
libebook::LRFParser::m_toc
ToC_t m_toc
Definition: LRFParser.h:131
libebook::LRFParser::readMetadata
void readMetadata()
Definition: LRFParser.cpp:349
libebook::LRFParser::OBJECT_TYPE_BOOK_ATR
Definition: LRFParser.h:56
libebook::LRFParser::OBJECT_TYPE_FONT
Definition: LRFParser.h:54
libebook::LRFParser::readCanvasObject
void readCanvasObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:943
libebook::LRFParser::readWindowObject
void readWindowObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1034
libebook::LRFParser::OBJECT_TYPE_WINDOW
Definition: LRFParser.h:50
libebook::LRFParser::m_objectIndex
ObjectIndex_t m_objectIndex
Definition: LRFParser.h:129
libebook::LRFParser::readMiniPageObject
void readMiniPageObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:743
libebook::LRFParser::LRFIndexEntry::size
unsigned size
Definition: LRFParser.h:64
libebook::LRFParser::OBJECT_TYPE_FOOTER
Definition: LRFParser.h:36
document
XMLTreeNodePtr_t document
Definition: EBOOKHTMLParser.cpp:169
libebook::LRFParser::readPopUpWinObject
void readPopUpWinObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1041
libebook::LRFParser::ToC_t
std::vector< unsigned > ToC_t
Definition: LRFParser.h:70
libebook::LRFParser::OBJECT_TYPE_PAGE_ATR
Definition: LRFParser.h:37
libebook::LRFParser::toInches
double toInches(unsigned px) const
libebook::LRFParser::OBJECT_TYPE_CANVAS
Definition: LRFParser.h:45
libebook::LRFParser::OBJECT_TYPE_MINI_PAGE
Definition: LRFParser.h:40
libebook::LRFParser::readPlaneStreamObject
void readPlaneStreamObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1055
libebook::LRFParser::OBJECT_TYPE_PAGE_TREE
Definition: LRFParser.h:33
libebook::EBOOKHTMLToken::input
Definition: EBOOKHTMLToken.h:91
libebook::LRFParser::readPageTreeObject
void readPageTreeObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:535
libebook::LRFParser::isObjectRead
bool isObjectRead(unsigned id) const
Definition: LRFParser.cpp:1597
libebook::LRFParser::OBJECT_TYPE_BLOCK_LIST
Definition: LRFParser.h:41
libebook::LRFParser::OBJECT_TYPE_SIMPLE_TEXT
Definition: LRFParser.h:57
libebook::LRFParser::isSupported
static bool isSupported(librevenge::RVNGInputStream *input)
Definition: LRFParser.cpp:300
libebook
Definition: CHMParser.cpp:20
libebook::LRFParser::readTOCObject
void readTOCObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1112
libebook::LRFParser::m_header
LRFHeader * m_header
Definition: LRFParser.h:128
libebook::LRFParser
Definition: LRFParser.h:24
libebook::LRFHeader
Definition: LRFParser.cpp:236
LRFCollector.h
libebook::LRFParser::skipUnhandledTag
void skipUnhandledTag(unsigned tag, librevenge::RVNGInputStream *input, const char *objectType)
Definition: LRFParser.cpp:1376
libebook::LRFParser::readPageAtrObject
void readPageAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: LRFParser.cpp:644
libebook::LRFParser::readBookAtrObject
void readBookAtrObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1076
libebook::LRFParser::readToCStream
void readToCStream(librevenge::RVNGInputStream *input)
Definition: LRFParser.cpp:1161
libebook::LRFParser::readImportObject
void readImportObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1020
libebook::LRFParser::readFontObject
void readFontObject(librevenge::RVNGInputStream *object)
Definition: LRFParser.cpp:1062
libebook::LRFParser::LRFIndexEntry::offset
unsigned offset
Definition: LRFParser.h:63
libebook::LRFParser::LRFIndexEntry
Definition: LRFParser.h:61
libebook::LRFParser::readImageObject
void readImageObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: LRFParser.cpp:908
libebook::LRFParser::OBJECT_TYPE_OBJECT_INFO
Definition: LRFParser.h:55
libebook::LRFParser::readImageStreamObject
void readImageStreamObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: LRFParser.cpp:964
libebook::LRFParser::OBJECT_TYPE_PAGE
Definition: LRFParser.h:34
libebook::LRFParser::readBlockObject
void readBlockObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: LRFParser.cpp:658