-
Notifications
You must be signed in to change notification settings - Fork 448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[t2CharStringPen] add "roundTolerance" option #804
Conversation
…argument Rounding of coordinates is now disabled by default. The pen now accepts an optional 'roundTolerance' float, with values between 0 and 1 (default is 0). Values >= 0.5 mean round all coordinates to integers. Values between 0 and 0.5 mean round only when the absolute difference between the original float and the rounded integer is within the tolerance Fixes fonttools#769
I think the default should remain rounding behavior and that the new behavior should be explicitly turned on. |
Yeah, initially I also thought it'd better to keep the current default, but then got carried away :) Shall I assert the tolerance is comprised between 0 and 0.5? Values between 0.5 and 1.0 don't make much sense.. |
…Tolerance hmtx only can have integer values, so it would be weird to have widths as float in CFF...
abs ends up calling fabs for floats anyway, and is a bit faster if 'number' is an int
No, please don't assert tolerance. I like to be able to say "UPEM * .005" for example and that should work. Assertions are for other things: for when the input is wrong. Which is not the case here. |
I'm confused. I'm using the built in round() to convert float to int. The maximum tolerance (which I define as the max absolute difference between the rounded and unrounded values) is 0.5, and couldn't be greater.. Am I'm missing something? |
@@ -77,7 +76,7 @@ def _round(number): | |||
# return rounded integer if the tolerance is 0.5, or if the absolute | |||
# difference between the original float and the rounded integer is | |||
# within the tolerance | |||
if tolerance == .5 or fabs(rounded - number) <= tolerance: | |||
if tolerance == .5 or abs(rounded - number) <= tolerance: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just make this "tolerance >= .5"
Correct. Which means rounding is an acceptable solution for any user-specified tolerance >= .5. A tolerance of 1.5 is NOT by any means an error. |
Ok, I got it. Thanks |
I went for the easy route, and simply added a
roundTolerance
argument to theT2CharStringPen
as @behdad was discussing in #769.I personally think that doing more clever things would be a bit beyond the scope of fontTools.
But I'm happy to be convinced otherwise ;)
PTAL, thanks