Skip to content
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

[psCharStrings] Shorten output of encodeFloat #3492

Merged
merged 1 commit into from May 11, 2024
Merged

Conversation

dscorbett
Copy link
Member

@dscorbett dscorbett commented Apr 28, 2024

This optimizes fontTools.misc.psCharStrings.encodeFloat to return shorter outputs. There are three independent optimizations:

  • Use exponential notation for multiples of 1000. For example, 10000 was encoded as 1e 10 00 0f but is now 1e 1b 4f.
  • Never use a decimal point and an exponent in the same number. For example, 12345678000 was encoded as 1e 1a 23 45 67 8b 10 ff but is now 1e 12 34 56 78 b3 ff.
    • Furthermore, don’t use an exponent at all if this optimization would otherwise produce an exponent of 1. For example, 909876540 was encoded as 1e 9a 09 87 65 4b 08 ff but is now 1e 90 98 76 54 0f.
  • Remove leading zeros from exponents. For example, 100000000 was encoded as 1e 1b 08 ff but is now 1e 1b 8f.

Sometimes the new output is not shorter (e.g. 1e e1 00 0f vs. 1e e1 b3 ff) but it is never longer.

@behdad
Copy link
Member

behdad commented Apr 28, 2024

Thanks. Can you do the same in HarfBuzz's encode_num_tp function?

@behdad behdad merged commit 0738c41 into main May 11, 2024
11 checks passed
@behdad behdad deleted the optimize-encodeFloat branch May 11, 2024 01:47
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.

None yet

2 participants