BelfrySCAD / BOSL2

The Belfry OpenScad Library, v2.0. An OpenSCAD library of shapes, masks, and manipulators to make working with OpenSCAD easier. BETA
https://github.com/BelfrySCAD/BOSL2/wiki
BSD 2-Clause "Simplified" License
999 stars 114 forks source link

shaped2d text module defaults to Helvetica, which is not universally available #1474

Closed MethylBromide closed 1 month ago

MethylBromide commented 1 month ago

Describe the bug If a call to the text module of shapes2d.scad is made without providing a font value, the default font used is Helvetica, which isn't available on all systems and which produces odd results.

Code To Reproduce Bug

include <BOSL2/std.scad>
text("abcd");

Expected behavior I had expected the same default font as the built-in text function to be used, or at any rate some reasonable, legible, sans-serif font. Instead an apparently random font is used since nothing on my system is called Helvetica. The font used is "Goma Stencil" so the name doesn't particularly resemble "Helvetica".

I don't understand why the text module in BOSL2 needs to override the default font of the built-in text function. It's a perfectly fine font.

Now there is also an OpenSCAD bug here because replacing an unrecognized font with a random one isn't reasonable behavior. But I also think BOSL2 is wrong to specify Helvetica -- especially since if you hope to remain backward compatible to 2019 versions, you should work around this bug.

Screenshots Screenshot_187 Screenshot_188

Additional context Add any other context about the problem here.

revarbat commented 1 month ago

... in days of Yor it used to be that there were exactly three universal platform independent fonts: Helvetica for sans-serif, Times for serif, and Courier for monospaced. In TCL/Tk, in fact, those font names were internally remapped to the platform similar font, if it somehow DIDN'T exist. My last big project was a CAD/CAM written in TCL/Tk, so I apparently made that assumption when I wrote that module. My bad. Perhaps if we default to passing font=undef, we can get the platform default font?

adrianVmariano commented 1 month ago

This change should presumably be made to all 3 text generating modules. Passing font=undef does appear to work. (Produces identical behavior on my machine to the current "Helvetica" default.) I think the docs for the font option for those 3 modules gives incorrect information, though I guess we don't know what the default font is? I checked with Jordan and he says OpenSCAD shipes with Liberation Sans and that should be the default font.

It does seem like OP has something wrong with their font setup that it returns Goma Stencil when Helvetica is requested. I suspect that's not an OpenSCAD problem. But there's no reason for us to specify a default font like we are currently doing.

adrianVmariano commented 1 month ago

Actually if @MethylBromide could enable the experimental textmetrics feature and run

echo(fontmetrics());

that would tell us their default font and confirm that it is Liberation Sans as expected.

MethylBromide commented 1 month ago

ECHO: { nominal = { ascent = 12.5733; descent = -2.9433; }; max = { ascent = 13.6109; descent = -4.2114; }; interline = 15.9709; font = { family = "Liberation Sans"; style = "Regular"; }; }

I can also confirm that when I use the built-in text function without specifying a font, it works as expected, while if I specify "Helvetica" or any other string that's not a real font name, the Goma Stencil font is used.

adrianVmariano commented 1 month ago

Yeah, that definitely sounds like your system is broken with regards to font management. Pretty strange. I've got the default font fixed in a PR.

Can you check if "Liberation Mono" works for you? I'm told the liberation fonts will always work, so I'm thinking of changing all the "Courier" examples in the manual to "Liberation Mono" instead to ensure that examples work for everybody.

MethylBromide commented 1 month ago

"Liberation Sans" is used when I specify it explicitly or when I use the system text function and font=undef. "Liberation Mono" works as expected. I don't understand how the fontmetrics output leads you to think something is special about my system.

adrianVmariano commented 1 month ago

What seems special about your system is that it returns "Goma Stencil" when any unavailable font is requested. The font system is supposed to select a font with the same characteristics as the requested font, not return a weird special effects font. It should work to request Helvetica on your system. That it fails indicates that something is broken somewhere.

The font metrics output just gives me confirmation that things are working as expected and that if I claim that "Liberation Sans" is the default font it's not false somewhere.

revarbat commented 1 month ago

Fix has been merged into mainline.