Skip to content

Commit 98e6ab0

Browse files
committed
Merge branch 'master' of C:/Users/Pierre Raybaut/Documents/Python/python-qwt
2 parents 7888724 + 7233d41 commit 98e6ab0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

qwt/text_engine.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,32 @@ class QwtPlainTextEngine(QwtTextEngine):
6666
def __init__(self):
6767
self.qrectf_max = QRectF(0, 0, QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)
6868
self._fm_cache = {}
69+
self._fm_cache_f = {}
6970

7071
def fontmetrics(self, font):
71-
fm = self._fm_cache.get(id(font))
72+
fid = font.toString()
73+
fm = self._fm_cache.get(fid)
7274
if fm is None:
73-
return self._fm_cache.setdefault(id(font), QFontMetricsF(font))
75+
return self._fm_cache.setdefault(fid, QFontMetrics(font))
76+
else:
77+
return fm
78+
79+
def fontmetrics_f(self, font):
80+
fid = font.toString()
81+
fm = self._fm_cache_f.get(fid)
82+
if fm is None:
83+
return self._fm_cache_f.setdefault(fid, QFontMetricsF(font))
7484
else:
7585
return fm
7686

7787
def heightForWidth(self, font, flags, text, width):
78-
fm = self.fontmetrics(font)
88+
fm = self.fontmetrics_f(font)
7989
rect = fm.boundingRect(QRectF(0, 0, width, QWIDGETSIZE_MAX),
8090
flags, text)
8191
return rect.height()
8292

8393
def textSize(self, font, flags, text):
84-
fm = self.fontmetrics(font)
94+
fm = self.fontmetrics_f(font)
8595
rect = fm.boundingRect(self.qrectf_max, flags, text)
8696
return rect.size()
8797

@@ -120,7 +130,7 @@ def findAscent(self, font):
120130

121131
def textMargins(self, font):
122132
left = right = top = 0
123-
fm = self.fontmetrics(font)
133+
fm = self.fontmetrics_f(font)
124134
top = fm.ascent() - self.effectiveAscent(font)
125135
bottom = fm.descent()
126136
return left, right, top, bottom

0 commit comments

Comments
 (0)