Skip to content

Fix position and size of the underline

Luca Carlon requested to merge lcarlon/konsole:fix-underline into master

When rendering underlined text in hidpi, the result may be wrong: position of the underline may be wrong, invisible or with incorrect size.

The patch draws the line using floating point precision and changes the y coord of the line to respect the Qt coordinate system specs.

I tested the code in a couple of cases. This is what happens in current master with a font reporting this (SourceCodeVF) with 2x scaling (libreoffice is for comparison):

Ascent: 16
Line width: 1
Underline pos: 1
Overline pos: 17
Font height: 21
Descent: 5
Line spacing: 0

master_sourcecode

This is what happens with this patch:

fix_sourcecode

If you zoom and measure, the underline pos is 4px in master, but should be 2px in 2x scale.

This is another case in 2x scaling with the Ubuntu Mono font:

Ascent: 14
Line width: 1
Underline pos: 2
Overline pos: 15
Font height: 17
Descent: 3
Line spacing: 0

master_ubuntu

this is with this patch:

fix_ubuntu

In this last case, the underline is completely missing, because it is overlapped by the following row.

The fix is relevant mostly because drawing out of the proper area may result in artifacts or missing parts (https://bugs.kde.org/show_bug.cgi?id=373232).

Edited by Luca Carlon

Merge request reports

Loading