getting font file (.ttf) based on font name?

   3284   6   1
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
Here is a tricky one…

I have the font face name as an attribute on my mesh, and I want to use it on the font SOP to return the actual font to use. However, it looks like font names are only part of the drop down menu display names. When choosing a font from the menu, Houdini maps the string to the actual filename. Any ideas on how to get that filename given the font face name? I can do string operations to even match the name from the drop down menu if needed

TX!
-G
User Avatar
Member
168 posts
Joined:
Offline
you could use hscript with string operations like

strreplace()
substr()
etc

for eg. `strreplace(chs(“../font1/file”), “.ttf”, “”)`


or python string operations:
http://docs.python.org/library/string.html [docs.python.org]
Albert
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
Hi tmdag! Thank you for your reply, unfortunately it is not that simple. Most TTF file names do not even match the font name (i.e. Arial Bold Narrow would be named something like ARLBLDNR.TTF). Most of them are so old that follow eight dot three convention.

The menu on the right of the font field in the font sop, however, does that conversion for you (when you pick a font face from the drop down menu, Houdini automatically drops the proper file name in the field as a string). However, I am not sure if you can access those menu items via python
-G
User Avatar
Member
7766 posts
Joined: July 2005
Offline
This is less than elegant and won't work for all cases, but FWIW…
import shlex
font_menu_items = map(shlex.split,open(hou.findFile(“fonts/font.index”)).readlines())
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
sir, this is the BOMB! I think this will most likely work, especially if I can rely on that font index being there thank you !

What cases were you thinking that may not work?
-G
User Avatar
Member
7766 posts
Joined: July 2005
Offline
grayOlorin
What cases were you thinking that may not work?

hou.findFile() will find the first such font.index in your HOUDINI_PATH. I'm not quite what happens if you have multiple font.index files in your path.
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
Thank you I will keep an eye fir that. I will probably iteratr this for every index file. It worked great
-G
  • Quick Links