Opened 9 months ago

Last modified 4 months ago

#15007 new bug

Font width misscalculated

Reported by: cb88 Owned by: nobody
Priority: normal Milestone: R1/beta2
Component: - General Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All


With the default font everything looks fine.

However if you switch to a different font that has a different width then it is broken. The more you type the more goes missing...

I am using IBM Plex Sans 12

The screenshot is of Vision but t also occurse in other text controls say the Query window for instance.

Attachments (1)

screenshot2.png (6.6 KB ) - added by cb88 9 months ago.
The text at the end should display think but it gets chopped off.

Download all attachments as: .zip

Change History (3)

by cb88, 9 months ago

Attachment: screenshot2.png added

The text at the end should display think but it gets chopped off.

comment:1 by waddlesplash, 8 months ago

Milestone: UnscheduledR1/beta2

It'd be nice, but not mandatory, if someone could look into this before beta2.

comment:2 by pulkomandy, 4 months ago

This is a known issue with subpixel rendering. Basically, the BeAPI tells that it is equivalent to do either of these:

const char* str = "Hello World"

float a = StringWidth(str);
float b = 0;
for (auto i: str)
    b += StringWidth(i);

(or cut the string in any other way).

And likewise, that it is safe to split the string as you want and draw it piecewise with multiple successive calls to DrawString.

However, with subpixel, this does not work at all:

  • The characters overwrite each other slightly when drawn as part of successive calls to DrawString
  • The pen position is possibly not preserved correctly, especially if the view doing the drawing does not use the B_SUBPIXEL_PRECISE flag which allows the pen position to not be automatically rounded to pixels

BTextView relies on the BeAPI behavior and uses it a low to do only minimal redrawing of small parts of the text (one letter at a time when you type, for example).

The default fonts we use (both DejaVu and Noto) have strong hinting, which mostly forces them to stick to the pixel grid already. But whenever you use a font with weaker hinting, the issue becomes more easily visible.

Workaround: disable subpixel rendering, but then the text will look ugly.

I'm not sure we can fix this without removing this possibility from the API (which we probably have to do if we're going to support ligatures and other typography features anyway). Maybe enabling B_SUBPIXEL_PRECISE for BTextView will work well enough for beta2.

Note: See TracTickets for help on using tickets.