Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#17229 closed bug (fixed)

Bad character escapements for some bold fonts

Reported by: hgsfghs Owned by: madmax
Priority: normal Milestone: R1/beta4
Component: Servers/app_server Version: R1/beta3
Keywords: Cc: madmax
Blocked By: Blocking:
Platform: All

Description

BFont.StringWidth () and BFont.GetEscapements () seem to return overly wide sizes for bold fonts. It can be reproduced by the following code:

    BView vw; /* Get a view somehow */
    const char *str = "Haiku test string";
    float fl[strlen (str)];
    edge_info ei[strlen (str)];
    ft.GetEscapements (str, strlen (str), (float *) &fl);
    ft.GetEdges (str, strlen (str), (edge_info *) &ei);
    vw->LockLooper ();
    vw->PushState ();
    vw->PushState ();
    vw->SetHighColor (128, 0, 0, 255);
    vw->SetPenSize (2.0);
    BRect r (0, 0, ft.StringWidth (str) - 1, 50);
    vw->StrokeRect (r);
    vw->PopState ();
    vw->MovePenTo (0, 50);
    vw->SetFont (&ft);
    vw->DrawString (str);
    vw->PopState ();
    vw->UnlockLooper ();

The rectangle drawn will be far wider than the text drawn, which is not the case with a plain font. Similar issues, albeit on a character-by-character basis can be seen in the escapements returned by BFont.GetEscapements ().

I have attached two screenshots, depicting the difference between the result of calling GetStringWidth () on a regular font and that of calling the same function on a bold font.

Attachments (2)

Screenshot from 2021-08-31 19-34-14.png (3.2 KB ) - added by hgsfghs 3 years ago.
StringWidth of string with bold font
Screenshot from 2021-08-31 19-29-16.png (3.5 KB ) - added by hgsfghs 3 years ago.
StringWidth of string with plain font

Download all attachments as: .zip

Change History (25)

by hgsfghs, 3 years ago

StringWidth of string with bold font

by hgsfghs, 3 years ago

StringWidth of string with plain font

comment:1 by waddlesplash, 3 years ago

Cc: madmax added
Component: KitsServers/app_server
Keywords: bfont escapements removed
Owner: changed from nobody to axeld

madmax, you seem to be the burgeoning fonts rendering person, perhaps you might have some time to look into this?

comment:2 by madmax, 3 years ago

Owner: changed from axeld to madmax
Status: newassigned

comment:3 by madmax, 3 years ago

Summary: Bad character escapements for bold fontsBad character escapements for some bold fonts

Reproducible with Noto Sans Bold, but not with Noto Sans Display Bold (or any other of the very few I've tested with).

comment:4 by hgsfghs, 3 years ago

I also noticed that BFont.GetEdges () and BFont.GetEscapements () doesn't seem to respect shear. Could this be related somehow?

comment:5 by madmax, 3 years ago

The problem is not with metrics. The painter is using SemiBold style instead of Bold for that font. Will try to find out why later in the evening.

comment:7 by hgsfghs, 3 years ago

Thanks for the help and timely fix :)

comment:8 by hgsfghs, 3 years ago

It doesn't seem like the patch has been installed yet. Is there any way I can help with this? Right now, it's preventing some important features such as reading e-mail with RMAIL from working correctly in Emacs.

Thanks.

comment:9 by pulkomandy, 3 years ago

Sorry, it seems this one got lost in the code review process, I have just merged it now.

comment:10 by pulkomandy, 3 years ago

Milestone: UnscheduledR1/beta4
Resolution: fixed
Status: assignedclosed

comment:11 by hgsfghs, 3 years ago

Thanks! One last question: will this patch end up in R1/Beta3 systems updated through SoftwareUpdater, or will it only show up in nightlies?

comment:12 by pulkomandy, 3 years ago

I have only merged it for nightlies. We can backport it to the beta3 branch as well if needed.

comment:13 by hgsfghs, 3 years ago

It would be nice to have Emacs work properly in R1/Beta3 (since that's the system I use for testing), but if you think it's too risky to backport then that's fine as well.

Thanks :)

comment:14 by pulkomandy, 3 years ago

I'd say let's wait for a week or two and if no one complains about regressions in nightlies we can backport it. Remind me then because I will probably forget to do it.

comment:15 by hgsfghs, 3 years ago

Okay, thanks!

comment:16 by hgsfghs, 3 years ago

It's been two weeks, so if there haven't been any regressions I think it would be nice for someone to backport it to R1/Beta3. WDYT?

Thanks.

in reply to:  13 comment:18 by madmax, 3 years ago

Replying to hgsfghs:

It would be nice to have Emacs work properly in R1/Beta3 (since that's the system I use for testing)

To be clear, does that mean we have not checked the patch solves your real problem in nightlies? It does fix a problem with font flags that leads to the issue in the description, but I only ran the test you provided and a few similar ones. Is that extracted from the code used by emacs? If that's not the case, can you provide instructions (detailed ones including setup, I have no emacs experience) to reproduce it in emacs?

comment:19 by hgsfghs, 3 years ago

No, I just meant to say that it would be nice to have it backported to the beta branch, since I use that for testing. I installed one of the nightlies temporarily to test, and it does fix the problem with Emacs.

Thanks.

Last edited 3 years ago by hgsfghs (previous) (diff)

comment:20 by korli, 3 years ago

This change is backported to the beta3 branch in Git.

comment:21 by hgsfghs, 3 years ago

Thanks.

comment:22 by korli, 3 years ago

can you confirm it works as expected for you on beta3?

comment:23 by hgsfghs, 3 years ago

It does, thanks.

Note: See TracTickets for help on using tickets.