ndevenish / gflabel

Generate 3d-printable labels for gridfinity label systems
BSD 3-Clause "New" or "Revised" License
44 stars 6 forks source link

Font_FontMgr, warning: unable to find font #4

Closed CullenJWebb closed 6 months ago

CullenJWebb commented 6 months ago

Hello again!

This tool is simply amazing. However, I am unable to use non-system fonts or else I get this error:

Font_FontMgr, warning: unable to find font 'Open Sans Regular' [regular]; 'Arial' [aspects: regular,bold,italic,bold-italic] [paths: C:\Windows\Fonts\arial.ttf;C:\Windows\Fonts\arialbd.ttf;C:\Windows\Fonts\ariali.ttf;C:\Windows\Fonts\arialbi.ttf] is used instead

I've tried the following to get it to work:

Any guidance would be helpful. Thank you!

CullenJWebb commented 6 months ago

I have it working on a Windows 10 device as opposed to 11 on the troublesome one, so this may just be a Windows 11 bug. Feel free to close out if you agree. Otherwise I'm happy to troubleshoot.

ndevenish commented 6 months ago

It's installed in a place other apps can just "see" it? I think build123d has a different way to specify font files directly, which I should probably expose

ndevenish commented 6 months ago

Does this raw python work for build123d:

from build123d import Text
Text("Test", 10, font="Open Sans Regular")

Or do you need to do some combination of font/font_path/both e.g.

from build123d import Text
Text("Test", 10, font="Open Sans Regular", font_path="/path/to/font/file")

If the latter, I should probably add a way to specify font path directly from the CLI, there isn't currently a way to pass through (I hadn't used it personally and so didn't know if people would want to use it that way)

CullenJWebb commented 6 months ago

It's installed in a place other apps can just "see" it? I think build123d has a different way to specify font files directly, which I should probably expose

Hmm. I checked for the font in other apps and they don't see it either. So this whole problem is probably isolated to my system. I can't see the font in Bambu Studio, for example. I will need to figure this out for myself as I need the font in my other apps, and I don't think this needs a workaround in gflabel. I'll still debug using the examples you provided though.

from build123d import Text Text("Test", 10, font="Open Sans Regular")

This did not work, I received the same error.

from build123d import Text Text("Test", 10, font="Open Sans Regular", font_path="/path/to/font/file")

This appeared to work. I didn't receive an error, but without a output file to check I can't be certain. I am not sure how to implement this with gflabel.

ndevenish commented 6 months ago

I am not sure how to implement this with gflabel.

I think the easiest way is just to add a --font-path option, that you can directly pass a font file in.

I also wonder if it'd be better to directly embed a free font as the default, rather than whatever the system has (I guess Arial, the default now is Futura which is good for me but probably not something a lot of people have).

ndevenish commented 6 months ago

Oops, apparently that particular phrasing triggered the autoclose.

I've added a commit to main, https://github.com/ndevenish/gflabel/commit/52ef499ebb3aace7c4a01a14803d9ac71edaa3cb , that allows setting font path directly with --font-path=/path/to/font.

I've also changed the default to "Open Sans" and bundled Open Sans. It seemed like a good reasonable default to put in.

Does this work for you/does --font-path work for you for other fonts?

CullenJWebb commented 6 months ago

That makes perfect sense, thanks a bunch. This way I can just package the font file in my scripts and it will be machine agnostic.