https://bugs.kde.org/show_bug.cgi?id=509556

--- Comment #15 from klaviaRtur <[email protected]> ---
I can still eproduce this on Plasma 6.6.6 (Qt 6.10.2, Noto Sans, TUXEDO OS /
Ubuntu noble).

Setup: vertical panel, width 60, Digital Clock with seconds (HH:MM:SS).
Whenever the last digit of the seconds is a 4, the whole time is drawn with a
smaller font for that second. A 4 elsewhere in the text (e.g. 14:44:43) does
not trigger it. With panel width 62 the problem is gone.

I narrowed it down with a small QML test (attached, test-4-width.qml).
It creates a Text with font.family "Noto Sans", font.features { "tnum": 1 },
text "12:34:5" + d for d = 0..9, and prints contentWidth for pixel sizes
10..60:

  px 11: 43.56 43.56 43.56 43.56 44.56 43.56 43.56 43.56 43.56 43.56   (d =
0..9)
  px 13: 51.47 51.47 51.47 51.47 52.47 51.47 51.47 51.47 51.47 51.47   (d =
0..9)
  px 20: 79.34 79.34 79.34 79.34 80.34 79.34 79.34 79.34 79.34 79.34   (d =
0..9)

So at 11, 13 and 20 px the text is exactly one pixel wider if the last digit is
a 4.
Only these three of the 51 tested sizes are affected (the other sizes give
identical widths), which fits the reports that only certain panel sizes are
affected.

In Noto Sans all digits have the same advance (572 units with tnum), but the 4
has the smallest right side bearing (20 units, the other digits 47-217). I have
not determined where exactly the extra pixel comes from.

What DigitalClock.qml does with this: 
setupLabels() picks the "widest" digit with timeMetrics.advanceWidth(i). Since
all advances are equal it always picks 0, so sizehelper.text is "00:00:00",
while the real text with a trailing 4 is one pixel wider. Text.Fit on timeLabel
then shrinks the font for that second.

I tried a fix: measure the digits in a separate FontMetrics at a large pixel
size with the same font features as timeLabel, and use the right edge of the
glyph (tightBoundingRect) as a tie breaker when the advances are equal, so the
4 gets picked. With this the clock keeps the same size for every last digit.

In a side by side comparison with the unpatched applet, the unpatched one is
slightly bigger for all last digits except 4, where it shrinks to the size of
the patched one. So the trade-off is that the font can be one pixel smaller in
affected sizes, but it is stable.

Disclosure: I used an AI assistant (Claude) to help with the code analysis and
to draft the patch. I reproduced the issue, ran the tests and verified the fix
on my machine myself.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to