From 7b434cffaf5faee619520ccc803c6b8c2c33fa25 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Mon, 23 May 2022 20:42:37 +0800 Subject: [PATCH 1/8] fix:epwing code format --- epwing_book.cc | 4 ++-- epwing_book.hh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/epwing_book.cc b/epwing_book.cc index 111f031a..7f8b2704 100644 --- a/epwing_book.cc +++ b/epwing_book.cc @@ -899,7 +899,7 @@ bool EpwingBook::getNextHeadword( EpwingHeadword & head ) } else { - allHeadwordPositions[ head.headword ]< baseFontsMap, customFontsMap; QVector< int > refPages, refOffsets; - QMap< QString, QList > allHeadwordPositions; + QMap< QString, QList< EWPos > > allHeadwordPositions; QVector< EWPos > LinksQueue; int refOpenCount, refCloseCount; static Mutex libMutex; From 9f5788ee1180439730c4b7f5f78ac7c919cd9741 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Mon, 23 May 2022 12:06:28 +0300 Subject: [PATCH 2/8] Remove unused declaration showFindButtons() c2cdf9b177b4995fa069820a512668befb3135fa declared this member function but it was never defined. --- articleview.hh | 1 - 1 file changed, 1 deletion(-) diff --git a/articleview.hh b/articleview.hh index 2c274e7e..8a38d00d 100644 --- a/articleview.hh +++ b/articleview.hh @@ -62,7 +62,6 @@ class ArticleView: public QFrame void highlightFTSResults(); void performFtsFindOperation( bool backwards ); - void showFindButtons(); public: /// The popupView flag influences contents of the context menus to be From bd5b36cac79637b849b4bc665a54e99b9b0706a2 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sun, 22 May 2022 22:12:30 +0300 Subject: [PATCH 3/8] Extract ArticleView::highlightAllFtsOccurences() Extracting this function allows to simplify the code and facilitates optimizing it in the next commit. Remove `#if QT_VERSION >= 0x040600` along the way as GoldenDict does not support Qt versions older than 4.6 for several years now. --- articleview.cc | 17 ++++++++--------- articleview.hh | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/articleview.cc b/articleview.cc index ac2bdf6e..2e01b7f0 100644 --- a/articleview.cc +++ b/articleview.cc @@ -2643,17 +2643,9 @@ void ArticleView::highlightFTSResults() if( ftsSearchMatchCase ) flags |= QWebPage::FindCaseSensitively; -#if QT_VERSION >= 0x040600 - flags |= QWebPage::HighlightAllOccurrences; - - for( int x = 0; x < allMatches.size(); x++ ) - ui.definition->findText( allMatches.at( x ), flags ); - - flags &= ~QWebPage::HighlightAllOccurrences; -#endif - if( !allMatches.isEmpty() ) { + highlightAllFtsOccurences( flags ); if( ui.definition->findText( allMatches.at( 0 ), flags ) ) { ui.definition->page()->currentFrame()-> @@ -2669,6 +2661,13 @@ void ArticleView::highlightFTSResults() ftsSearchIsOpened = true; } +void ArticleView::highlightAllFtsOccurences( QWebPage::FindFlags flags ) +{ + flags |= QWebPage::HighlightAllOccurrences; + for( int x = 0; x < allMatches.size(); x++ ) + ui.definition->findText( allMatches.at( x ), flags ); +} + void ArticleView::performFtsFindOperation( bool backwards ) { if( !ftsSearchIsOpened ) diff --git a/articleview.hh b/articleview.hh index 8a38d00d..ebc9dbaf 100644 --- a/articleview.hh +++ b/articleview.hh @@ -61,6 +61,7 @@ class ArticleView: public QFrame int ftsPosition; void highlightFTSResults(); + void highlightAllFtsOccurences( QWebPage::FindFlags flags ); void performFtsFindOperation( bool backwards ); public: From b87b023db0a7fcd2fdc92916dd572afe8926040c Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sun, 22 May 2022 22:21:00 +0300 Subject: [PATCH 4/8] Optimize highlighting FTS matches in articles The wall time of calls to ArticleView::highlightAllFtsOccurences() on my GNU/Linux system before and at this commit: allMatches.size() uniqueMatches.size() before(ms) at(ms) 79 1 277 4 98 1 380 4 267 1 16803 65 --- articleview.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/articleview.cc b/articleview.cc index 2e01b7f0..8de8efff 100644 --- a/articleview.cc +++ b/articleview.cc @@ -2664,8 +2664,22 @@ void ArticleView::highlightFTSResults() void ArticleView::highlightAllFtsOccurences( QWebPage::FindFlags flags ) { flags |= QWebPage::HighlightAllOccurrences; - for( int x = 0; x < allMatches.size(); x++ ) - ui.definition->findText( allMatches.at( x ), flags ); + + // Usually allMatches contains mostly duplicates. Thus searching for each element of + // allMatches to highlight them takes a long time => collect unique elements into a + // set and search for them instead. + // Don't use QList::toSet() or QSet's range constructor because they reserve space + // for QList::size() elements, whereas the final QSet size is likely 1 or 2. + QSet< QString > uniqueMatches; + for( int x = 0; x < allMatches.size(); ++x ) + { + QString const & match = allMatches.at( x ); + // Consider words that differ only in case equal if the search is case-insensitive. + uniqueMatches.insert( ftsSearchMatchCase ? match : match.toLower() ); + } + + for( QSet< QString >::const_iterator it = uniqueMatches.constBegin(); it != uniqueMatches.constEnd(); ++it ) + ui.definition->findText( *it, flags ); } void ArticleView::performFtsFindOperation( bool backwards ) From de11e573d3bcc1d5cbb5d31bc21431a9b6c27016 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Mon, 23 May 2022 23:38:04 +0800 Subject: [PATCH 5/8] fix:quit application failed when the inspector windows is show --- mainwindow.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mainwindow.cc b/mainwindow.cc index 28ad0dc8..8f5df588 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1244,6 +1244,10 @@ void MainWindow::closeEvent( QCloseEvent * ev ) void MainWindow::quitApp() { + if( inspector && inspector->isVisible() ) + { + inspector->hide(); + } commitData(); qApp->quit(); } From bb9811bdf454d13f7bee9d98a76cbebee5f22afb Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Mon, 23 May 2022 23:42:52 +0800 Subject: [PATCH 6/8] clean code: remove unused line --- article_netmgr.cc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/article_netmgr.cc b/article_netmgr.cc index e63ebfff..db2aa0e9 100644 --- a/article_netmgr.cc +++ b/article_netmgr.cc @@ -131,22 +131,11 @@ using std::string; emit errorOccurred( code ); } -// void AllowFrameReply::readDataFromBase() -// { -//// QByteArray data; -//// data.resize( baseReply->bytesAvailable() ); -//// baseReply->read( data.data(), data.size() ); -//// buffer += data; -// emit readyRead(); -// } - qint64 AllowFrameReply::readData( char * data, qint64 maxSize ) { auto bytesAvailable= baseReply->bytesAvailable(); qint64 size = qMin( maxSize, bytesAvailable ); baseReply->read( data, size ); -// memcpy( data, buffer.data(), size ); -// buffer.remove( 0, size ); return size; } From f07ba75a5cdf6b1307491035d684bc13d31b437f Mon Sep 17 00:00:00 2001 From: Abs62 Date: Mon, 23 May 2022 20:43:58 +0300 Subject: [PATCH 7/8] Epwing: Fix full-text search for some CJK dictionaries (issue #1490) --- epwing_book.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/epwing_book.cc b/epwing_book.cc index 28d8eadc..50e6b4b3 100644 --- a/epwing_book.cc +++ b/epwing_book.cc @@ -1099,6 +1099,9 @@ void EpwingBook::getArticle( QString & headword, QString & articleText, headword = QString::fromUtf8( buffer, length ); finalizeText( headword ); + if( text_only ) + fixHeadword( headword ); + articleText = getText( pos.page, pos.offset, text_only ); } From 19a09b5f1b3c12cf5f34f02651b232140d50ff6b Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Tue, 24 May 2022 21:03:25 +0800 Subject: [PATCH 8/8] fix:remove epwing headword size limitation --- epwing.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/epwing.cc b/epwing.cc index 9d67cd2d..cd5eec5c 100644 --- a/epwing.cc +++ b/epwing.cc @@ -1054,8 +1054,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( for( ; ; ) { - //skip too long headword - if( !head.headword.isEmpty() && head.headword.size() < 30 ) + if( !head.headword.isEmpty() ) { uint32_t offset = chunks.startNewBlock(); chunks.addToBlock( &head.page, sizeof( head.page ) );