Skip to content

Don't require individual tuple encapsulation in fontforge.font.bitmapSizes setter#5138

Merged
skef merged 1 commit intofontforge:masterfrom
nabijaczleweli:master
Jan 10, 2024
Merged

Don't require individual tuple encapsulation in fontforge.font.bitmapSizes setter#5138
skef merged 1 commit intofontforge:masterfrom
nabijaczleweli:master

Conversation

@nabijaczleweli
Copy link
Copy Markdown
Contributor

@nabijaczleweli nabijaczleweli commented Nov 10, 2022

Documentation specs that this should take the same format as font.bitmapSizes returns: it doesn't;

>>> f.bitmapSizes = ((1,), (2,))

yields

>>> f.bitmapSizes
(1, 2)

Which is fun, but what actually happens is the user gets

>>> f.bitmapSizes = (1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: new style getargs format but argument is not a tuple

and gives up, as in #5137. This is also, obviously, not reversible, unlike specced.

The new behaviour is congruent with the documentation (error cases included at the end):

(sid-with-nab ff)root@tarta:/srv/fontforge/build# bin/fontforge -
Copyright (c) 2000-2022. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20220308
 Based on sources from 2022-11-10 01:12 UTC-ML-D-GDK3.
 Based on source from git with hash: 8ce3216d492d4a249ffec163c005d098df28e58c
>>> f=fontforge.font()
>>> f.bitmapSizes = (16, 32, 64, 128)
Number out of range: 2.14748e+09 in type2 output (must be [-65536,65535])
>>> f.bitmapSizes
(16, 32, 64, 128)
>>> f.bitmapSizes = ()
>>> f.bitmapSizes
()
>>> f.bitmapSizes = (48,)
Number out of range: 2.14748e+09 in type2 output (must be [-65536,65535])
>>> f.bitmapSizes
(48,)
>>>
>>>
>>> f.bitmapSizes = (48,())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object cannot be interpreted as an integer
>>> f.bitmapSizes = 48
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: ../Objects/tupleobject.c:172: bad argument to internal function

idk what the ERANGEs are but they're unrelated

Type of change

Comment thread fontforge/python.c
sizes = malloc((cnt+1)*sizeof(int));
for ( i=0; i<cnt; ++i ) {
if ( !PyArg_ParseTuple(PyTuple_GetItem(value,i),"i", &sizes[i])) {
sizes[i] = PyLong_AsLong(PyTuple_GetItem(value,i));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the issue, but will break the existing scripts for those who managed to figure out this peculiarity.

On one hand, preserving existing state has merits, but on the other hand we do break things from time to time, like when migrating to Python3 or updating AGL for new fonts.

@skef, what do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm fine with standardizing on flat ints but the code should still accept the singleton tuples in case scripts have relied on that behavior. It's not that hard to code that way.

…Sizes setter

Documentation specs that this should take the same format as
font.bitmapSizes returns: it doesn't;
  >>> f.bitmapSizes = ((1,), (2,))
yields
  >>> f.bitmapSizes
  (1, 2)

Which is fun, but what actually happens is the user gets
  >>> f.bitmapSizes = (1, 2)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  SystemError: new style getargs format but argument is not a tuple
and gives up.

Closes: #5137
@nabijaczleweli
Copy link
Copy Markdown
Contributor Author

Updated to allow both

>>> f=fontforge.font()
>>> f.bitmapSizes = (16, 32, 64, 128)
>>> f.bitmapSizes = ((32,), (64,), (128,), (256,))

Copy link
Copy Markdown
Contributor

@skef skef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@skef skef merged commit 5dcdbe1 into fontforge:master Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants