2024-11-07 03:53:04 +00:00
|
|
|
#pragma once
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2023-05-30 06:31:07 +00:00
|
|
|
#include "dict/dictionary.hh"
|
|
|
|
#include "ex.hh"
|
|
|
|
|
|
|
|
#include <QMap>
|
|
|
|
#include <QStack>
|
|
|
|
#include <QList>
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
#if defined( Q_OS_WIN32 ) || defined( Q_OS_MAC )
|
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <QString>
|
2024-11-14 04:36:37 +00:00
|
|
|
#include <QtCore5Compat/QTextCodec>
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2024-11-20 10:27:01 +00:00
|
|
|
// POSIX symbol unavailable on Windows needed for eb headers
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#ifndef _SSIZE_T
|
|
|
|
#define _SSIZE_T
|
|
|
|
#define ssize_t long
|
|
|
|
#endif
|
2016-04-07 21:45:27 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
#include <eb/eb.h>
|
|
|
|
|
|
|
|
namespace Epwing {
|
|
|
|
|
|
|
|
DEF_EX_STR( exEbLibrary, "EB library report error", Dictionary::Ex )
|
|
|
|
DEF_EX_STR( exEpwing, "Epwing parsing error:", Dictionary::Ex )
|
|
|
|
|
|
|
|
void initialize();
|
|
|
|
void finalize();
|
|
|
|
|
|
|
|
namespace Book {
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TextBufferSize = 4095,
|
|
|
|
BinaryBufferSize = 50000,
|
|
|
|
TextSizeLimit = 2800000
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EpwingHeadword
|
|
|
|
{
|
|
|
|
QString headword;
|
|
|
|
quint32 page;
|
|
|
|
quint32 offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EpwingBook
|
|
|
|
{
|
2014-05-21 19:10:24 +00:00
|
|
|
using EWPos = std::pair< int, int >;
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
void setErrorString( QString const & func, EB_Error_Code code );
|
|
|
|
|
|
|
|
EB_Book book;
|
|
|
|
EB_Appendix appendix;
|
2014-05-21 19:10:24 +00:00
|
|
|
EB_Hookset hookSet, refHookSet;
|
2014-05-20 13:59:56 +00:00
|
|
|
EB_Subbook_Code subBookList[ EB_MAX_SUBBOOKS ];
|
|
|
|
EB_Subbook_Code subAppendixList[ EB_MAX_SUBBOOKS ];
|
2014-05-21 19:10:24 +00:00
|
|
|
EB_Position currentPosition, indexHeadwordsPosition;
|
2014-05-20 13:59:56 +00:00
|
|
|
int subBookCount, subAppendixCount;
|
|
|
|
int currentSubBook;
|
|
|
|
QString error_string;
|
|
|
|
QString mainCacheDir, rootDir;
|
|
|
|
QString cacheImagesDir, cacheSoundsDir, cacheMoviesDir, cacheFontsDir;
|
|
|
|
QString dictID;
|
|
|
|
QTextCodec *codec_ISO, *codec_GB, *codec_Euc;
|
|
|
|
QStack< unsigned int > decorationStack;
|
|
|
|
int monoWidth, monoHeight;
|
|
|
|
QStringList imageCacheList, soundsCacheList, moviesCacheList, fontsCacheList;
|
2014-05-22 16:53:06 +00:00
|
|
|
QMap< QString, QString > baseFontsMap, customFontsMap;
|
2014-05-20 13:59:56 +00:00
|
|
|
QList< int > refPages, refOffsets;
|
2022-10-04 07:07:04 +00:00
|
|
|
QMap< uint64_t, bool > allHeadwordPositions;
|
|
|
|
QMap< uint64_t, bool > allRefPositions;
|
2014-05-22 16:53:06 +00:00
|
|
|
QList< EWPos > LinksQueue;
|
2014-05-20 13:59:56 +00:00
|
|
|
int refOpenCount, refCloseCount;
|
2023-05-29 13:56:04 +00:00
|
|
|
static QMutex libMutex;
|
2023-08-30 11:12:59 +00:00
|
|
|
QList< EpwingHeadword > candidateItems;
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
QString createCacheDir( QString const & dir );
|
|
|
|
|
|
|
|
// Close unslosed tags
|
|
|
|
void finalizeText( QString & text );
|
|
|
|
|
|
|
|
// Reset internal variables
|
|
|
|
void prepareToRead();
|
|
|
|
|
2014-05-21 19:10:24 +00:00
|
|
|
// Retrieve references from article
|
|
|
|
void getReferencesFromText( int page, int offset );
|
|
|
|
|
|
|
|
// Move to next article
|
|
|
|
EB_Error_Code forwardText( EB_Position & startPos );
|
|
|
|
|
|
|
|
// Retrieve article text from dictionary
|
2022-10-04 07:07:04 +00:00
|
|
|
QString getText( int page, int offset, bool text_only );
|
2023-03-12 07:04:49 +00:00
|
|
|
void seekBookThrow( int page, int offset );
|
|
|
|
QString getTextWithLength( int page, int offset, int total, EB_Position & pos );
|
|
|
|
QString getPreviousTextWithLength( int page, int offset, int total, EB_Position & pos );
|
2014-05-21 19:10:24 +00:00
|
|
|
|
|
|
|
unsigned int normalizeDecorationCode( unsigned int code );
|
|
|
|
|
2014-05-22 16:53:06 +00:00
|
|
|
QByteArray codeToUnicode( QString const & code );
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum DecorationCodes {
|
|
|
|
UNKNOWN = 0,
|
|
|
|
ITALIC = 1,
|
|
|
|
BOLD = 3,
|
|
|
|
EMPHASIS = 4,
|
|
|
|
SUBSCRIPT = 5,
|
|
|
|
SUPERSCRIPT = 6
|
|
|
|
};
|
|
|
|
|
|
|
|
EpwingBook();
|
|
|
|
~EpwingBook();
|
|
|
|
|
2023-05-29 13:56:04 +00:00
|
|
|
QMutex & getLibMutex()
|
|
|
|
{
|
|
|
|
return libMutex;
|
|
|
|
}
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
QString const & errorString() const
|
|
|
|
{
|
|
|
|
return error_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCodec * codecISO()
|
|
|
|
{
|
|
|
|
return codec_ISO;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCodec * codecGB()
|
|
|
|
{
|
|
|
|
return codec_GB;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTextCodec * codecEuc()
|
|
|
|
{
|
|
|
|
return codec_Euc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getSubBookCount()
|
|
|
|
{
|
|
|
|
return subBookCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDictID( const string & id )
|
|
|
|
{
|
|
|
|
dictID = QString::fromUtf8( id.c_str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString const & getImagesCacheDir()
|
|
|
|
{
|
|
|
|
return cacheImagesDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString const & getSoundsCacheDir()
|
|
|
|
{
|
|
|
|
return cacheSoundsDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString const & getMoviesCacheDir()
|
|
|
|
{
|
|
|
|
return cacheMoviesDir;
|
|
|
|
}
|
|
|
|
|
2014-05-21 19:10:24 +00:00
|
|
|
void clearBuffers()
|
|
|
|
{
|
|
|
|
allHeadwordPositions.clear();
|
2022-10-04 07:07:04 +00:00
|
|
|
allRefPositions.clear();
|
2014-05-22 16:53:06 +00:00
|
|
|
LinksQueue.clear();
|
2014-05-21 19:10:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
// Make name for resource
|
|
|
|
QString makeFName( QString const & ext, int page, int offset ) const;
|
2023-08-30 11:12:59 +00:00
|
|
|
QByteArray handleCandidate( EB_Hook_Code code, const unsigned * argv );
|
|
|
|
QString currentCandidate();
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
// Store all files in Epwing folder
|
|
|
|
static void collectFilenames( QString const & directory, vector< string > & files );
|
|
|
|
|
|
|
|
// Initialize dictionary book
|
|
|
|
int setBook( string const & directory );
|
|
|
|
|
|
|
|
// Set subbook inside dictionary
|
|
|
|
bool setSubBook( int book_nom );
|
|
|
|
|
|
|
|
void setCacheDirectory( QString const & cacheDir );
|
|
|
|
|
|
|
|
QString getCurrentSubBookDirectory();
|
|
|
|
|
|
|
|
QString copyright();
|
2023-08-30 11:12:59 +00:00
|
|
|
QList< EpwingHeadword > candidate( int page, int offset );
|
2014-05-20 13:59:56 +00:00
|
|
|
QString title();
|
|
|
|
|
|
|
|
// Seek to first article
|
2023-08-30 11:12:59 +00:00
|
|
|
bool getFirstHeadword( EpwingHeadword & head );
|
|
|
|
bool haveMenu();
|
|
|
|
bool getMenu( EpwingHeadword & head );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
// Find next headword and article position
|
|
|
|
bool getNextHeadword( EpwingHeadword & head );
|
|
|
|
|
2014-05-21 19:10:24 +00:00
|
|
|
bool readHeadword( EB_Position const & pos, QString & headword, bool text_only );
|
|
|
|
|
2014-05-21 14:18:37 +00:00
|
|
|
bool isHeadwordCorrect( QString const & headword );
|
|
|
|
|
|
|
|
void fixHeadword( QString & headword );
|
|
|
|
|
2014-05-20 13:59:56 +00:00
|
|
|
// Retrieve article from dictionary
|
|
|
|
void getArticle( QString & headword, QString & articleText, int page, int offset, bool text_only );
|
2023-03-12 07:04:49 +00:00
|
|
|
void readHeadword( QString & headword, bool text_only );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2023-03-12 07:04:49 +00:00
|
|
|
EB_Position getArticleNextPage( QString & headword, QString & articleText, int page, int offset, bool text_only );
|
|
|
|
EB_Position getArticlePreviousPage( QString & headword, QString & articleText, int page, int offset, bool text_only );
|
2014-05-20 13:59:56 +00:00
|
|
|
const char * beginDecoration( unsigned int code );
|
|
|
|
const char * endDecoration( unsigned int code );
|
|
|
|
|
|
|
|
QByteArray handleColorImage( EB_Hook_Code code, const unsigned int * argv );
|
|
|
|
|
|
|
|
QByteArray handleMonoImage( EB_Hook_Code code, const unsigned int * argv );
|
|
|
|
|
|
|
|
QByteArray handleWave( EB_Hook_Code code, const unsigned int * argv );
|
|
|
|
|
|
|
|
QByteArray handleMpeg( EB_Hook_Code code, const unsigned int * argv );
|
|
|
|
|
2014-05-22 16:53:06 +00:00
|
|
|
QByteArray handleNarrowFont( const unsigned int * argv, bool text_only );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
2014-05-22 16:53:06 +00:00
|
|
|
QByteArray handleWideFont( const unsigned int * argv, bool text_only );
|
2014-05-20 13:59:56 +00:00
|
|
|
|
|
|
|
QByteArray handleReference( EB_Hook_Code code, const unsigned int * argv );
|
2014-07-10 13:55:14 +00:00
|
|
|
|
|
|
|
bool getMatches( QString word, QList< QString > & matches );
|
|
|
|
|
2014-07-11 13:41:29 +00:00
|
|
|
bool getArticlePos( QString word, QList< int > & pages, QList< int > & offsets );
|
2023-08-27 10:30:55 +00:00
|
|
|
QString repairSubBookDirectory( QString subBookDir );
|
2014-05-20 13:59:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EContainer
|
|
|
|
{
|
|
|
|
EpwingBook * book;
|
|
|
|
bool textOnly;
|
|
|
|
|
|
|
|
EContainer( EpwingBook * book_ ):
|
|
|
|
book( book_ ),
|
|
|
|
textOnly( false )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EContainer( EpwingBook * book_, bool text_only ):
|
|
|
|
book( book_ ),
|
|
|
|
textOnly( text_only )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Book
|
|
|
|
|
|
|
|
} // namespace Epwing
|