gui: PreviewGeneratorPdf: Only highlight whole words

Only highlight whole words, which is less confusing
This commit is contained in:
Albert S. 2022-08-27 22:16:48 +02:00
rodič 11b070ed42
revize e6a0c0daee
1 změnil soubory, kde provedl 4 přidání a 1 odebrání

Zobrazit soubor

@ -1,5 +1,6 @@
#include <QMutexLocker>
#include <QPainter>
#include <QRegularExpression>
#include "previewgeneratorpdf.h"
static QMutex cacheMutex;
@ -17,6 +18,7 @@ Poppler::Document *PreviewGeneratorPdf::document(QString path)
return nullptr;
}
result->setRenderHint(Poppler::Document::TextAntialiasing);
QMutexLocker locker(&cacheMutex);
documentcache.insert(path, result);
locker.unlock();
@ -45,7 +47,8 @@ QSharedPointer<PreviewResult> PreviewGeneratorPdf::generate(RenderConfig config,
QImage img = pdfPage->renderToImage(config.scaleX, config.scaleY);
for(QString &word : config.wordsToHighlight)
{
QList<QRectF> rects = pdfPage->search(word, Poppler::Page::SearchFlag::IgnoreCase);
QList<QRectF> rects =
pdfPage->search(word, Poppler::Page::SearchFlag::IgnoreCase | Poppler::Page::SearchFlag::WholeWords);
for(QRectF &rect : rects)
{
QPainter painter(&img);