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

excessive number of unused lookups generated for NotoSansGrantha.glyphs #1046

Open
anthrotype opened this issue Oct 16, 2024 · 4 comments
Open
Labels
bug Something isn't working
Milestone

Comments

@anthrotype
Copy link
Member

fontc_crater reports that grantha/sources/NotoSansGrantha.glyphs's GSUB table as built by fontc is strikingly different from fontmake's:

Image

Inspecting the built fonts leads me to think this is because fontc ends up building hundreds of additional lookups that are not used nor referenced from anywhere, somehow more than 700+ lookups are just dead weight.

Try to run the following python script (which in turns uses the fonttools subsetter prune_lookups method to remove all the unused lookups in GSUB or GPOS tables) on the NotoSansGrantha font built by fontc:

https://gist.github.com/anthrotype/4facc66668c1dca9414180e4e276b922

you'll notice how the LookupList.LookupCount decreases from a whopping 830 to 114. That's a lot

-      <!-- LookupCount=830 -->
+      <!-- LookupCount=114 -->

I'm still not sure how/why this happens.

Running the same above script on the same font as generated by fontmake only gets rid of 1 lookup out of 115 in total. Much better than fontc even though not perfect.

@anthrotype anthrotype added the bug Something isn't working label Oct 16, 2024
@cmyr
Copy link
Member

cmyr commented Oct 16, 2024

There's definitely something funny going on here; our GSUB is about 190kb, versus 67.5kb for fontmake.

It might be that fontc just isn't doing 'dead lookup' analysis at all? Looking at the FEA for that font it does appear that there are a bunch of lookups that get declared but then are never added to a feature...

@rsheeter
Copy link
Contributor

Does fontmake prune layout (e.g. drop dead lookups)? Which code does that?

@rsheeter
Copy link
Contributor

our GSUB is about 190kb, versus 67.5kb for fontmake.

Strengthens case for #972 I suppose!

@anthrotype
Copy link
Member Author

Does fontmake prune layout (e.g. drop dead lookups)? Which code does that?

I don't think it explicitly does, no. Something else must be going on.

After much debugging, I think I have isolated the snippet of FEA that is generating the hundreds of seemingly unreferenced lookups in fontc (it's self contained):

@class2 = [bha_gran bha_gran.flat cha_gran da_gran dda_gran ddha_gran ga_gran ga_gran.flat h_ma_gran ha_gran ha_gran.flat j_j_nya_gran j_ja_gran j_nya_gran ja_gran k_ssa_gran k_ssa_gran.flat la_gran lla_gran m_ma_gran ma_gran n_tha_gran nga_gran nna_gran ny_cha_gran nya_gran pha_gran sa_gran ss_tta_gran ssa_gran t_tha_gran tha_gran ttha_gran ttha_gran.alt];
@class3 = [ba_gran.below bha_gran.below bha_gran.flat.below ca_gran.below cha_gran.below d_dha_gran.below d_va_gran.below da_gran.below dda_gran.below ddha_gran.below dha_gran.below ga_gran.below ga_gran.flat.below gha_gran.below h_ma_gran.below ha_gran.below ha_gran.flat.below j_ja_gran.below j_nya_gran.below ja_gran.below jha_gran.below k_ssa_gran.below k_ssa_gran.flat.below k_t_va_gran.below k_ta_gran.below k_ta_gran.flat.below ka_gran.below kha_gran.below la_gran.below lla_gran.below m_ma_gran.below ma_gran.below n_da_gran.below n_dha_gran.below n_ma_gran.below n_na_gran.below n_na_gran.flat.below n_t_va_gran.below n_ta_gran.below n_ta_gran.flat.below n_tha_gran.below n_va_gran.below na_gran.below na_gran.flat.below nga_gran.below nna_gran.below ny_ca_gran.below ny_cha_gran.below ny_ja_gran.below nya_gran.below pa_gran.below pha_gran.below ra_gran.below sa_gran.below sh_ca_gran.below sh_ra_gran.below sha_gran.below ss_tta_gran.below ssa_gran.below ssa_gran.flat.below t_ra_gran.below t_tha_gran.below t_va_gran.below ta_gran.below ta_gran.flat.below tha_gran.below tta_gran.below ttha_gran.below ttha_gran.below.alt va_gran.below ya_gran.below];
@markAttachmentSet1 = [virama_gran virama_gran.alt virama_gran.s1];
# Prefix: Languagesystems
languagesystem DFLT dflt;
languagesystem gran dflt;
languagesystem tml2 dflt;
feature abvs {
    lookupflag MarkAttachmentType @markAttachmentSet1;
    sub @class2 [virama_gran virama_gran.s1]' by virama_gran.alt;
    sub @class2 @class3' @class3' [repha_gran repha_yaPhalaa repha_yaPhalaa.alt repha_yaPhalaa.short]' [virama_gran virama_gran.s1]' by virama_gran.alt;
    sub @class2 @class3' [repha_gran repha_yaPhalaa repha_yaPhalaa.alt repha_yaPhalaa.short]' [virama_gran virama_gran.s1]' by virama_gran.alt;
    sub @class2 @class3' @class3' [virama_gran virama_gran.s1]' by virama_gran.alt;
    sub @class2 @class3' [virama_gran virama_gran.s1]' by virama_gran.alt;
    sub @class2 [repha_gran repha_yaPhalaa repha_yaPhalaa.alt repha_yaPhalaa.short]' [virama_gran virama_gran.s1]' by virama_gran.alt;
} abvs;

Fontmake only builds 7 lookups in total from the snippet above, whereas fontc builds 722, most of which never actually called upon.
I also am seeing that fontc builds a lot of extension lookups whereas fontmake manages to not build any extensions..

Maybe there's something going badly with offset overflow resolution, I don't know yet.

@rsheeter rsheeter added this to the fontc 1.0 milestone Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants