mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #7107 from radarhere/float_font_sizes
Support float font sizes
This commit is contained in:
commit
139acc4542
|
@ -191,6 +191,16 @@ def test_getlength(
|
|||
assert length == length_raqm
|
||||
|
||||
|
||||
def test_float_size():
|
||||
lengths = []
|
||||
for size in (48, 48.5, 49):
|
||||
f = ImageFont.truetype(
|
||||
"Tests/fonts/NotoSans-Regular.ttf", size, layout_engine=layout_engine
|
||||
)
|
||||
lengths.append(f.getlength("text"))
|
||||
assert lengths[0] != lengths[1] != lengths[2]
|
||||
|
||||
|
||||
def test_render_multiline(font):
|
||||
im = Image.new(mode="RGB", size=(300, 100))
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
|
|
@ -116,7 +116,9 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
|
|||
int error = 0;
|
||||
|
||||
char *filename = NULL;
|
||||
Py_ssize_t size;
|
||||
float size;
|
||||
FT_Size_RequestRec req;
|
||||
FT_Long width;
|
||||
Py_ssize_t index = 0;
|
||||
Py_ssize_t layout_engine = 0;
|
||||
unsigned char *encoding;
|
||||
|
@ -133,7 +135,7 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
|
|||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args,
|
||||
kw,
|
||||
"etn|nsy#n",
|
||||
"etf|nsy#n",
|
||||
kwlist,
|
||||
Py_FileSystemDefaultEncoding,
|
||||
&filename,
|
||||
|
@ -179,7 +181,13 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
|
|||
}
|
||||
|
||||
if (!error) {
|
||||
error = FT_Set_Pixel_Sizes(self->face, 0, size);
|
||||
width = size * 64;
|
||||
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
|
||||
req.width = width;
|
||||
req.height = width;
|
||||
req.horiResolution = 0;
|
||||
req.vertResolution = 0;
|
||||
error = FT_Request_Size(self->face, &req);
|
||||
}
|
||||
|
||||
if (!error && encoding && strlen((char *)encoding) == 4) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user