Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,17 @@ def test_variation_set_by_axes(font: ImageFont.FreeTypeFont) -> None:
_check_text(font, "Tests/images/variation_tiny_axes.png", 32.5)


def test_variation_set_by_fractional_axes() -> None:
font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf", 200)

def mask(weight: float) -> bytes:
font.set_variation_by_axes([weight, 0])
return bytes(font.getmask("test"))

# A fractional value must not be truncated or rounded
assert mask(600) != mask(600.5) != mask(601)


@pytest.mark.parametrize(
"anchor, left, top",
(
Expand Down
8 changes: 3 additions & 5 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,6 @@ font_setvaraxes_impl(FontObject *self, PyObject *args) {
PyObject *axes, *item;
Py_ssize_t i, num_coords;
FT_Fixed *coords;
FT_Fixed coord;
if (!PyArg_ParseTuple(args, "O", &axes)) {
return NULL;
}
Expand All @@ -1489,19 +1488,18 @@ font_setvaraxes_impl(FontObject *self, PyObject *args) {
}

if (PyFloat_Check(item)) {
coord = PyFloat_AS_DOUBLE(item);
coords[i] = lround(PyFloat_AS_DOUBLE(item) * 65536);
} else if (PyLong_Check(item)) {
coord = (float)PyLong_AsLong(item);
coords[i] = PyLong_AsLong(item) * 65536;
} else if (PyNumber_Check(item)) {
coord = PyFloat_AsDouble(item);
coords[i] = lround(PyFloat_AsDouble(item) * 65536);
} else {
Py_DECREF(item);
free(coords);
PyErr_SetString(PyExc_TypeError, "list must contain numbers");
return NULL;
}
Py_DECREF(item);
coords[i] = coord * 65536;
}

error = FT_Set_Var_Design_Coordinates(self->face, num_coords, coords);
Expand Down
Loading