BBeBParser.h Source File documentation

BBeBParser.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 BBEBPARSER_H_INCLUDED
11 #define BBEBPARSER_H_INCLUDED
12
13 #include <vector>
14 #include <map>
15 #include <memory>
16
17 #include "BBeBCollector.h"
18
19
20 namespace libebook
21 {
22
23 struct BBeBHeader;
24
25 class BBeBParser
26 {
27 // disable copying
28 BBeBParser(const BBeBParser &other);
29 BBeBParser &operator=(const BBeBParser &other);
30
31 enum ObjectType
32 {
33 OBJECT_TYPE_UNSPECIFIED = 0x0,
34 OBJECT_TYPE_PAGE_TREE = 0x1,
35 OBJECT_TYPE_PAGE = 0x2,
36 OBJECT_TYPE_HEADER = 0x3,
37 OBJECT_TYPE_FOOTER = 0x4,
38 OBJECT_TYPE_PAGE_ATR = 0x5,
39 OBJECT_TYPE_BLOCK = 0x6,
40 OBJECT_TYPE_BLOCK_ATR = 0x7,
41 OBJECT_TYPE_MINI_PAGE = 0x8,
42 OBJECT_TYPE_BLOCK_LIST = 0x9,
43 OBJECT_TYPE_TEXT = 0xa,
44 OBJECT_TYPE_TEXT_ATR = 0xb,
45 OBJECT_TYPE_IMAGE = 0xc,
46 OBJECT_TYPE_CANVAS = 0xd,
47 OBJECT_TYPE_PARAGRAPH_ATR = 0xe,
48 OBJECT_TYPE_IMAGE_STREAM = 0x11,
49 OBJECT_TYPE_SoftBookORT = 0x12,
50 OBJECT_TYPE_BUTTON = 0x13,
51 OBJECT_TYPE_WINDOW = 0x14,
52 OBJECT_TYPE_POP_UP_WIN = 0x15,
53 OBJECT_TYPE_SOUND = 0x16,
54 OBJECT_TYPE_PLANE_STREAM = 0x17,
55 OBJECT_TYPE_FONT = 0x19,
56 OBJECT_TYPE_OBJECT_INFO = 0x1a,
57 OBJECT_TYPE_BOOK_ATR = 0x1c,
58 OBJECT_TYPE_SSoftBookLE_TEXT = 0x1d,
59 OBJECT_TYPE_TOC = 0x1e
60 };
61
62 struct BBeBIndexEntry
63 {
64 unsigned offset;
65 unsigned size;
66 bool reading;
67 bool read;
68 };
69
70 typedef std::map<unsigned, BBeBIndexEntry> ObjectIndex_t;
71 typedef std::vector<unsigned> ToC_t;
72
73 public:
74 BBeBParser(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document);
75 ~BBeBParser();
76
77 bool parse();
78
79 static bool isSupported(librevenge::RVNGInputStream *input);
80
81 private:
82 void readHeader();
83 void readMetadata();
84 void readThumbnail();
85 void readObjectIndex();
86
87 void readObject(unsigned id, unsigned type = OBJECT_TYPE_UNSPECIFIED);
88
89 void readPageTreeObject(librevenge::RVNGInputStream *object);
90 void readPageObject(librevenge::RVNGInputStream *object);
91 void readFooterObject(librevenge::RVNGInputStream *object);
92 void readHeaderObject(librevenge::RVNGInputStream *object);
93 void readPageAtrObject(librevenge::RVNGInputStream *object, unsigned id);
94 void readBlockObject(librevenge::RVNGInputStream *object, unsigned id);
95 void readBlockAtrObject(librevenge::RVNGInputStream *object, unsigned id);
96 void readMiniPageObject(librevenge::RVNGInputStream *object);
97 void readBlockListObject(librevenge::RVNGInputStream *object);
98 void readTextObject(librevenge::RVNGInputStream *object);
99 void readTextAtrObject(librevenge::RVNGInputStream *object, unsigned id);
100 void readImageObject(librevenge::RVNGInputStream *object, unsigned id);
101 void readCanvasObject(librevenge::RVNGInputStream *object);
102 void readParagraphAtrObject(librevenge::RVNGInputStream *object, unsigned id);
103 void readImageStreamObject(librevenge::RVNGInputStream *object, unsigned id);
104 void readImportObject(librevenge::RVNGInputStream *object);
105 void readButtonObject(librevenge::RVNGInputStream *object);
106 void readWindowObject(librevenge::RVNGInputStream *object);
107 void readPopUpWinObject(librevenge::RVNGInputStream *object);
108 void readSoundObject(librevenge::RVNGInputStream *object);
109 void readPlaneStreamObject(librevenge::RVNGInputStream *object);
110 void readFontObject(librevenge::RVNGInputStream *object);
111 void readObjectInfoObject(librevenge::RVNGInputStream *object);
112 void readBookAtrObject(librevenge::RVNGInputStream *object);
113 void readSimpleTextObject(librevenge::RVNGInputStream *object);
114 void readTOCObject(librevenge::RVNGInputStream *object);
115
116 void readToCStream(librevenge::RVNGInputStream *input);
117
118 bool readAttribute(unsigned tag, librevenge::RVNGInputStream *input, BBeBAttributes &attributes);
119
120 void skipUnhandledTag(unsigned tag, librevenge::RVNGInputStream *input, const char *objectType);
121
122 bool isObjectRead(unsigned id) const;
123
124 double toInches(unsigned px) const;
125
126 private:
127 BBeBCollector m_collector;
128 librevenge::RVNGInputStream *m_input;
129 std::unique_ptr<BBeBHeader> m_header;
130 ObjectIndex_t m_objectIndex;
131 unsigned m_pageTree;
132 ToC_t m_toc;
133 };
134
135 } // namespace libebook
136
137 #endif // BBEBPARSER_H_INCLUDED
138 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
BBeBCollector.h
type
EBOOKDocument::Type type
Definition: EBOOKDocument.cpp:325
document
XMLTreeNodePtr_t document
Definition: EBOOKHTMLParser.cpp:163
tag
qi::rule< Iterator, std::pair< int, Attributes_t >, qi::space_type > tag
Definition: TealDocParser.cpp:229
libebook::BBeBCollector
Definition: BBeBCollector.h:23
libebook::BBeBParser
Definition: BBeBParser.h:26
libebook::BBeBParser::readSimpleTextObject
void readSimpleTextObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1119
libebook::BBeBParser::readMiniPageObject
void readMiniPageObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:749
libebook::BBeBParser::readImportObject
void readImportObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1034
libebook::BBeBParser::readObjectInfoObject
void readObjectInfoObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1083
libebook::BBeBParser::m_pageTree
unsigned m_pageTree
Definition: BBeBParser.h:131
libebook::BBeBParser::skipUnhandledTag
void skipUnhandledTag(unsigned tag, librevenge::RVNGInputStream *input, const char *objectType)
Definition: BBeBParser.cpp:1392
libebook::BBeBParser::readToCStream
void readToCStream(librevenge::RVNGInputStream *input)
Definition: BBeBParser.cpp:1175
libebook::BBeBParser::ObjectType
ObjectType
Definition: BBeBParser.h:32
libebook::BBeBParser::OBJECT_TYPE_PAGE_ATR
@ OBJECT_TYPE_PAGE_ATR
Definition: BBeBParser.h:38
libebook::BBeBParser::OBJECT_TYPE_MINI_PAGE
@ OBJECT_TYPE_MINI_PAGE
Definition: BBeBParser.h:41
libebook::BBeBParser::OBJECT_TYPE_SOUND
@ OBJECT_TYPE_SOUND
Definition: BBeBParser.h:53
libebook::BBeBParser::OBJECT_TYPE_PAGE_TREE
@ OBJECT_TYPE_PAGE_TREE
Definition: BBeBParser.h:34
libebook::BBeBParser::OBJECT_TYPE_CANVAS
@ OBJECT_TYPE_CANVAS
Definition: BBeBParser.h:46
libebook::BBeBParser::OBJECT_TYPE_SSoftBookLE_TEXT
@ OBJECT_TYPE_SSoftBookLE_TEXT
Definition: BBeBParser.h:58
libebook::BBeBParser::OBJECT_TYPE_OBJECT_INFO
@ OBJECT_TYPE_OBJECT_INFO
Definition: BBeBParser.h:56
libebook::BBeBParser::OBJECT_TYPE_TEXT_ATR
@ OBJECT_TYPE_TEXT_ATR
Definition: BBeBParser.h:44
libebook::BBeBParser::OBJECT_TYPE_PARAGRAPH_ATR
@ OBJECT_TYPE_PARAGRAPH_ATR
Definition: BBeBParser.h:47
libebook::BBeBParser::OBJECT_TYPE_IMAGE_STREAM
@ OBJECT_TYPE_IMAGE_STREAM
Definition: BBeBParser.h:48
libebook::BBeBParser::OBJECT_TYPE_BUTTON
@ OBJECT_TYPE_BUTTON
Definition: BBeBParser.h:50
libebook::BBeBParser::OBJECT_TYPE_IMAGE
@ OBJECT_TYPE_IMAGE
Definition: BBeBParser.h:45
libebook::BBeBParser::OBJECT_TYPE_WINDOW
@ OBJECT_TYPE_WINDOW
Definition: BBeBParser.h:51
libebook::BBeBParser::OBJECT_TYPE_FONT
@ OBJECT_TYPE_FONT
Definition: BBeBParser.h:55
libebook::BBeBParser::OBJECT_TYPE_SoftBookORT
@ OBJECT_TYPE_SoftBookORT
Definition: BBeBParser.h:49
libebook::BBeBParser::OBJECT_TYPE_TOC
@ OBJECT_TYPE_TOC
Definition: BBeBParser.h:59
libebook::BBeBParser::OBJECT_TYPE_TEXT
@ OBJECT_TYPE_TEXT
Definition: BBeBParser.h:43
libebook::BBeBParser::OBJECT_TYPE_BLOCK_ATR
@ OBJECT_TYPE_BLOCK_ATR
Definition: BBeBParser.h:40
libebook::BBeBParser::OBJECT_TYPE_PLANE_STREAM
@ OBJECT_TYPE_PLANE_STREAM
Definition: BBeBParser.h:54
libebook::BBeBParser::OBJECT_TYPE_POP_UP_WIN
@ OBJECT_TYPE_POP_UP_WIN
Definition: BBeBParser.h:52
libebook::BBeBParser::OBJECT_TYPE_FOOTER
@ OBJECT_TYPE_FOOTER
Definition: BBeBParser.h:37
libebook::BBeBParser::OBJECT_TYPE_HEADER
@ OBJECT_TYPE_HEADER
Definition: BBeBParser.h:36
libebook::BBeBParser::OBJECT_TYPE_BLOCK
@ OBJECT_TYPE_BLOCK
Definition: BBeBParser.h:39
libebook::BBeBParser::OBJECT_TYPE_BLOCK_LIST
@ OBJECT_TYPE_BLOCK_LIST
Definition: BBeBParser.h:42
libebook::BBeBParser::OBJECT_TYPE_UNSPECIFIED
@ OBJECT_TYPE_UNSPECIFIED
Definition: BBeBParser.h:33
libebook::BBeBParser::OBJECT_TYPE_PAGE
@ OBJECT_TYPE_PAGE
Definition: BBeBParser.h:35
libebook::BBeBParser::OBJECT_TYPE_BOOK_ATR
@ OBJECT_TYPE_BOOK_ATR
Definition: BBeBParser.h:57
libebook::BBeBParser::readCanvasObject
void readCanvasObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:955
libebook::BBeBParser::readWindowObject
void readWindowObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1048
libebook::BBeBParser::readBlockObject
void readBlockObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: BBeBParser.cpp:659
libebook::BBeBParser::m_input
librevenge::RVNGInputStream * m_input
Definition: BBeBParser.h:128
libebook::BBeBParser::parse
bool parse()
Definition: BBeBParser.cpp:282
libebook::BBeBParser::readBlockAtrObject
void readBlockAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: BBeBParser.cpp:735
libebook::BBeBParser::ToC_t
std::vector< unsigned > ToC_t
Definition: BBeBParser.h:71
libebook::BBeBParser::readButtonObject
void readButtonObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1041
libebook::BBeBParser::readObject
void readObject(unsigned id, unsigned type=OBJECT_TYPE_UNSPECIFIED)
Definition: BBeBParser.cpp:382
libebook::BBeBParser::readPageObject
void readPageObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:553
libebook::BBeBParser::readParagraphAtrObject
void readParagraphAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: BBeBParser.cpp:962
libebook::BBeBParser::operator=
BBeBParser & operator=(const BBeBParser &other)
libebook::BBeBParser::readHeader
void readHeader()
Definition: BBeBParser.cpp:307
libebook::BBeBParser::readTextObject
void readTextObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:763
libebook::BBeBParser::readPlaneStreamObject
void readPlaneStreamObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1069
libebook::BBeBParser::readTextAtrObject
void readTextAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: BBeBParser.cpp:906
libebook::BBeBParser::m_objectIndex
ObjectIndex_t m_objectIndex
Definition: BBeBParser.h:130
libebook::BBeBParser::toInches
double toInches(unsigned px) const
libebook::BBeBParser::readImageStreamObject
void readImageStreamObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: BBeBParser.cpp:976
libebook::BBeBParser::~BBeBParser
~BBeBParser()
Definition: BBeBParser.cpp:278
libebook::BBeBParser::readThumbnail
void readThumbnail()
Definition: BBeBParser.cpp:361
libebook::BBeBParser::m_collector
BBeBCollector m_collector
Definition: BBeBParser.h:127
libebook::BBeBParser::readAttribute
bool readAttribute(unsigned tag, librevenge::RVNGInputStream *input, BBeBAttributes &attributes)
Definition: BBeBParser.cpp:1205
libebook::BBeBParser::readFontObject
void readFontObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1076
libebook::BBeBParser::m_toc
ToC_t m_toc
Definition: BBeBParser.h:132
libebook::BBeBParser::readBookAtrObject
void readBookAtrObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1090
libebook::BBeBParser::isObjectRead
bool isObjectRead(unsigned id) const
Definition: BBeBParser.cpp:1613
libebook::BBeBParser::readImageObject
void readImageObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: BBeBParser.cpp:920
libebook::BBeBParser::readTOCObject
void readTOCObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1126
libebook::BBeBParser::readPopUpWinObject
void readPopUpWinObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1055
libebook::BBeBParser::readFooterObject
void readFooterObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:631
libebook::BBeBParser::readBlockListObject
void readBlockListObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:756
libebook::BBeBParser::BBeBParser
BBeBParser(const BBeBParser &other)
libebook::BBeBParser::readSoundObject
void readSoundObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:1062
libebook::BBeBParser::m_header
std::unique_ptr< BBeBHeader > m_header
Definition: BBeBParser.h:129
libebook::BBeBParser::readMetadata
void readMetadata()
Definition: BBeBParser.cpp:348
libebook::BBeBParser::readHeaderObject
void readHeaderObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:638
libebook::BBeBParser::readObjectIndex
void readObjectIndex()
Definition: BBeBParser.cpp:366
libebook::BBeBParser::isSupported
static bool isSupported(librevenge::RVNGInputStream *input)
Definition: BBeBParser.cpp:299
libebook::BBeBParser::readPageAtrObject
void readPageAtrObject(librevenge::RVNGInputStream *object, unsigned id)
Definition: BBeBParser.cpp:645
libebook::BBeBParser::ObjectIndex_t
std::map< unsigned, BBeBIndexEntry > ObjectIndex_t
Definition: BBeBParser.h:70
libebook::BBeBParser::readPageTreeObject
void readPageTreeObject(librevenge::RVNGInputStream *object)
Definition: BBeBParser.cpp:533
libebook::EBOOKHTMLToken::input
@ input
Definition: EBOOKHTMLToken.h:89
libebook
Definition: BBeBCollector.cpp:19
libebook::BBeBAttributes
Definition: BBeBTypes.h:109
libebook::BBeBParser::BBeBIndexEntry
Definition: BBeBParser.h:63
libebook::BBeBParser::BBeBIndexEntry::read
bool read
Definition: BBeBParser.h:67
libebook::BBeBParser::BBeBIndexEntry::reading
bool reading
Definition: BBeBParser.h:66
libebook::BBeBParser::BBeBIndexEntry::size
unsigned size
Definition: BBeBParser.h:65
libebook::BBeBParser::BBeBIndexEntry::offset
unsigned offset
Definition: BBeBParser.h:64