From d112682611cd38fe7f28943f688648b5862c7582 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 13 Dec 2020 00:16:46 +0100 Subject: [PATCH] =?UTF-8?q?Make=20search=20work=20on=20documents=20that=20?= =?UTF-8?q?describe=20A=CC=8A=20as=20A=20+=20=E2=97=8C=CC=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUGS: 430243 --- autotests/searchtest.cpp | 23 +++++++++++++++++++++++ core/textpage.cpp | 17 ++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/autotests/searchtest.cpp b/autotests/searchtest.cpp index 7baf55269..333f42ddd 100644 --- a/autotests/searchtest.cpp +++ b/autotests/searchtest.cpp @@ -44,6 +44,7 @@ private slots: void test311232(); void test323262(); void test323263(); + void test430243(); void testDottedI(); void testHyphenAtEndOfLineWithoutYOverlap(); void testHyphenWithYOverlap(); @@ -222,6 +223,28 @@ void SearchTest::test323263() delete page; } +void SearchTest::test430243() +{ + // 778 is COMBINING RING ABOVE + // 197 is LATIN CAPITAL LETTER A WITH RING ABOVE + QVector text; + text << QStringLiteral("A") << QString(QChar(778)); + + QVector rect; + rect << Okular::NormalizedRect(0, 0, 1, 1) << Okular::NormalizedRect(1, 0, 2, 1); + + CREATE_PAGE; + + Okular::RegularAreaRect *result = tp->findText(0, QString(QChar(197)), Okular::FromTop, Qt::CaseSensitive, nullptr); + QVERIFY(result); + Okular::RegularAreaRect expected; + expected.append(rect[0] | rect[1]); + QCOMPARE(*result, expected); + delete result; + + delete page; +} + void SearchTest::testDottedI() { // Earlier versions of okular had the bug that the letter "İ" (capital dotter i) did not match itself diff --git a/core/textpage.cpp b/core/textpage.cpp index 79e60aee9..2d6506a12 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -245,8 +245,23 @@ TextPage::~TextPage() void TextPage::append(const QString &text, NormalizedRect *area) { - if (!text.isEmpty()) + if (!text.isEmpty()) { + if (!d->m_words.isEmpty()) { + TinyTextEntity *lastEntity = d->m_words.last(); + const QString concatText = lastEntity->text() + text.normalized(QString::NormalizationForm_KC); + if (concatText != concatText.normalized(QString::NormalizationForm_KC)) { + // If this happens it means that the new text + old one have combined, for example A and ◌̊ form Å + NormalizedRect newArea = *area | lastEntity->area; + delete area; + delete lastEntity; + d->m_words.removeLast(); + d->m_words.append(new TinyTextEntity(concatText.normalized(QString::NormalizationForm_KC), newArea)); + return; + } + } + d->m_words.append(new TinyTextEntity(text.normalized(QString::NormalizationForm_KC), *area)); + } delete area; }