[instancer] Recalc avgcharwidth after instancing

pull/4487/head
Qunxin Liu 1 year ago committed by Behdad Esfahbod
parent d053426bb4
commit d550e16acc
  1. 22
      src/hb-ot-os2-table.hh
  2. 1
      src/hb-subset.cc
  3. BIN
      test/subset/data/expected/apply_cvar_delta/Comfortaa-Regular-new.default.retain-all-codepoint.wght=300.ttf
  4. BIN
      test/subset/data/expected/apply_cvar_delta/Comfortaa-Regular-new.default.retain-all-codepoint.wght=700.ttf
  5. BIN
      test/subset/data/expected/apply_cvar_delta/Muli-ABC.default.retain-all-codepoint.wght=300.ttf
  6. BIN
      test/subset/data/expected/apply_cvar_delta/Muli-ABC.default.retain-all-codepoint.wght=700.ttf
  7. BIN
      test/subset/data/expected/empty_region_vardata/RobotoFlex-Variable.ABC.default.retain-all-codepoint.wght=200-300,opsz=14.ttf
  8. BIN
      test/subset/data/expected/empty_region_vardata/RobotoFlex-Variable.ABC.default.retain-all-codepoint.wght=400,wdth=100,opsz=14.ttf
  9. BIN
      test/subset/data/expected/feature_variation_instance_collect_lookups/AnekBangla-question-subset.default.retain-all-codepoint.wdth=112.5.ttf
  10. BIN
      test/subset/data/expected/feature_variations_partial_instance/NotoSansOriya-subset.default.retain-all-codepoint.wdth=75.ttf
  11. BIN
      test/subset/data/expected/feature_variations_partial_instance/NotoSansOriya-subset.keep-all-layout-features.retain-all-codepoint.wdth=75.ttf
  12. BIN
      test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=150,wdth=80.ttf
  13. BIN
      test/subset/data/expected/full_instance/Roboto-Variable.default.retain-all-codepoint.wght=300,wdth=90.ttf
  14. BIN
      test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=150,wdth=80.ttf
  15. BIN
      test/subset/data/expected/full_instance/Roboto-Variable.no-prune-unicode-ranges.retain-all-codepoint.wght=300,wdth=90.ttf
  16. BIN
      test/subset/data/expected/gdef_partial_instance/AnekBangla-subset.default.retain-all-codepoint.wght=300.ttf
  17. BIN
      test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.ABC.default.retain-all-codepoint.wght=200-300-500,wdth=80-90.ttf
  18. BIN
      test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.ABC.default.retain-all-codepoint.wght=300-600,wdth=85.ttf
  19. BIN
      test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.composite.default.retain-all-codepoint.wght=200-300-500,wdth=80-90.ttf
  20. BIN
      test/subset/data/expected/glyf_partial_instancing/Roboto-Variable.composite.default.retain-all-codepoint.wght=300-600,wdth=85.ttf
  21. BIN
      test/subset/data/expected/instance_feature_variations/MPLUS1-Variable.default.30DD.wght=100.ttf
  22. BIN
      test/subset/data/expected/instance_feature_variations/MPLUS1-Variable.default.30DD.wght=400.ttf
  23. BIN
      test/subset/data/expected/instance_no_double_free/Handjet.default.retain-all-codepoint.wght=100,ELGR=1,ELSH=2.ttf
  24. BIN
      test/subset/data/expected/instance_no_double_free/Handjet.notdef-outline.retain-all-codepoint.wght=100,ELGR=1,ELSH=2.ttf
  25. BIN
      test/subset/data/expected/instantiate_cff2/AdobeVFPrototype.default.retain-all-codepoint.wght=650,CNTR=50.otf
  26. BIN
      test/subset/data/expected/instantiate_cff2_update_metrics/Cantarell-VF-ABC.default.retain-all-codepoint.wght=800.otf
  27. BIN
      test/subset/data/expected/instantiate_cff2_update_metrics/Cantarell-VF-ABC.retain-gids.retain-all-codepoint.wght=800.otf
  28. BIN
      test/subset/data/expected/instantiate_colrv1/Foldit.default.retain-all-codepoint.wght=900.ttf
  29. BIN
      test/subset/data/expected/instantiate_glyf/Roboto-Variable.ABC.default.retain-all-codepoint.wght=200,wdth=90.ttf
  30. BIN
      test/subset/data/expected/instantiate_glyf/Roboto-Variable.ABC.default.retain-all-codepoint.wght=650,wdth=85.ttf
  31. BIN
      test/subset/data/expected/instantiate_glyf/Roboto-Variable.composite.default.retain-all-codepoint.wght=200,wdth=90.ttf
  32. BIN
      test/subset/data/expected/instantiate_glyf/Roboto-Variable.composite.default.retain-all-codepoint.wght=650,wdth=85.ttf
  33. BIN
      test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=150,wdth=80,CTGR=0.ttf
  34. BIN
      test/subset/data/expected/mvar_full_instance/NotoSans-VF.abc.no-layout.retain-all-codepoint.wght=300,wdth=90,CTGR=0.ttf
  35. BIN
      test/subset/data/expected/mvar_partial_instance/NotoSans-VF.abc.default.retain-all-codepoint.wght=200-600,wdth=80-90,CTGR=20-60.ttf
  36. BIN
      test/subset/data/expected/mvar_partial_instance/NotoSans-VF.abc.default.retain-all-codepoint.wght=300-600.ttf
  37. BIN
      test/subset/data/expected/mvar_partial_instance/NotoSans-VF.abc.default.retain-all-codepoint.wght=500-800.ttf
  38. BIN
      test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=400,wdth=100.0.ttf
  39. BIN
      test/subset/data/expected/pin_all_at_default/Roboto-Variable.ABC.default.retain-all-codepoint.wght=drop,wdth=100.ttf
  40. BIN
      test/subset/data/expected/post_apply_mvar_delta/Recursive-ABC.no-layout.retain-all-codepoint.wght=400,CASL=0,CRSV=0,MONO=0,slnt=0.ttf
  41. BIN
      test/subset/data/expected/update_def_wght/SourceSerifVariable-Roman.default.retain-all-codepoint.wght=300-600.ttf
  42. BIN
      test/subset/data/expected/update_def_wght/SourceSerifVariable-Roman.default.retain-all-codepoint.wght=500-800.ttf
  43. BIN
      test/subset/data/expected/value_format_partial_instance/NotoSansOriya-valueformat-subset.default.retain-all-codepoint.wght=400.ttf
  44. BIN
      test/subset/data/expected/value_format_partial_instance/NotoSansOriya-valueformat-subset.drop-hints.retain-all-codepoint.wght=400.ttf
  45. 2
      test/subset/generate-expected-outputs.py

@ -209,6 +209,23 @@ struct OS2
return ret;
}
static unsigned calc_avg_char_width (const hb_hashmap_t<hb_codepoint_t, hb_pair_t<unsigned, int>>& 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

@ -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);

@ -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.

Loading…
Cancel
Save