use mode for getsize

This commit is contained in:
nulano 2020-05-27 23:21:32 +02:00
parent ba58ae752c
commit 9fbd35fe87
2 changed files with 13 additions and 5 deletions

View File

@ -259,7 +259,7 @@ class FreeTypeFont:
:return: (width, height)
"""
size, offset = self.font.getsize(text, direction, features, language)
size, offset = self.font.getsize(text, False, direction, features, language)
return (
size[0] + stroke_width * 2 + offset[0],
size[1] + stroke_width * 2 + offset[1],
@ -468,7 +468,9 @@ class FreeTypeFont:
:py:mod:`PIL.Image.core` interface module, and the text offset, the
gap between the starting coordinate and the first marking
"""
size, offset = self.font.getsize(text, direction, features, language)
size, offset = self.font.getsize(
text, mode == "1", direction, features, language
)
size = size[0] + stroke_width * 2, size[1] + stroke_width * 2
im = fill("L", size, 0)
self.font.render(

View File

@ -605,6 +605,8 @@ font_getsize(FontObject* self, PyObject* args)
FT_Face face;
int xoffset, yoffset;
int horizontal_dir;
int mask = 0;
int load_flags;
const char *dir = NULL;
const char *lang = NULL;
size_t i, count;
@ -614,11 +616,11 @@ font_getsize(FontObject* self, PyObject* args)
/* calculate size and bearing for a given string */
PyObject* string;
if (!PyArg_ParseTuple(args, "O|zOz:getsize", &string, &dir, &features, &lang)) {
if (!PyArg_ParseTuple(args, "O|izOz:getsize", &string, &mask, &dir, &features, &lang)) {
return NULL;
}
count = text_layout(string, self, dir, features, lang, &glyph_info, 0);
count = text_layout(string, self, dir, features, lang, &glyph_info, mask);
if (PyErr_Occurred()) {
return NULL;
}
@ -637,7 +639,11 @@ font_getsize(FontObject* self, PyObject* args)
/* Note: bitmap fonts within ttf fonts do not work, see #891/pr#960
* Yifu Yu<root@jackyyf.com>, 2014-10-15
*/
error = FT_Load_Glyph(face, index, FT_LOAD_DEFAULT|FT_LOAD_NO_BITMAP);
load_flags = FT_LOAD_NO_BITMAP;
if (mask) {
load_flags |= FT_LOAD_TARGET_MONO;
}
error = FT_Load_Glyph(face, index, load_flags);
if (error) {
return geterror(error);
}