Repository navigation
Conversation
23b2e18 to
aabb26a
Compare
Looks to me like |
|
Er, yes..? The test passes (even on On $ uv pip install -e .
$ uv run python
Python 3.14.6 (main, Jun 11 2026, 03:55:33) [Clang 22.1.3 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import ImageFont
>>> f = ImageFont.load_default()
>>> f.font.getsize(bytearray(b"f"))
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
f.font.getsize(bytearray(b"f"))
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes
>>>even though the typings say they should be accepted: ~/b/Pillow (main) $ grep -C2 getsize src/PIL/_imagingft.pyi
def getsize(
self,
string: str | bytes | bytearray, |
|
Oh, right, most PR tests fail without the other changes, but that was not your intention here. |
030e19a to
6428532
Compare
e918a3a to
5bcbe16
Compare
9e51b32 to
a403f4c
Compare
You've initialized Lines 227 to 231 in 0253ef0 But you are ensuring that it is always populated from Python bcause you are concerned about someone writing future code that isn't aware that it might be |
I can re-add the |
aa3dd08 to
54b8025
Compare
|
Rebased... |
| int index, x_offset, x_advance, y_offset, y_advance; | ||
| unsigned int cluster; | ||
| unsigned int index; // the index of the glyph in the font file | ||
| FT_F26Dot6 x_offset; // horizontal movement of the glyph from current point |
There was a problem hiding this comment.
In raqm, this is an int, whereas FT_F26Dot6 is a signed long?
There was a problem hiding this comment.
That should be fine. signed long is wider than int, so this is just a widening. The whole point here is to make it obvious to the reader that these are 26.6 units, as that was the source of the bugs fixed in the followup #9909.
|
Merged I'd like to rebase this to clean the history up, though. |
|
Ok, rebase if you would like. |
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
| /* round a 26.6 pixel coordinate to the nearest integer */ | ||
| #define PIXEL(x) ((((x) + 32) & -64) >> 6) | ||
| /* convert from pixels to 26.6 fixed-point */ | ||
| #define PIXEL_TO_FIXED(x) ((x) * 64) |
There was a problem hiding this comment.
Just for the record, is there any reason you didn't include roundf in here? It is used every time this is called.
There was a problem hiding this comment.
This helper is just a type converter, it doesn't feel right that it should round too.
|
I've just pushed a commit to use https://freetype.org/freetype2/docs/reference/ft2-sizing_and_scaling.html#ft_size_requestrec lists
So not all 26.6 values are |
Yeah, FreeType doesn't seem to be totally internally consistent about these. |
|
I've merged the type hint updates in #10526 As far as the variable types, the updates here are a form of documentation, rather than being made to reflect reality. I've highlighted points where this disagrees with Raqm and with FreeType. If you'd like to changes the types here, I'd suggest convincing those projects to update them the first. |
|
Alright. The variable types will be updated comprehensively towards reality in #9909 anyhow. It'll just be a couple commits longer to review. |
Refs #9898 - had to figure out what's happening in
_imagingftto get to the bottom of the kerning woes, and these came out of that. The actual bugfixes will be in another PR stacked on this.Basically:
FT_F26Dot6type (an alias tolong, since C doesn't have real newtypes, more's the shame) to make it more obvious to the reader.* 64s or<< 6s. Not truly type-safe since, well, see above about newtypes, but better than throwing magic numbers around.getfont()'s signature to make all arguments required (C interface is internal #9879 in mind, that should be fine to do), since callinggetfont()without encoding could handily segfault (sinceencodingin C was left uninitialized, set to stack garbage)._imagingft.pyi's types to match the reality of the module.