Reputation: 4586
In cairo
, fonts can be specified by their family name, e.g. 'HelveticaNeueLTStd'. Then, weights and styles can be defined by cairo.FONT_WEIGHT_[NORMAL|BOLD]
and cairo.FONT_SLANT_[NORMAL|OBLIQUE|ITALIC]
, which are constants with integer values. Only these 2 and 3 options are built in. I am wondering, how to select specific weights and styles in case the family have more of them? E.g. Light, Semi-bold, etc.
I am using pycairo 1.10.0
in python 2.7
, although these things looks the same in any language.
I could find the solution by guessing, so I will answer my question, but still I am wondering if this is the standard way of doing.
Upvotes: 0
Views: 3971
Reputation: 4586
Font files have various names and other annotations. In FontForge, you can find these listed in menu Element > Font info
. Here as I found cairo
is able to identify the font by its TTF names > Family
or which is the same its WindowsString
. In case of Adobe's Helvetica Neue light this string has the value 'HelveticaNeueLT Std Lt'
. Then selecting the font by this name, and setting the slant and weight to normal, the light weight will be used:
context.select_font_face('HelveticaNeueLT Std Lt', \
cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
It is possible to find font names by many softwares. On Linux fontconfig
is able to list fonts, and the name in the second column what cairo recognizes:
$ fc-list | grep HelveticaNeue
...
/usr/share/fonts/.../HelveticaNeueLTStd-Lt.otf: Helvetica Neue LT Std,HelveticaNeueLT Std Lt:style=45 Light,Regular
...
$ fc-list | sed 's/.*:\(.*,\|\s\)\(.*\):.*/\2/'
...
HelveticaNeueLT Std Lt
...
Upvotes: 4