Page MenuHome

Fix T96267: Sidebar Tab Font Size Correction
ClosedPublic

Authored by Harley Acheson (harley) on Mar 13 2022, 7:30 PM.

Details

Summary

Correction to the calculation of font size used for the tabs on the
N-Panel so that they are always the same size as other content on the
panel.


As the bug report shows, in master when the UI scale is at 1X the font size of tabs on N-Panel is noticeably larger than surrounding text. Increase the UI scale to 2X and there is less of a difference. In Blender 3.0 this text was not larger at 1X scale.

This is because our code is specifically trying to make this text 110% of the other text, for some reason. But because font sizing was in integers it was truncated to a smaller size than was requested. With float text sizing we now get what we ask for so the text is 10% larger there.

This patch takes out that 10% expansion. This also cleans up a bit of confusion in that code section. The ui_fontscale was using a division by U.pixelsize, which is incorrect since that is line-width (bigger with "wide lines"). This was most likely done because the next line was calling BLF_size with our U.dpi as dpi argument. But for unfathomable reasons our U.dpi is actually the DPI divided by U.pixelsize, so it has to be multiplied by same to get dpi back.

Diff Detail

Repository
rB Blender

Event Timeline

Harley Acheson (harley) requested review of this revision.Mar 13 2022, 7:30 PM
Harley Acheson (harley) created this revision.
Harley Acheson (harley) edited the summary of this revision. (Show Details)Mar 13 2022, 7:34 PM
William Reynish (billreynish) retitled this revision from Fix T96267: N-Panel Tab Font Size Correction to Fix T96267: Sidebar Tab Font Size Correction.Mar 13 2022, 8:11 PM
Brecht Van Lommel (brecht) added inline comments.
source/blender/editors/interface/interface_panel.c
1361

Other code calling BLF_size does this:

BLF_size(fontid, fstyle_points * U.pixelsize, U.dpi);

Which I imagine is practically the same thing, but better to be consistent.

@Brecht Van Lommel (brecht) - Other code calling BLF_size does this:

I don't mind doing it that way, but it adds to the confusion, all caused by our treatment of U.pixelsize. Although that is a float it is a whole number line width. So if the UI scale is 1.6X then it is 1.0f, but at 1.8X that is 2.0f. Keep the scale the same but turn on "wide lines" and it might become "3.0f"

BLF_size(fontid, fstyle_points * U.pixelsize, U.dpi);

So it is easy to look at the above and wonder how this works when pixelsize is a whole number, and you'd assume DPI was something like 72. It only works because U.dpi is really actual DPI divided by that pixelsize. So the multiplication by U.pixelsize here is not a scaling at all but a correction for that dumb division. We really need to fix that.

This is probably the most explanatory way for it:

diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index c7f2eb230cb..aacba3d7756 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -1357,9 +1357,8 @@ void UI_panel_category_draw_all(ARegion *region, const char *category_id_active)
 
   BLF_enable(fontid, BLF_ROTATION);
   BLF_rotation(fontid, M_PI_2);
-  // UI_fontstyle_set(&style->widget);
-  ui_fontscale(&fstyle_points, aspect / (U.pixelsize * 1.1f));
-  BLF_size(fontid, fstyle_points, U.dpi);
+  int dpi = U.dpi * U.pixelsize;
+  BLF_size(fontid, fstyle_points / aspect, dpi);
 
   /* Check the region type supports categories to avoid an assert
    * for showing 3D view panels in the properties space. */

The point is not that I think the existing convention is good, in fact I believe we should remove usage of U.pixelsize and U.dpi from the code entirely.

But it's better to be consistent so that when we do refactor, we don't have to wonder why this one case was doing something different, even if in isolation it might be more clear.

@Brecht Van Lommel (brecht) - it's better to be consistent so that when we do refactor...

Yes, no worries. I wasn't really arguing with you, more taking the chance to vent about it some more. LOL.

This revision is now accepted and ready to land.Mar 14 2022, 12:15 AM