From d550e16acc61e8c25dbafd9f19f62b25cd4e79f1 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Mon, 6 Nov 2023 10:31:05 -0800 Subject: [PATCH] [instancer] Recalc avgcharwidth after instancing --- src/hb-ot-os2-table.hh | 22 ++++++++++++++++++ src/hb-subset.cc | 1 + ....default.retain-all-codepoint.wght=300.ttf | Bin 131708 -> 131708 bytes ....default.retain-all-codepoint.wght=700.ttf | Bin 131584 -> 131584 bytes ....default.retain-all-codepoint.wght=300.ttf | Bin 5788 -> 5788 bytes ....default.retain-all-codepoint.wght=700.ttf | Bin 5784 -> 5784 bytes ...ain-all-codepoint.wght=200-300,opsz=14.ttf | Bin 10136 -> 10136 bytes ...ll-codepoint.wght=400,wdth=100,opsz=14.ttf | Bin 6404 -> 6404 bytes ...efault.retain-all-codepoint.wdth=112.5.ttf | Bin 2668 -> 2668 bytes ...t.default.retain-all-codepoint.wdth=75.ttf | Bin 3296 -> 3296 bytes ...-features.retain-all-codepoint.wdth=75.ttf | Bin 4500 -> 4500 bytes ....retain-all-codepoint.wght=150,wdth=80.ttf | Bin 114196 -> 114196 bytes ....retain-all-codepoint.wght=300,wdth=90.ttf | Bin 114296 -> 114296 bytes ....retain-all-codepoint.wght=150,wdth=80.ttf | Bin 114196 -> 114196 bytes ....retain-all-codepoint.wght=300,wdth=90.ttf | Bin 114296 -> 114296 bytes ....default.retain-all-codepoint.wght=300.ttf | Bin 3300 -> 3300 bytes ...-codepoint.wght=200-300-500,wdth=80-90.ttf | Bin 8708 -> 8708 bytes ...ain-all-codepoint.wght=300-600,wdth=85.ttf | Bin 7592 -> 7592 bytes ...-codepoint.wght=200-300-500,wdth=80-90.ttf | Bin 7568 -> 7568 bytes ...ain-all-codepoint.wght=300-600,wdth=85.ttf | Bin 6932 -> 6932 bytes .../MPLUS1-Variable.default.30DD.wght=100.ttf | Bin 1404 -> 1404 bytes .../MPLUS1-Variable.default.30DD.wght=400.ttf | Bin 1656 -> 1656 bytes ...n-all-codepoint.wght=100,ELGR=1,ELSH=2.ttf | Bin 2224 -> 2224 bytes ...n-all-codepoint.wght=100,ELGR=1,ELSH=2.ttf | Bin 2676 -> 2676 bytes ....retain-all-codepoint.wght=650,CNTR=50.otf | Bin 41760 -> 41760 bytes ....default.retain-all-codepoint.wght=800.otf | Bin 1488 -> 1488 bytes ...ain-gids.retain-all-codepoint.wght=800.otf | Bin 1488 -> 1488 bytes ....default.retain-all-codepoint.wght=900.ttf | Bin 2488 -> 2488 bytes ....retain-all-codepoint.wght=200,wdth=90.ttf | Bin 6736 -> 6736 bytes ....retain-all-codepoint.wght=650,wdth=85.ttf | Bin 6688 -> 6688 bytes ....retain-all-codepoint.wght=200,wdth=90.ttf | Bin 6416 -> 6416 bytes ....retain-all-codepoint.wght=650,wdth=85.ttf | Bin 6368 -> 6368 bytes ...-all-codepoint.wght=150,wdth=80,CTGR=0.ttf | Bin 1396 -> 1396 bytes ...-all-codepoint.wght=300,wdth=90,CTGR=0.ttf | Bin 1432 -> 1432 bytes ...int.wght=200-600,wdth=80-90,CTGR=20-60.ttf | Bin 4300 -> 4300 bytes ...ault.retain-all-codepoint.wght=300-600.ttf | Bin 6808 -> 6808 bytes ...ault.retain-all-codepoint.wght=500-800.ttf | Bin 7288 -> 7288 bytes ...tain-all-codepoint.wght=400,wdth=100.0.ttf | Bin 6780 -> 6780 bytes ...etain-all-codepoint.wght=drop,wdth=100.ttf | Bin 6780 -> 6780 bytes ...t.wght=400,CASL=0,CRSV=0,MONO=0,slnt=0.ttf | Bin 1884 -> 1884 bytes ...ault.retain-all-codepoint.wght=300-600.ttf | Bin 305092 -> 305092 bytes ...ault.retain-all-codepoint.wght=500-800.ttf | Bin 250164 -> 250164 bytes ....default.retain-all-codepoint.wght=400.ttf | Bin 1848 -> 1848 bytes ...op-hints.retain-all-codepoint.wght=400.ttf | Bin 1824 -> 1824 bytes test/subset/generate-expected-outputs.py | 2 +- 45 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 1bf7dd52f..8c2e696f5 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -209,6 +209,23 @@ struct OS2 return ret; } + static unsigned calc_avg_char_width (const hb_hashmap_t>& hmtx_map) + { + unsigned num = 0; + unsigned total_width = 0; + for (const auto& _ : hmtx_map.values_ref ()) + { + unsigned width = _.first; + if (width) + { + total_width += width; + num++; + } + } + + return num ? (unsigned) roundf (total_width / num) : 0; + } + bool subset (hb_subset_context_t *c) const { TRACE_SUBSET (this); @@ -244,6 +261,11 @@ struct OS2 HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_X_HEIGHT, sxHeight); HB_ADD_MVAR_VAR (HB_OT_METRICS_TAG_CAP_HEIGHT, sCapHeight); } + + unsigned avg_char_width = calc_avg_char_width (c->plan->hmtx_map); + if (!c->serializer->check_assign (os2_prime->xAvgCharWidth, avg_char_width, + HB_SERIALIZE_ERROR_INT_OVERFLOW)) + return_trace (false); } #endif diff --git a/src/hb-subset.cc b/src/hb-subset.cc index de0fc590e..06e77dd8e 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -460,6 +460,7 @@ _dependencies_satisfied (hb_subset_plan_t *plan, hb_tag_t tag, case HB_OT_TAG_hmtx: case HB_OT_TAG_vmtx: case HB_OT_TAG_maxp: + case HB_OT_TAG_OS2: return !plan->normalized_coords || !pending_subset_tags.has (HB_OT_TAG_glyf); case HB_OT_TAG_GPOS: return plan->all_axes_pinned || !pending_subset_tags.has (HB_OT_TAG_GDEF); diff --git a/test/subset/data/expected/apply_cvar_delta/Comfortaa-Regular-new.default.retain-all-codepoint.wght=300.ttf b/test/subset/data/expected/apply_cvar_delta/Comfortaa-Regular-new.default.retain-all-codepoint.wght=300.ttf index 8745250d14d3cf0f7dfb18c02a5912bd3aac9071..35ad91f9517cb5542398c9795cfa35655d88cda4 100644 GIT binary patch delta 31 ncmeybKVyXcE#B~a; delta 31 ncmeyPDAtM#i_3FEHve)-^G;F)>bKVyXcE#B~a; diff --git a/test/subset/data/expected/apply_cvar_delta/Comfortaa-Regular-new.default.retain-all-codepoint.wght=700.ttf b/test/subset/data/expected/apply_cvar_delta/Comfortaa-Regular-new.default.retain-all-codepoint.wght=700.ttf index ee327056d54e4f998ce32e5d3ff37317793b3d41..6715573fd7d039ccfca219a00dbbf79d922f7d6f 100644 GIT binary patch delta 34 qcmZo@;b>^#nBdH)x6!4Vk+FF40Y-hs_T~?a?H?E!r+;8%5&!_q%L|eK delta 34 qcmZo@;b>^#nBdH)y3wVYk+F610Y-hsy5^ch!dE@4tp1ps?X2!Q|q delta 25 hcmbQ?Kf`}QFr)FtkoSy?8z;Lk=`&VtE@4tp1ps?X2!Q|q diff --git a/test/subset/data/expected/empty_region_vardata/RobotoFlex-Variable.ABC.default.retain-all-codepoint.wght=400,wdth=100,opsz=14.ttf b/test/subset/data/expected/empty_region_vardata/RobotoFlex-Variable.ABC.default.retain-all-codepoint.wght=400,wdth=100,opsz=14.ttf index 838765ef542eab53a891eae68db0d8dfe18fa36a..fd8ce121ee38629b439552913c3914ab713afd24 100644 GIT binary patch delta 25 gcmZoMYB8D+%$U6~gq?{oe{u|yKI6vCJxmp10BGC?+W-In delta 25 gcmZoMYB8D+%xJtZgq?};{^S@Yea6boJxmp10BGC?+W-In diff --git a/test/subset/data/expected/feature_variation_instance_collect_lookups/AnekBangla-question-subset.default.retain-all-codepoint.wdth=112.5.ttf b/test/subset/data/expected/feature_variation_instance_collect_lookups/AnekBangla-question-subset.default.retain-all-codepoint.wdth=112.5.ttf index 2b980d5809f7dcff7d1edec5ba41adb211f215e9..8cf54c82a2e3ac735cf606acae88d648668cd04a 100644 GIT binary patch delta 28 kcmaDO@@~E!?b`M0Gz)HJOBUy delta 28 kcmaDO@>FK@7@6vRPhP>8&&b{^!L(h1iSf^F0L`%rv;Y7A delta 32 ocmbR8hi%Fqwh7LRof}<}7@2CnPhP>8&)C^4!L(h1iSf^F0Nx@Dvj6}9 diff --git a/test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf b/test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf index 0c991335ee78af1c0ca8667364199ffbbfd7c4cd..b70db5c0bfcb74b942834f1ad84230ceb27db7a4 100644 GIT binary patch delta 31 ncmezIhwaB7wh7LRo*P|~85zG$UcuPR=+Ughv|WdZ(Ps|;-)am9 delta 31 ncmezIhwaB7wh7LRT^n7J85xTwuV8Fu>}=Ly+OEUI=(7g^-)am9 diff --git a/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=150,wdth=80.ttf b/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=150,wdth=80.ttf index ec29a1219a8d07c88ef0584ce7e3f090c4a75897..757611f922e41fe68cbf71a23bfe06adb678f4de 100644 GIT binary patch delta 32 ocmbR8hi%Fqwh7LR>>FK@7@6vRPhP>8&&b{^!L(h1iSf^F0L`%rv;Y7A delta 32 ocmbR8hi%Fqwh7LRof}<}7@2CnPhP>8&)C^4!L(h1iSf^F0Nx@Dvj6}9 diff --git a/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf b/test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf index 0c991335ee78af1c0ca8667364199ffbbfd7c4cd..b70db5c0bfcb74b942834f1ad84230ceb27db7a4 100644 GIT binary patch delta 31 ncmezIhwaB7wh7LRo*P|~85zG$UcuPR=+Ughv|WdZ(Ps|;-)am9 delta 31 ncmezIhwaB7wh7LRT^n7J85xTwuV8Fu>}=Ly+OEUI=(7g^-)am9 diff --git a/test/subset/data/expected/gdef_partial_instance/AnekBangla-subset.default.retain-all-codepoint.wght=300.ttf b/test/subset/data/expected/gdef_partial_instance/AnekBangla-subset.default.retain-all-codepoint.wght=300.ttf index b075a80b48f9d295fc170ba6502324b61f1f744f..4254ae1b845bdd9dea08c4cb71d63412b96dc789 100644 GIT binary patch delta 27 jcmaDN`9yL;Fr&@JkWY+EE-sTjn5vjq;x`{*Qs4prjyeeZ delta 27 jcmaDN`9yL;FyoJnA)gqToX$-4V5(wbmEL@WNr4Lhq9qCY diff --git a/test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.ABC.default.retain-all-codepoint.wght=200-300-500,wdth=80-90.ttf b/test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.ABC.default.retain-all-codepoint.wght=200-300-500,wdth=80-90.ttf index 9f12445fbcfea8766fc6e154516f5ad3506909dd..97cc1b2ab992cb069614adae2a16d2d44ebf0ccd 100644 GIT binary patch delta 25 hcmZp1X>pkl%(#DJh&>bI)X7trwlh|2_F>*32LOAu2|)k= delta 25 hcmZp1X>pkl%y?mAh&>Zy@#HB?+Zj7I`!Mg20|0xq2|)k= diff --git a/test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.ABC.default.retain-all-codepoint.wght=300-600,wdth=85.ttf b/test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.ABC.default.retain-all-codepoint.wght=300-600,wdth=85.ttf index a5e455b890207beb84b77898ef4fb04fdf07234e..e60233179640cd6fa8641b65c01d2eb126dcdbb5 100644 GIT binary patch delta 25 hcmZ2sy~27zFyroxA>mAn`zEhp+Rj+AIfdCp3IK#J31|QS delta 25 hcmZ2sy~27zFyn=dA>mAnQzoxr+RoUyIfdCp3IK#J31|QS diff --git a/test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.composite.default.retain-all-codepoint.wght=200-300-500,wdth=80-90.ttf b/test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.composite.default.retain-all-codepoint.wght=200-300-500,wdth=80-90.ttf index 387536ea45938dee1a68e32bd97ac06e7c0767f7..0c926c80219a7f2b01b0190e18c218affab15ed6 100644 GIT binary patch delta 26 icmbPWJ;8cHFyqsWAw^6~$qOf+U`l6vy4ip^K?(qkaS7=F delta 26 icmbPWJ;8cHFk|P&kRm3gl*q{^n9>Oum`YP8XE5n8F}>S7gXswq0HAvcegFUf delta 28 kcmeyv^@nSM5!2MQ8%>Oun2I+~&S27GVm`ik2GbKJ0HAvcegFUf diff --git a/test/subset/data/expected/instance_feature_variations/MPLUS1-Variable.default.30DD.wght=400.ttf b/test/subset/data/expected/instance_feature_variations/MPLUS1-Variable.default.30DD.wght=400.ttf index ca7a74bf75a2bd4b132a68c6494fa19abd88710c..3a49bf343908db481507cc11a0fe183dbfa29a17 100644 GIT binary patch delta 26 icmeyt^MhxCF{AoM6Coxh)$qw4Ox28zn~yMUVFmzn9|$!7 delta 26 icmeyt^MhxCG2_~eCPGY1D&CVln5r3%Z$84bg&6>Vm@Bjb+ delta 28 kcmdlWxIu7&6VtA%8(l6jGP&DMmSD@c;k- diff --git a/test/subset/data/expected/instance_no_double_free/Handjet.notdef-outline.retain-all-codepoint.wght=100,ELGR=1,ELSH=2.ttf b/test/subset/data/expected/instance_no_double_free/Handjet.notdef-outline.retain-all-codepoint.wght=100,ELGR=1,ELSH=2.ttf index e0af6862307ea92a61a02802e83ee67809f9917e..803066f32fbd20c40d10876b802fe424d1a6aa2b 100644 GIT binary patch delta 28 kcmew&@eSv#IFyp0-A?p~KgicImVbW(T*lfZyhZz8cI0(J~ delta 26 icmcb>eSv#IFypL^A?p~Kge@ksFzGW|Y&KzeSv#IFyp0-A?p~KgicImVbW(T*lfZyhZz8cI0(J~ delta 26 icmcb>eSv#IFypL^A?p~Kge@ksFzGW|Y&Kzukh#*`o?rtfDa?_knrT)6oK(*-sFlvvijVVD)Og}D6-od2LD8Kmy(*-sFn`8>- diff --git a/test/subset/data/expected/instantiate_glyf/Roboto-Variable.ABC.default.retain-all-codepoint.wght=200,wdth=90.ttf b/test/subset/data/expected/instantiate_glyf/Roboto-Variable.ABC.default.retain-all-codepoint.wght=200,wdth=90.ttf index 4294ef09c8e0f35a617ae944fca810c3d42f9ff1..7a6eed8eb731cb87ad012d588270f4888de41324 100644 GIT binary patch delta 25 hcmca$a=~PRGvn5cF8>)BT_?LRH8bXIKEc!>4giQ93A6wJ delta 25 hcmca$a=~PRGvkGgF8>)B`6s(DH8XZ@KEc!>4giQ93A6wJ diff --git a/test/subset/data/expected/instantiate_glyf/Roboto-Variable.ABC.default.retain-all-codepoint.wght=650,wdth=85.ttf b/test/subset/data/expected/instantiate_glyf/Roboto-Variable.ABC.default.retain-all-codepoint.wght=650,wdth=85.ttf index 6b247a25fd25e0930221a85883102e942fcb39d7..abda0115a6bc1fbf46986b2c14b63e81d780627c 100644 GIT binary patch delta 25 hcmZ2rvcP15GvnEfF8>)B?I*i1)BEhoD$cWP`;JadU}|POzxfH1ju-%kI|<fsuiMft#U$ftkU;KUm)=^JJ{$Mv*i|rk%o*YZ$Yb81HRfsuiMft#U$ftkU;KUm)=^JMJ8jUs7`Ogo$>*Dz)=F}ZDi!PvtL0QIK~ A8vpfsuiMft#U$ftkU;KUm)=D={{GqevPf)8+WdHH_tq?3=$ZE@1`$!$}J2 delta 43 zcmbQiJ%d|>fsuiMft#U$ftkU;KUm)=D=~K2Mv*i|rb`be*D#hdx^4c#xP%!1&wC5$ diff --git a/test/subset/data/expected/mvar_partial_instance/NotoSans-VF.abc.default.retain-all-codepoint.wght=200-600,wdth=80-90,CTGR=20-60.ttf b/test/subset/data/expected/mvar_partial_instance/NotoSans-VF.abc.default.retain-all-codepoint.wght=200-600,wdth=80-90,CTGR=20-60.ttf index d0cb79760ad7e5f204697a4f2ff93a1a9a52622e..2136b9d53d6231ac9c13440858da35a9994b2a1f 100644 GIT binary patch delta 27 jcmX@3ct&wTGGocclt+wAN=}U5AGULpRDUTT$%O-m;U5AGUMuvDUTT$gC=`0G@gviS~U11kXRx(tQ@ delta 42 ycmcb^cZW}efsuiMftR6yftew|KUm)=<;4cJjUv+-8IvZjVbo_V-h79#ffWGS%?pPB diff --git a/test/subset/data/expected/update_def_wght/SourceSerifVariable-Roman.default.retain-all-codepoint.wght=300-600.ttf b/test/subset/data/expected/update_def_wght/SourceSerifVariable-Roman.default.retain-all-codepoint.wght=300-600.ttf index 2c8f3e70992e1d9a4ebc6ae599f35b610b2c6259..c920c008e3dcb80caee9d0c08eceda5451b134a6 100644 GIT binary patch delta 43 vcmX?dUg*eqp$W;1S2m_3GcqbpKEb%2QMI{(sl9@U5r{!F^Y#iR7N4a6b-oV^ delta 43 vcmX?dUg*eqp$W;1H#VjuGcrm}KEb%2QM0*%sl9@U5r{!F^Y#iR7N4a6b-oV^ diff --git a/test/subset/data/expected/update_def_wght/SourceSerifVariable-Roman.default.retain-all-codepoint.wght=500-800.ttf b/test/subset/data/expected/update_def_wght/SourceSerifVariable-Roman.default.retain-all-codepoint.wght=500-800.ttf index f50af5275f13ce63b5333253a5c7ef3219ea82cf..7747dd108ffb38a00434c61f93f51e4c480b60bb 100644 GIT binary patch delta 38 tcmdn8h=0o>{t3y9H#ertW@L1j#I&AKt9b)c`vxXPAZFUWfr+{08~`P)4qyNP delta 38 tcmdn8h=0o>{t3y9H#VlsW@L1l#I&AKvv~tk`vxXPAZFUWfr+{08~`P(4qyNP diff --git a/test/subset/data/expected/value_format_partial_instance/NotoSansOriya-valueformat-subset.default.retain-all-codepoint.wght=400.ttf b/test/subset/data/expected/value_format_partial_instance/NotoSansOriya-valueformat-subset.default.retain-all-codepoint.wght=400.ttf index e0ff13d67802fa10757bd73d1cae6fca53b2a36c..b4a6ab74fc55ed48d6b6707cf28a336a68d2a326 100644 GIT binary patch delta 25 hcmdnNw}WqjGh^XK7hxvGyOSfBiW#{!pJB>j0RV3h2o?YU delta 25 hcmdnNw}WqjGvmFDF2YQV%#$OSiW$o{pJB>j0RV3h2o?YU diff --git a/test/subset/data/expected/value_format_partial_instance/NotoSansOriya-valueformat-subset.drop-hints.retain-all-codepoint.wght=400.ttf b/test/subset/data/expected/value_format_partial_instance/NotoSansOriya-valueformat-subset.drop-hints.retain-all-codepoint.wght=400.ttf index c50aeeafc6b230c2b6ec6ecb442dae4fbb5f316b..0e1c801f69f4139e7f9daf9092f27d18e2645f76 100644 GIT binary patch delta 26 icmZ3$w}5YgGh^XKmtTxbw~Zz{FcmX$ZQjC^!vX+)cL>b@ delta 26 icmZ3$w}5YgGvmFDF25L=ZbeLXU@B%T-@Jt>hXnwN*9pu3 diff --git a/test/subset/generate-expected-outputs.py b/test/subset/generate-expected-outputs.py index 4e375627f..477d0532a 100755 --- a/test/subset/generate-expected-outputs.py +++ b/test/subset/generate-expected-outputs.py @@ -44,7 +44,7 @@ def generate_expected_output(input_file, unicodes, profile_flags, instance_flags fonttools_path = os.path.join(tempfile.mkdtemp (), font_name) args = ["fonttools", "subset", input_path] if instance_flags: - args.extend(["--recalc-bounds"]) + args.extend(["--recalc-bounds", "--recalc-average-width"]) args.extend(["--drop-tables+=DSIG", "--drop-tables-=sbix", "--no-harfbuzz-repacker", # disable harfbuzz repacker so we aren't comparing to ourself.