[Interest] Make a specific Unicode glyph wider in a QTextLayout
Eskil Abrahamsen Blomfeldt
Eskil.Abrahamsen-Blomfeldt at qt.io
Mon Dec 16 12:03:48 CET 2024
Hi!
For certain things, such as spaces and line/paragraph separators etc. we do support this: https://doc.qt.io/qt-6/qtextoption.html#Flag-enum
There's no way to customize how those look, though, except through the font.
For more detailed control, you could get the glyph runs from the layout with QTextLayout::glyphRuns() and then iterate over this, replacing the glyphs manually for these control characters but retaining the positions.
But for things like the zero-width space, there will not be space in the layout for any other glyph, so you might want to replace that with a normal space first. In practice, there will probably be a handful of zero-width characters you need to handle especially in advance.
Eskil Abrahamsen Blomfeldt
Senior Manager, Graphics Engines
The Qt Company
Sandakerveien 116
0484 Oslo, Norway
eskil.abrahamsen-blomfeldt at qt.io
http://qt.io
________________________________
From: Interest <interest-bounces at qt-project.org> on behalf of Wang Gary <wzc782970009 at gmail.com>
Sent: Sunday, December 15, 2024 8:23 AM
To: interest at qt-project.org <interest at qt-project.org>
Subject: [Interest] Make a specific Unicode glyph wider in a QTextLayout
Hi,
I'm attempting to implement a feature in a plain text editor that similar to Notepad++'s "show hidden characters", which allows toggle the visibility of non-printable characters, like zero-width space, CR LF and so-on, which look like this in Notepad++ (see the attachment for the sample document):
[image.png]
By looking at QTextLine and QTextLayout, it doesn't seems like there is a way to specific a certain unicode glyph's width (to reserve the space so we can then draw the character as visible glyphs manually). What comes to mind are the following two approaches:
1. Subclass QTextLayout to override the behavior of `cursorToX()` and other related functions.
By quickly take a look at this approach, it might be more complex than I thought, which will require using Qt's private header to access QTextEngine-related stuff.
2. Create a custom font that provides these characters, and ensure that font will be used before any other fonts.
I'm not exactly sure if this method is possible though.
So the question is, what's the proper approach to implement such a feature using Qt's public API? Do the mentioned two approaches sound right?
Thanks!
Gary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20241216/7d062ce0/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 8225 bytes
Desc: image.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20241216/7d062ce0/attachment.png>
More information about the Interest
mailing list