Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions kiva/qpainter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@
draw_modes[constants.FILL_STROKE] = QtCore.Qt.OddEvenFill
draw_modes[constants.EOF_FILL_STROKE] = QtCore.Qt.WindingFill

font_family_to_style_hint = {
constants.DEFAULT: QtGui.QFont.StyleHint.AnyStyle,
constants.SWISS: QtGui.QFont.StyleHint.SansSerif,
constants.ROMAN: QtGui.QFont.StyleHint.Serif,
constants.MODERN: QtGui.QFont.StyleHint.Monospace,
constants.TELETYPE: QtGui.QFont.StyleHint.TypeWriter,
constants.DECORATIVE: QtGui.QFont.StyleHint.Decorative,
constants.SCRIPT: QtGui.QFont.StyleHint.Cursive,
}

font_styles = {}
font_styles["regular"] = constants.NORMAL
font_styles["bold"] = constants.NORMAL
Expand Down Expand Up @@ -649,13 +659,28 @@ def select_font(self, name, size, style="regular", encoding=None):
def set_font(self, font):
""" Set the font for the current graphics context.
"""
qfont = QtGui.QFont(font.face_name, font.size)

qfont = QtGui.QFont()
qfont.setStyleHint(font_family_to_style_hint[font.family])
qfont.setPointSizeF(font.size)
weight = font._get_weight()
qfont.setWeight(weight_to_qt_weight[weight])

qfont.setItalic(font.style in constants.italic_styles)

if font.face_name:
name = font.face_name
else:
# if we don't have a face name, see if Qt can suggest one
name = qfont.defaultFamily()
if not name:
# otherwise use kiva.fonttools to suggest one
name = font.findfontname()

# setFamilies() was introduced in Qt 5.13
if hasattr(qfont, 'setFamilies'):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a note here that the method was introduced in Qt 5.13 would be helpful?

qfont.setFamilies([name])
else:
qfont.setFamily(name)

self.gc.setFont(qfont)

def set_font_size(self, size):
Expand Down