Use FT_LOAD_TARGET_MONO in getsize#4664
Conversation
|
|
||
| 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)) { |
There was a problem hiding this comment.
Can we add the new parameter to the end, to maintain compatibility?
People have been calling ImageFont.font.getsize directly. A quick example:
font = ImageFont.truetype(fontname, fontsize)
limits = font.getsize(text)There was a problem hiding this comment.
The linked and quoted example is the Python-layer function. It looks confusing as the code refers to the FreeTypeFont object as font, but updated function would have to be called with font.font.getsize(...). The same is true for the search results in the first few pages.
There are three functions concerning the size of text (ignoring the multiline variants):
ImageDraw.Draw.textsize(...)
ImageFont.FreeTypeFont.getsize(...) # the Python version; I did not update this
ImageFont.FreeTypeFont.font.getsize(...) # the C version; updated by this PRThe equivalent code would be:
font = ImageFont.truetype(...)
font.getsize(...) # the Python function
font.font.getsize(...) # the C functionI did not update the Python function as I think it would confusing to have the arguments in a different order, but not backwards compatible to add it at the front (suggestions are welcome).
If you still think the C function is a concern, would something with PyArg_ParseTupleAndKeywords be a good solution (i.e. making all future additions kwarg only)?
There was a problem hiding this comment.
Thanks, I think we're fine to change this then. The C API is internal and doesn't need to maintain backwards compatibility.
|
Thank you! |
Fixes #4177.
Changes proposed in this pull request:
maskparameter to the internalgetsizefunction. I did not add it to the public function, as I'm not sure what is the best way to update the API in a reasonable and backwards-compatible manner.maskparameter. I did not include it in tests, as the epsilon among systems is greater than epsilon to a blank image.