move caching of get_qfont() to a non-member function
@@ -273,17 +273,12 @@ class PyQtBackend(Backend):
)
self._set_item_data(item)
- @lru_cache(maxsize=256) # fonts.Font is a named tuple
def get_qfont(self, font: fonts.FontFace) -> qg.QFont:
- qfont = self._text_renderer.default_font
- if font:
- family = font.family
- italic = "italic" in font.style.lower()
- weight = _map_weight(font.weight)
- qfont = qg.QFont(family, weight=weight, italic=italic)
- # INFO: setting the stretch value makes results worse!
- # qfont.setStretch(_map_stretch(font.stretch))
- return qfont
+ # can't pass default font: qg.QFont is not unhashable!
+ font = _get_qfont(font)
+ if font is None:
+ return self._text_renderer.default_font
+ return font
def get_font_measurements(
self, cap_height: float, font: fonts.FontFace = None
@@ -321,7 +316,19 @@ class PyQtBackend(Backend):
self._get_pen(properties),
self._no_fill,
)
- self.get_qfont.cache_clear()
+
+
+@lru_cache(maxsize=256) # fonts.Font is a named tuple
+def _get_qfont(font: fonts.FontFace) -> Optional[qg.QFont]:
+ qfont = None
+ if font:
+ family = font.family
+ italic = "italic" in font.style.lower()
+ weight = _map_weight(font.weight)
+ qfont = qg.QFont(family, weight=weight, italic=italic)
+ # INFO: setting the stretch value makes results worse!
+ # qfont.setStretch(_map_stretch(font.stretch))
+ return qfont
class _CosmeticPath(qw.QGraphicsPathItem):
