The FontManager and FontQuery system ignore the Font.weight attribute and look for a style which holds flags for BOLD, ITALIC, BOLD_ITALIC, etc. See:
|
def _make_font_query(self): |
|
""" Returns a FontQuery object that encapsulates our font properties. |
|
""" |
|
# XXX: change the weight to a numerical value |
|
if self.style == BOLD or self.style == BOLD_ITALIC: |
|
weight = "bold" |
|
else: |
|
weight = "normal" |
|
if self.style == ITALIC or self.style == BOLD_ITALIC: |
|
style = "italic" |
|
else: |
|
style = "normal" |
|
query = FontQuery( |
|
family=self.familymap[self.family], |
|
style=style, |
|
weight=weight, |
|
size=self.size, |
|
) |
|
if self.face_name != "": |
|
query.set_name(self.face_name) |
|
return query |
But the str_to_font function populates weight. See:
|
elif lword in font_weights: |
|
weight = font_weights[lword] |
As does the trait validator:
|
elif lword in font_weights: |
|
weight = font_weights[lword] |
As does the Wx editor:
|
weight=( |
|
kc.NORMAL, kc.BOLD |
|
)[font.GetWeight() == wx.FONTWEIGHT_BOLD], |
To reproduce, you can use kvia_explorer.py with this script and the agg backend:
# The graphics context is available as gc.
from kiva.api import (
Font, BOLD_ITALIC, BOLD, ITALIC
)
from kiva.fonttools import str_to_font
font_1 = Font(
'Courier New',
style=BOLD_ITALIC,
size=24,
)
font_2 = str_to_font('24 pt italic bold Courier New')
with gc:
gc.set_font(font_1)
gc.show_text_at_point(f"font_1: weight={font_1.weight} style={font_1.style}", 20, 60)
gc.set_font(font_2)
gc.show_text_at_point(f"font_2: weight={font_2.weight} style={font_2.style}", 20, 20)
Which produces:

We would expect the second line to be bold.
Most backends suffer from this: Cairo does not, and a number of backends ignore bold/italic
The
FontManagerandFontQuerysystem ignore theFont.weightattribute and look for astylewhich holds flags forBOLD,ITALIC,BOLD_ITALIC, etc. See:enable/kiva/fonttools/font.py
Lines 149 to 169 in 62f390f
But the
str_to_fontfunction populatesweight. See:enable/kiva/fonttools/font.py
Lines 54 to 55 in 62f390f
As does the trait validator:
enable/kiva/trait_defs/kiva_font_trait.py
Lines 122 to 123 in 62f390f
As does the Wx editor:
enable/kiva/trait_defs/ui/wx/kiva_font_editor.py
Lines 98 to 100 in 62f390f
To reproduce, you can use
kvia_explorer.pywith this script and the agg backend:Which produces:

We would expect the second line to be bold.
Most backends suffer from this: Cairo does not, and a number of backends ignore bold/italic