From 1cdc197664fa65dd0bef403d17368fa4ec281fda Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Sat, 6 May 2023 20:20:44 +0300 Subject: [PATCH] a11y atspi: Report correct char code point when it's > 65535 QString uses UTF-16 encoding and thus "unicode characters with code values above 65535 are stored using surrogate pairs, i.e., two consecutive QChars.". [1] When the character inside of text is retrieved using the GetCharacterAtOffset method of the AT-SPI Text interface, use QStringIterator to retrieve the character's actual codepoint instead of returning an invalid/incorrect one. [1] https://doc.qt.io/qt-6/qstring.html Fixes: QTBUG-113438 Change-Id: I07108481716329fd23a92c88892eaedd3f9defc6 Reviewed-by: Edward Welbourne (cherry picked from commit c7b925757f9b55924b788a2f08d777baa0e63250) Reviewed-by: Qt Cherry-pick Bot --- src/gui/accessible/linux/atspiadaptor.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/accessible/linux/atspiadaptor.cpp b/src/gui/accessible/linux/atspiadaptor.cpp index e6ada2c2403..4965cecdd20 100644 --- a/src/gui/accessible/linux/atspiadaptor.cpp +++ b/src/gui/accessible/linux/atspiadaptor.cpp @@ -16,6 +16,7 @@ #if QT_CONFIG(accessibility) #include "socket_interface.h" #include "qspi_constant_mappings_p.h" +#include #include #include "qspiapplicationadaptor_p.h" @@ -1980,8 +1981,13 @@ bool AtSpiAdaptor::textInterface(QAccessibleInterface *interface, const QString int offset = message.arguments().at(0).toInt(); int start; int end; - QString result = interface->textInterface()->textAtOffset(offset, QAccessible::CharBoundary, &start, &end); - sendReply(connection, message, (int) *(qPrintable (result))); + const QString charString = interface->textInterface() + ->textAtOffset(offset, QAccessible::CharBoundary, &start, &end); + int codePoint = 0; + QStringIterator stringIt(charString); + if (stringIt.hasNext()) + codePoint = static_cast(stringIt.peekNext()); + sendReply(connection, message, codePoint); } else if (function == "GetCharacterExtents"_L1) { int offset = message.arguments().at(0).toInt(); int coordType = message.arguments().at(1).toUInt();