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

Var store quantize #3126

Merged
merged 4 commits into from May 25, 2023
Merged

Var store quantize #3126

merged 4 commits into from May 25, 2023

Conversation

behdad
Copy link
Member

@behdad behdad commented May 24, 2023

No description provided.

@behdad
Copy link
Member Author

behdad commented May 24, 2023

Not sure if we want to set quantization higher than one by default in any fontmake-related codepath.

for regionIdx, v in zip(regionIndices, item):
row[regionIdx] += (
round(v / quantization) * quantization
) # TODO: round towards 0
Copy link
Member

Choose a reason for hiding this comment

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

why "round towards 0"?

you can use decimal.Decimal's quantize method with a ROUND_DOWN rounding method:

https://docs.python.org/3/library/decimal.html#decimal.ROUND_DOWN

though it might be quicker to simply do floor(v) if v > 0 else ceil(v)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll remove the comment. round is fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

What I meant was a round that rounds .5 to 0, such that eg. with quantization 2, value 1 will become 0, not 2.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

yeah i think as a size saving optimization this quantization should make the deltas smaller, would be strange if it made them bigger

Copy link
Member

Choose a reason for hiding this comment

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

(though the sharing comes from reuse, not the delta magnitude itself)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@anthrotype
Copy link
Member

anthrotype commented May 25, 2023

Not sure if we want to set quantization higher than one by default in any fontmake-related codepath.

I don't know, maybe an option in the public varLib.build/build_many methods that ufo2ft uses. But I'm not sure if one wants to use the same quantization (if at all) for all the VarStores (HVAR, MVAR, COLR, etc.).
What did you have in mind for this? Make GPOS variable kerning tables smaller? Did somebody request this?

@anthrotype
Copy link
Member

anthrotype commented May 25, 2023

I think it's fine to have this option available in the fonttools varLib.varStore command-line tool only for now (that one only touches GDEF VarStore as used in GPOS), one can already start experiment with it and if needed we can surface it to varLib's public api

@behdad
Copy link
Member Author

behdad commented May 25, 2023

Did somebody request this?

