Skip to content

Commit 9fbd35f

Browse files
committed
use mode for getsize
1 parent ba58ae7 commit 9fbd35f

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/PIL/ImageFont.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def getsize(
259259
260260
:return: (width, height)
261261
"""
262-
size, offset = self.font.getsize(text, direction, features, language)
262+
size, offset = self.font.getsize(text, False, direction, features, language)
263263
return (
264264
size[0] + stroke_width * 2 + offset[0],
265265
size[1] + stroke_width * 2 + offset[1],
@@ -468,7 +468,9 @@ def getmask2(
468468
:py:mod:`PIL.Image.core` interface module, and the text offset, the
469469
gap between the starting coordinate and the first marking
470470
"""
471-
size, offset = self.font.getsize(text, direction, features, language)
471+
size, offset = self.font.getsize(
472+
text, mode == "1", direction, features, language
473+
)
472474
size = size[0] + stroke_width * 2, size[1] + stroke_width * 2
473475
im = fill("L", size, 0)
474476
self.font.render(

src/_imagingft.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ font_getsize(FontObject* self, PyObject* args)
605605
FT_Face face;
606606
int xoffset, yoffset;
607607
int horizontal_dir;
608+
int mask = 0;
609+
int load_flags;
608610
const char *dir = NULL;
609611
const char *lang = NULL;
610612
size_t i, count;
@@ -614,11 +616,11 @@ font_getsize(FontObject* self, PyObject* args)
614616
/* calculate size and bearing for a given string */
615617

616618
PyObject* string;
617-
if (!PyArg_ParseTuple(args, "O|zOz:getsize", &string, &dir, &features, &lang)) {
619+
if (!PyArg_ParseTuple(args, "O|izOz:getsize", &string, &mask, &dir, &features, &lang)) {
618620
return NULL;
619621
}
620622

621-
count = text_layout(string, self, dir, features, lang, &glyph_info, 0);
623+
count = text_layout(string, self, dir, features, lang, &glyph_info, mask);
622624
if (PyErr_Occurred()) {
623625
return NULL;
624626
}
@@ -637,7 +639,11 @@ font_getsize(FontObject* self, PyObject* args)
637639
/* Note: bitmap fonts within ttf fonts do not work, see #891/pr#960
638640
* Yifu Yu<root@jackyyf.com>, 2014-10-15
639641
*/
640-
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
642+
load_flags = FT_LOAD_NO_BITMAP;
643+
if (mask) {
644+
load_flags |= FT_LOAD_TARGET_MONO;
645+
}
646+
error = FT_Load_Glyph(face, index, load_flags);
641647
if (error) {
642648
return geterror(error);
643649
}

0 commit comments

Comments
 (0)