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

Fixes issue #688: [tx] subroutinizing with -no_futile may make font larger than without #704

Merged
merged 18 commits into from
Jan 14, 2019

Conversation

blueshade7
Copy link
Contributor

@blueshade7 blueshade7 commented Dec 19, 2018

The original futile subroutine removal option was implemented as a multi-phase subroutine assignment process, where futile (zero/single-use) subroutines are detected & removed after each assignment, then reiterated until there are no more futile subroutines. While this implementation generally makes the result smaller with fonts of size < 30MB, it was observed to make a subroutinized result of a very large font (> 150MB) larger than without the option. This behavior can be explained as a sub-optimal assignment with a smaller set of subroutines after each iteration.

In this PR, the futile subroutine removal is re-implemented as a straight-forward logic. After the first subroutine assignment, detected single-use subroutines are inlined and removed along with zero-use. A call list is used to record subroutine calls made by each charstring or subroutine (previously, a subroutinized charstring/subroutine was generated immediately after assignment so calls were recorded only temporarily). After building call lists for all charstrings and (tentative) subroutines, futile subroutines are removed, remaining subroutines are renumbered (to fill gaps left by futile), then reordered by their actual use counts.

Although the new futile removal logic makes a difference with a very large font only, the new code appears to make subroutinized fonts often smaller than before due to the extra reordering step as a by-product.

tx -no_futile option has been deprecated. The new behavior is always enabled with +S.

No test case is added for the original problem which is seen with a very large font as it is too much for a build check. An expected result SourceCodeVar-Roman_CFF2_subr for an existing test case tx_test.py::test_cff2_extract has been updated with a new result.

1. treat CFF2 subroutines the same as CFF1 tail subroutines, because CFF2 has no return
2. modified buildCallList to list up subroutine candidates by savings, not by mere lengths. there may be slight differences between the two (when hinted, subr number size differ)
3. qsort comp function cmpSubrLengths was not sorting subrs by smallest ofset first as the second key despite the comment. fixed it, and renamed comp function to cmpSubrSavings
fixed sorting by offset in cmpSubrLengths
Copy link
Contributor

@cjchapman cjchapman left a comment

Choose a reason for hiding this comment

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

This looks OK to me, but given the extent of the changes, I'd definitely like @readroberts to review as well before we merge.

Copy link
Contributor

@readroberts readroberts left a comment

Choose a reason for hiding this comment

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

This is a good solution. Glad you were able to work on this. I see how this works, but it would have taken me a lot longer.

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.

4 participants