No. I was just inspecting some varstores in GDEFs and saw many similar values. Ie. this is the entirety of the varstore from NotoSansCJK:

      <VarData index="0">
        <!-- ItemCount=118 -->
        <NumShorts value="0"/>
        <!-- VarRegionCount=1 -->
        <VarRegionIndex index="0" value="0"/>
        <Item index="0" value="[-113]"/>
        <Item index="1" value="[-93]"/>
        <Item index="2" value="[-91]"/>
        <Item index="3" value="[-90]"/>
        <Item index="4" value="[-88]"/>
        <Item index="5" value="[-84]"/>
        <Item index="6" value="[-83]"/>
        <Item index="7" value="[-73]"/>
        <Item index="8" value="[-71]"/>
        <Item index="9" value="[-69]"/>
        <Item index="10" value="[-68]"/>
        <Item index="11" value="[-66]"/>
        <Item index="12" value="[-65]"/>
        <Item index="13" value="[-62]"/>
        <Item index="14" value="[-61]"/>
        <Item index="15" value="[-58]"/>
        <Item index="16" value="[-57]"/>
        <Item index="17" value="[-56]"/>
        <Item index="18" value="[-52]"/>
        <Item index="19" value="[-51]"/>
        <Item index="20" value="[-50]"/>
        <Item index="21" value="[-49]"/>
        <Item index="22" value="[-48]"/>
        <Item index="23" value="[-47]"/>
        <Item index="24" value="[-46]"/>
        <Item index="25" value="[-45]"/>
        <Item index="26" value="[-44]"/>
        <Item index="27" value="[-43]"/>
        <Item index="28" value="[-42]"/>
        <Item index="29" value="[-41]"/>
        <Item index="30" value="[-40]"/>
        <Item index="31" value="[-39]"/>
        <Item index="32" value="[-38]"/>
        <Item index="33" value="[-37]"/>
        <Item index="34" value="[-36]"/>
        <Item index="35" value="[-34]"/>
        <Item index="36" value="[-33]"/>
        <Item index="37" value="[-32]"/>
        <Item index="38" value="[-31]"/>
        <Item index="39" value="[-30]"/>
        <Item index="40" value="[-29]"/>
        <Item index="41" value="[-28]"/>
        <Item index="42" value="[-27]"/>
        <Item index="43" value="[-26]"/>
        <Item index="44" value="[-25]"/>
        <Item index="45" value="[-24]"/>
        <Item index="46" value="[-23]"/>
        <Item index="47" value="[-22]"/>
        <Item index="48" value="[-21]"/>
        <Item index="49" value="[-20]"/>
        <Item index="50" value="[-19]"/>
        <Item index="51" value="[-18]"/>
        <Item index="52" value="[-17]"/>
        <Item index="53" value="[-16]"/>
        <Item index="54" value="[-15]"/>
        <Item index="55" value="[-14]"/>
        <Item index="56" value="[-13]"/>
        <Item index="57" value="[-12]"/>
        <Item index="58" value="[-11]"/>
        <Item index="59" value="[-10]"/>
        <Item index="60" value="[-9]"/>
        <Item index="61" value="[-8]"/>
        <Item index="62" value="[-7]"/>
        <Item index="63" value="[-6]"/>
        <Item index="64" value="[-5]"/>
        <Item index="65" value="[-4]"/>
        <Item index="66" value="[-3]"/>
        <Item index="67" value="[-2]"/>
        <Item index="68" value="[-1]"/>
        <Item index="69" value="[1]"/>
        <Item index="70" value="[2]"/>
        <Item index="71" value="[3]"/>
        <Item index="72" value="[4]"/>
        <Item index="73" value="[5]"/>
        <Item index="74" value="[6]"/>
        <Item index="75" value="[7]"/>
        <Item index="76" value="[8]"/>
        <Item index="77" value="[9]"/>
        <Item index="78" value="[10]"/>
        <Item index="79" value="[11]"/>
        <Item index="80" value="[12]"/>
        <Item index="81" value="[13]"/>
        <Item index="82" value="[14]"/>
        <Item index="83" value="[15]"/>
        <Item index="84" value="[16]"/>
        <Item index="85" value="[17]"/>
        <Item index="86" value="[18]"/>
        <Item index="87" value="[19]"/>
        <Item index="88" value="[20]"/>
        <Item index="89" value="[21]"/>
        <Item index="90" value="[22]"/>
        <Item index="91" value="[23]"/>
        <Item index="92" value="[26]"/>
        <Item index="93" value="[27]"/>
        <Item index="94" value="[28]"/>
        <Item index="95" value="[29]"/>
        <Item index="96" value="[30]"/>
        <Item index="97" value="[31]"/>
        <Item index="98" value="[33]"/>
        <Item index="99" value="[34]"/>
        <Item index="100" value="[35]"/>
        <Item index="101" value="[36]"/>
        <Item index="102" value="[37]"/>
        <Item index="103" value="[38]"/>
        <Item index="104" value="[39]"/>
        <Item index="105" value="[40]"/>
        <Item index="106" value="[41]"/>
        <Item index="107" value="[42]"/>
        <Item index="108" value="[43]"/>
        <Item index="109" value="[44]"/>
        <Item index="110" value="[46]"/>
        <Item index="111" value="[47]"/>
        <Item index="112" value="[49]"/>
        <Item index="113" value="[52]"/>
        <Item index="114" value="[55]"/>
        <Item index="115" value="[56]"/>
        <Item index="116" value="[66]"/>
        <Item index="117" value="[95]"/>
      </VarData>

@behdad
Copy link
Member Author

behdad commented May 25, 2023

I think it's fine to have this option available in the fonttools varLib.varStore command-line tool only for now (that one only touches GDEF VarStore as used in GPOS), one can already start experiment with it and if needed we can surface it to varLib's public api

Sounds good. Thanks.

@behdad behdad merged commit 5255c01 into main May 25, 2023
7 of 8 checks passed
@behdad behdad deleted the varStore-quantize branch May 25, 2023 12:26
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