CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.26k stars 295 forks source link

Cannot find correct font resource in makeText (OCP branch) #337

Closed michaelgale closed 7 months ago

michaelgale commented 4 years ago

When attempting to specify a specific typeface for makeText, it results in the following error:

Font_FontMgr, warning: unable to find font '/usr/share/fonts/truetype/DIN/DIN-Regular.ttf' [regular]; 'FreeSans' [aspects: regular,bold,italic,bold-italic] [paths: /usr/share/fonts/truetype/freefont/FreeSans.ttf;/usr/share/fonts/truetype/freefont/FreeSansBold.ttf;/usr/share/fonts/truetype/freefont/FreeSansOblique.ttf;/usr/share/fonts/truetype/freefont/FreeSansBoldOblique.ttf] is used instead

After making an alternate implementation of makeText, I discovered that the makeText method should be modified as follows:

        text_flat = Shape(
            builder.Perform(font.FontPath(font_kind).ToCString(), size, font_kind, text)
        )

should be:

        text_flat = Shape(
            builder.Perform(font.FontName().ToCString(), size, font_kind, text)
        )

Perhaps its related to how Font_BRepTextBuilder gets wrapped when building OCP?

Tested on Linux version 4.15.0-96-generic (ubuntu 18.04)

jmwright commented 4 years ago

I get the same error on Ubuntu 18.04.

michaelgale commented 4 years ago

@jmwright Glad to hear its repeatable. After changing the way Font_BRepTextBuilder gets called, I can use any font (although not all Font Aspects) discovered by OCCT from the OS's font libraries. I can also register new fonts (or modify mappings inside the OCCT internal font library) to fine tune the selection of desired typefaces. I think the problem is related to how the arguments to Font_BRepTextBuilder.Perform get mapped from OCCT to OCP.

adam-urbanczyk commented 4 years ago

Thanks for finding this @michaelgale !

jmwright commented 3 years ago

So was this fixed in this commit? https://github.com/CadQuery/cadquery/commit/23418b98a7278173eb7576ed5e3faf9ec5a803ea

jmwright commented 7 months ago

This seems to be fixed. Closing.

michaelgale commented 7 months ago

Yep. Its been fixed for a while. Forgot to close.