From 73d3d43c332a44b87b26ee5cebe98b6829ea3be7 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Mon, 12 Sep 2022 14:10:25 +0800 Subject: [PATCH] fix: hunspell on the epwing dictionary does not work fix goldendict/goldendict#1551 --- epwing.cc | 90 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 38 deletions(-) diff --git a/epwing.cc b/epwing.cc index bdb1d28b..2483a9b9 100644 --- a/epwing.cc +++ b/epwing.cc @@ -478,6 +478,10 @@ public: void run(); // Run from another thread by EpwingArticleRequestRunnable + void getBuiltInArticle(wstring const & word_, QVector< int > & pages, + QVector< int > & offsets, + multimap< wstring, pair< string, string > > & mainArticles ); + virtual void cancel() { isCancelled.ref(); @@ -509,7 +513,6 @@ void EpwingArticleRequest::run() for( unsigned x = 0; x < alts.size(); ++x ) { /// Make an additional query for each alt - vector< WordArticleLink > altChain = dict.findArticles( alts[ x ], ignoreDiacritics ); chain.insert( chain.end(), altChain.begin(), altChain.end() ); @@ -577,44 +580,10 @@ void EpwingArticleRequest::run() } // Also try to find word in the built-in dictionary index - try - { - string headword, articleText; - - QVector< int > pg, off; - { - Mutex::Lock _( dict.eBook.getLibMutex() ); - dict.eBook.getArticlePos( gd::toQString( word ), pg, off ); - } - - for( int i = 0; i < pg.size(); i++ ) - { - bool already = false; - for( int n = 0; n < pages.size(); n++ ) - { - if( pages.at( n ) == pg.at( i ) - && abs( offsets.at( n ) - off.at( i ) ) <= 4 ) - { - already = true; - break; - } - } - - if( !already ) - { - dict.loadArticle( pg.at( i ), off.at( i ), headword, articleText ); - - mainArticles.insert( pair< wstring, pair< string, string > >( - Folding::applySimpleCaseOnly( Utf8::decode( headword ) ), - pair< string, string >( headword, articleText ) ) ); - - pages.append( pg.at( i ) ); - offsets.append( off.at( i ) ); - } - } - } - catch(...) + getBuiltInArticle(word, pages, offsets, mainArticles ); + for( unsigned x = 0; x < alts.size(); ++x ) { + getBuiltInArticle( alts[ x ], pages, offsets, alternateArticles ); } if ( mainArticles.empty() && alternateArticles.empty() ) @@ -657,6 +626,51 @@ void EpwingArticleRequest::run() finish(); } +void EpwingArticleRequest::getBuiltInArticle( wstring const & word_, + QVector< int > & pages, + QVector< int > & offsets, + multimap< wstring, pair< string, string > > & mainArticles ) +{ + try + { + string headword, articleText; + + QVector< int > pg, off; + { + Mutex::Lock _( dict.eBook.getLibMutex() ); + dict.eBook.getArticlePos( gd::toQString( word_ ), pg, off ); + } + + for( int i = 0; i < pg.size(); i++ ) + { + bool already = false; + for( int n = 0; n < pages.size(); n++ ) + { + if( pages.at( n ) == pg.at( i ) && abs( offsets.at( n ) - off.at( i ) ) <= 4 ) + { + already = true; + break; + } + } + + if( !already ) + { + dict.loadArticle( pg.at( i ), off.at( i ), headword, articleText ); + + mainArticles.insert( + pair< wstring, pair< string, string > >( Folding::applySimpleCaseOnly( Utf8::decode( headword ) ), + pair< string, string >( headword, articleText ) ) ); + + pages.append( pg.at( i ) ); + offsets.append( off.at( i ) ); + } + } + } + catch( ... ) + { + } +} + sptr< Dictionary::DataRequest > EpwingDictionary::getArticle( wstring const & word, vector< wstring > const & alts, wstring const &,