Skip to content

Commit d67d6ac

Browse files
committed
test_transform: simplified get_font_array code
May contribute fixing Test failures with test_transform on NixOS #20
1 parent 54c84d4 commit d67d6ac

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

plotpy/tests/items/test_transform.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def get_font_array(sz: int, chars: str = DEFAULT_CHARS) -> np.ndarray | None:
4848
metric = pnt.fontMetrics()
4949
rct = metric.boundingRect(chars)
5050
pnt.end()
51-
h = rct.height()
52-
w = rct.width()
51+
h, w = rct.height(), rct.width()
5352
img = QG.QImage(w, h, QG.QImage.Format_ARGB32)
5453
paint = QG.QPainter()
5554
paint.begin(img)
@@ -62,12 +61,11 @@ def get_font_array(sz: int, chars: str = DEFAULT_CHARS) -> np.ndarray | None:
6261
paint.drawText(0, paint.fontMetrics().ascent(), chars)
6362
paint.end()
6463
try:
65-
data = img.bits().asstring(img.sizeInBytes())
64+
data = img.bits().asstring(h * w * 4)
6665
except AttributeError:
6766
data = img.bits()
68-
npy = np.frombuffer(data, np.uint8)
69-
npy.shape = img.height(), img.bytesPerLine() // 4, 4
70-
return npy[:, :, 0]
67+
npy: np.ndarray = np.frombuffer(data, np.uint8)
68+
return npy.reshape(h, w, 4)[:, :, 0]
7169

7270

7371
def write_text_on_array(

0 commit comments

Comments
 (0)