-
Notifications
You must be signed in to change notification settings - Fork 19
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
[ufonormalizer] use repr() to stringify float; don't round to 10 digits #26
Conversation
Seems like a good change to me, but I'd like to hear from @typesupply. |
ops, sorry yes I'll do that. |
I'm no longer sure this is a good idea... Let's think about it a bit it more. |
ok, I just fixed the tests -- and convinced myself again that using |
Hm. I'm torn on this. The use of As far as the 10 digit limitation goes, I did that on purpose. Not every environment is going to have the same level of precision. Besides, we're making fonts on a pretty coarse grid. The difference between 0.0000000001 and 0.00000000005 is extremely small in practice. You can crank it up to 17 if you want, but it's going to make UFO file sizes bigger for a tiny gain in precision. |
^ I thought the same as the second paragraph here, FWIW. |
Now, I don't disagree that the discrepancy between versions is embarrasing, too. |
I may have contributed to create a bit of confusion around this float strings issue. Let me try to clarify it again. The problem I see in the ufonormalizer has not to do with the difference between python 2 and 3's That was indeed an issue in ufoLib, since the latter was using the The issue I'm trying to solve here, by replacing a fixed number of decimal digits with However, I think it should be left to the user to decide whether and how much to round floats. I believe that there are situations when you don't want to have any rounding, e.g. when you want to ensure that conditions that hold before floats have been serialized to a .glif file will still hold by the time these float strings are converted back to float numbers upon reading the file. The built-in The UFO spec (rightly) leaves the door open to float numbers of arbitrary precision. The choice of 10 decimal positions, while I agree it's sensible and reasonable, it's still arbitrary nonetheless. |
I'd like to reiterate my point above, especially considering that a similar PR was merged in the reference ufoLib implementation, so there's now a discrepancy between the way the latter and the ufoNormalizer treat float strings: unified-font-object/ufoLib#20 |
ufoLib is not a normalizer. The normalization guidelines are not requirements. Editors can do whatever they want within the parameters of the UFO specification. The point of the normalizer is to take output from two environments and ensure that they are consistent to a certain level of precision. Here's an example:
Unbeknownst to Designers A and B, Editor 2 writes over all GLIF files, regardless of if the represented glyph has changed or not, and the language that Editor 2 is written in outputs floats differently that the language used by Editor 1. So, instead of "0.1" the transformation is now "0.10000000000000001". The designers then have a noisy, pointless diff. Mutliply this by N number of components in N number of fonts and it's a lot of unnecessary noise. Insert normalization between the editors and the repository and these differences are abstracted away. I completely understand your desire for roundtripping unlimited precision in the abstract. I'm a precision-to-the-max guy myself. However, I'm not sure that the increased precision for some edge cases outweighs the effect of increasing the float length for all UFOs. I know that Perhaps precision could be specified like this: normalizeUFO("path/to/my.ufo", floatPrecision=10) # the default
normalizeUFO("path/to/my.ufo", floatPrecision=1000) # mega precise!
normalizeUFO("path/to/my.ufo", floatPrecision=None) # use repr This would need to be worked into the guts of the normalizer, but that shouldn't be too hard. Just to reiterate my position on the overall outlook for the UFO: I'm significantly more concerned about keeping the main UFO workflow working smoothly for daily common use. If an edge case can be handled without causing unnecessary effects in common use cases, that's great. If not, I prefer opt-out arguments than can be used by designers seeking specific handling of unusual situations. To be honest, I'm seeing more and more edge case handling and invalid data ignoring being pushed into the workflow at the potential expense of most users and it's making me very nervous. I'd like to try to make these slopes a lot less slippery rather than more. |
Thank you, Tal. I understand your point. I'll add a About the "ufoLib is not a normalizer', I wonder.. wouldn't it be desirable if ufoLib and the ufoNormalizer produced the same output, so that when one uses ufoLib to write a UFO, one would not need to do any normalization? |
also, convert scientific-notation floats to fixed-point notation See unified-font-object/ufoLib#19
the default is the same as the current (10 decimal digits). If value is None, then no rounding occurs and repr() is used I had to use a global variable as I couldn't find a nice way to propagate the option down to xmlConvertFloat, as it's used all over the places...
I just added a |
This looks good. Thanks!
Ideally, but we don't have control over the entire toolchain that ufoLib is built on. There are probably lots of things deep in the standard library's plistlib that vary from our desired normalization. We should try to keep as much as we can in ufoLib in sync, though. |
See unified-font-object/ufoLib#19