From ca64365e3a7245f6ef0f8f6962db3c1b85421cef Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 12 Dec 2022 11:04:54 +0100 Subject: Don't hide object replacement char except in rich text The object replacement character (U+FFFC) is used to represent inline objects such as images in rich-text. To enable this, we have special handling of it in QTextEngine. For classes where inline images are not supported, it will just be hidden from the visual text, which is unexpected. Instead of always special-casing it, we make this dependent on whether the document layout has registered any object handlers. If they have not, then there will be no visual representation of the object, and it is better to show the glyph for it. For anything based on QTextDocument, there will always be the image handler, so U+FFFC will still have special handling there, but for non-rich labels and plain text editors the glyph will be shown instead. Note that there was also a bug in QLineEdit, where the object replacement character was always replaced by a space. This was introduced in 2007, in a patch which replaced a !ch.isPrint() with a check for "the most obvious non-printable characters" to reduce the number of characters that were not shown. However, U+FFFC is a printable character and would thus not have been filtered by the !isPrint() condition, so I think this was a mistake at the time. However, due to the special-casing of the character in Qt, it would not have had any effect until now. This also changes the QTextLayout::cursorToXForInlineObject() test to actually test proper inline objects, as this was previously using a hack which depended on the inline object code to be used even for plain QTextLayouts with no handlers for these. [ChangeLog][Text] The object replacement character (U+FFFC) is now only filtered out in rich text controls, where they represent inline objects. In other controls, its glyphs will be shown as with other text. Pick-to: 6.5 Fixes: QTBUG-101526 Change-Id: I7fcaf2b10918feb41589e1098016efbf79a0e62d Reviewed-by: Lars Knoll Reviewed-by: Qt CI Bot --- src/widgets/widgets/qwidgetlinecontrol.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 30465b95fa..ed7bc035ec 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -85,8 +85,7 @@ void QWidgetLineControl::updateDisplayText(bool forceUpdate) for (int i = 0; i < (int)str.size(); ++i) { if ((uc[i].unicode() < 0x20 && uc[i].unicode() != 0x09) || uc[i] == QChar::LineSeparator - || uc[i] == QChar::ParagraphSeparator - || uc[i] == QChar::ObjectReplacementCharacter) + || uc[i] == QChar::ParagraphSeparator) uc[i] = QChar(0x0020); } -- cgit v1.2.3