Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to use font specified at path #198

Closed
bweissinger opened this issue Oct 11, 2019 · 5 comments
Closed

Ability to use font specified at path #198

bweissinger opened this issue Oct 11, 2019 · 5 comments
Labels
OCC feature Requires coding at OCC implementation level text rendering Features and issues related to text rendering

Comments

@bweissinger
Copy link
Contributor

It would be handy to be able to use a font located at a specific file path. Right now you can specify what font to use with text() by font name. PythonOCC/OCE will search the registered system fonts to find the named font. As far as I can tell there is currently no way in CadQuery to use a non-system font.

register_font from OCC.Core.Addons does provide capability to register a font for use. I propose that we wrap register_font and either allow a file path to be passed to text, and then register and use that font, or create a separate function to allow users to register additional fonts.

@adam-urbanczyk adam-urbanczyk added OCC feature Requires coding at OCC implementation level text rendering Features and issues related to text rendering labels Oct 13, 2019
@adam-urbanczyk
Copy link
Member

Agreed, I added this to the CQ2.1 issue list.

@cactrot
Copy link
Contributor

cactrot commented Sep 18, 2020

I was just working on doing this. Excellent that you are already planning on implementing it.

The use of the "typing" module threw me off for a bit, but this appears to load a font properly.

register the font

font_mgr = cq.occ_impl.importers.OCP.Font.Font_FontMgr
font_aspect = cq.occ_impl.importers.OCP.Font.Font_FontAspect_Regular

font_mgr_instance = font_mgr.GetInstance_s()

font_list = cq.occ_impl.importers.OCP.Font.Font_NListOfSystemFont()

a_string = cq.occ_impl.shapes.TCollection_AsciiString

system_font = cq.occ_impl.importers.OCP.Font.Font_SystemFont(a_string("Liberation Sans"))

system_font.SetFontPath(font_aspect, a_string("""C:\Windows\fonts\LiberationSans.ttf"""))

font_mgr_instance.RegisterFont(system_font, False)

#check if it worked
font_instance = font_mgr_instance.FindFont(a_string("Liberation Sans"), font_aspect)

font_instance.FontName().ToCString()

font_instance.FontPath(font_aspect).ToCString()

font_mgr_instance.AvailableFonts(font_list)

while font_list.Size():
item = font_list.First()
font_name = item.FontName()
font_path = item.FontPath(font_aspect)
print(font_name.ToCString(), font_path.ToCString())
font_list.RemoveFirst()

@jmwright
Copy link
Member

@cactrot Would you be interested in putting together a PR for this?

@cactrot cactrot mentioned this issue Sep 21, 2020
@cactrot
Copy link
Contributor

cactrot commented Oct 14, 2020

I believe the merge of #453 resolves this issue.

@jmwright
Copy link
Member

Yep, seems that way. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCC feature Requires coding at OCC implementation level text rendering Features and issues related to text rendering
Projects
None yet
Development

No branches or pull requests

4 participants