Parser EPUB in C++: ZIP minimale (STORE/DEFLATE via zlib), container/OPF/spine, TOC EPUB2+3, chiavi segno — testato su EPUB di esempio
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
#ifndef EPUB_H
|
||||
#define EPUB_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
struct EpubChapter
|
||||
{
|
||||
QString id;
|
||||
QString path; // path assoluto del file HTML estratto
|
||||
QString title;
|
||||
};
|
||||
|
||||
class EpubBook
|
||||
{
|
||||
public:
|
||||
EpubBook();
|
||||
~EpubBook();
|
||||
|
||||
bool open(const QString &epubPath);
|
||||
void close();
|
||||
|
||||
QString title() const { return m_title; }
|
||||
QString author() const { return m_author; }
|
||||
QList<EpubChapter> chapters() const { return m_chapters; }
|
||||
QString baseDir() const { return m_baseDir; }
|
||||
int chapterCount() const { return m_chapters.size(); }
|
||||
|
||||
QString chapterFilePath(int index) const;
|
||||
QString chapterTitle(int index) const;
|
||||
|
||||
// chiave segno locale, es. "cw:v1:3:0.42" (capitolo 3, 42% del capitolo)
|
||||
QString makeBookmarkKey(int chapterIndex, double fraction) const;
|
||||
bool parseBookmarkKey(const QString &key, int *chapterIndex, double *fraction) const;
|
||||
|
||||
private:
|
||||
bool extractZip(const QString &epubPath);
|
||||
bool parseContainer();
|
||||
bool parseOpf();
|
||||
void parseTocEpub3(const QString &navPath);
|
||||
void parseTocEpub2(const QString &ncxPath);
|
||||
QString absolutePath(const QString &relativeToOpfDir) const;
|
||||
|
||||
QString m_baseDir;
|
||||
QString m_opfDir;
|
||||
QString m_title;
|
||||
QString m_author;
|
||||
QList<EpubChapter> m_chapters;
|
||||
};
|
||||
|
||||
#endif // EPUB_H
|
||||
Reference in New Issue
Block a user