From f2d21425a353728fa69680eff24421cce22981de Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 20 Apr 2023 17:31:58 -0600 Subject: [PATCH] [VarC/subset] Support subsetting VarComposites By renumbering components. --- src/OT/glyf/SubsetGlyph.hh | 15 +++++++++++++-- src/OT/glyf/VarCompositeGlyph.hh | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/OT/glyf/SubsetGlyph.hh b/src/OT/glyf/SubsetGlyph.hh index deac1212f..26dc374ea 100644 --- a/src/OT/glyf/SubsetGlyph.hh +++ b/src/OT/glyf/SubsetGlyph.hh @@ -46,19 +46,30 @@ struct SubsetGlyph if (unlikely (!dest_glyph.length)) return_trace (true); - /* update components gids. TODO: VarComposite. */ + /* update components gids. */ for (auto &_ : Glyph (dest_glyph).get_composite_iterator ()) { hb_codepoint_t new_gid; if (plan->new_gid_for_old_gid (_.get_gid(), &new_gid)) const_cast (_).set_gid (new_gid); } +#ifndef HB_NO_VAR_COMPOSITES + for (auto &_ : Glyph (dest_glyph).get_var_composite_iterator ()) + { + hb_codepoint_t new_gid; + if (plan->new_gid_for_old_gid (_.get_gid(), &new_gid)) + const_cast (_).set_gid (new_gid); + } +#endif #ifndef HB_NO_BEYOND_64K auto it = Glyph (dest_glyph).get_composite_iterator (); if (it) { - /* lower GID24 to GID16 in components if possible. TODO: VarComposite. */ + /* lower GID24 to GID16 in components if possible. + * + * TODO: VarComposite. Not as critical, since VarComposite supports + * gid24 from the first version. */ char *p = it ? (char *) &*it : nullptr; char *q = p; const char *end = dest_glyph.arrayZ + dest_glyph.length; diff --git a/src/OT/glyf/VarCompositeGlyph.hh b/src/OT/glyf/VarCompositeGlyph.hh index f543eff2b..189122bed 100644 --- a/src/OT/glyf/VarCompositeGlyph.hh +++ b/src/OT/glyf/VarCompositeGlyph.hh @@ -71,6 +71,14 @@ struct VarCompositeGlyphRecord return StructAfter (numAxes); } + void set_gid (hb_codepoint_t gid) + { + if (flags & GID_IS_24BIT) + StructAfter (numAxes) = gid; + else + StructAfter (numAxes) = gid; + } + unsigned get_numAxes () const { return numAxes;