From 000a3c5dca1deb811646cf94e705733f5e9ee422 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 20 Apr 2023 15:53:10 -0600 Subject: [PATCH] [beyond-64k/subset] Fetch lsb from glyph table if not available The beyond-64k hmtx table doesn't encode LSB. If subsetting brings the glyph under 64k (which currently is the only mode we support), then we need to encode the LSB, which wasn't available. We need to fetch xMin from glyf table and set it as LSB. --- src/OT/glyf/Glyph.hh | 1 + src/OT/glyf/glyf.hh | 9 +++++++++ src/hb-ot-font.cc | 16 ---------------- src/hb-ot-hmtx-table.hh | 6 +++++- src/hb-static.cc | 23 +++++++++++++++++++++++ 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/OT/glyf/Glyph.hh b/src/OT/glyf/Glyph.hh index 22887306c..5dec0ea26 100644 --- a/src/OT/glyf/Glyph.hh +++ b/src/OT/glyf/Glyph.hh @@ -515,6 +515,7 @@ struct Glyph hb_bytes_t get_bytes () const { return bytes; } glyph_type_t get_type () const { return type; } + const GlyphHeader *get_header () const { return header; } Glyph () : bytes (), header (bytes.as ()), diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index 7d2522e34..67fb5ff94 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -346,6 +346,15 @@ struct glyf_accelerator_t } #endif + bool get_leading_bearing_without_var_unscaled (hb_codepoint_t gid, bool is_vertical, int *lsb) const + { + if (unlikely (gid >= num_glyphs)) return false; + if (is_vertical) return false; // TODO Humm, what to do here? + + *lsb = glyph_for_gid (gid).get_header ()->xMin; + return true; + } + public: bool get_extents (hb_font_t *font, hb_codepoint_t gid, hb_glyph_extents_t *extents) const { diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 19ae02e28..8fda0b4ac 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -633,20 +633,4 @@ hb_ot_font_set_funcs (hb_font_t *font) _hb_ot_font_destroy); } -#ifndef HB_NO_VAR -bool -_glyf_get_leading_bearing_with_var_unscaled (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical, - int *lsb) -{ - return font->face->table.glyf->get_leading_bearing_with_var_unscaled (font, glyph, is_vertical, lsb); -} - -unsigned -_glyf_get_advance_with_var_unscaled (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical) -{ - return font->face->table.glyf->get_advance_with_var_unscaled (font, glyph, is_vertical); -} -#endif - - #endif diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 53a3e2f83..15ac9545f 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -50,6 +50,9 @@ _glyf_get_leading_bearing_with_var_unscaled (hb_font_t *font, hb_codepoint_t gly HB_INTERNAL unsigned _glyf_get_advance_with_var_unscaled (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical); +HB_INTERNAL bool +_glyf_get_leading_bearing_without_var_unscaled (hb_face_t *face, hb_codepoint_t gid, bool is_vertical, int *lsb); + namespace OT { @@ -208,7 +211,8 @@ struct hmtxvmtx if (!c->plan->old_gid_for_new_gid (_, &old_gid)) return hb_pair (0u, 0); int lsb = 0; - (void) _mtx.get_leading_bearing_without_var_unscaled (old_gid, &lsb); + if (!_mtx.get_leading_bearing_without_var_unscaled (old_gid, &lsb)) + (void) _glyf_get_leading_bearing_without_var_unscaled (c->plan->source, old_gid, !T::is_horizontal, &lsb); return hb_pair (_mtx.get_advance_without_var_unscaled (old_gid), +lsb); } return mtx_map->get (_); diff --git a/src/hb-static.cc b/src/hb-static.cc index 5f647c6ad..31acc0172 100644 --- a/src/hb-static.cc +++ b/src/hb-static.cc @@ -36,6 +36,7 @@ #include "OT/Color/COLR/COLR.hh" #include "hb-ot-glyf-table.hh" #include "hb-ot-head-table.hh" +#include "hb-ot-hmtx-table.hh" #include "hb-ot-maxp-table.hh" #ifndef HB_NO_VISIBILITY @@ -108,4 +109,26 @@ hb_face_t::load_upem () const } +#ifndef HB_NO_VAR +bool +_glyf_get_leading_bearing_with_var_unscaled (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical, + int *lsb) +{ + return font->face->table.glyf->get_leading_bearing_with_var_unscaled (font, glyph, is_vertical, lsb); +} + +unsigned +_glyf_get_advance_with_var_unscaled (hb_font_t *font, hb_codepoint_t glyph, bool is_vertical) +{ + return font->face->table.glyf->get_advance_with_var_unscaled (font, glyph, is_vertical); +} +#endif + +bool +_glyf_get_leading_bearing_without_var_unscaled (hb_face_t *face, hb_codepoint_t gid, bool is_vertical, int *lsb) +{ + return face->table.glyf->get_leading_bearing_without_var_unscaled (gid, is_vertical, lsb); +} + + #endif