From e711e305c8d59b9e381e9bf7aa7fd7f85d5008b7 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 4 May 2023 18:47:55 +0000 Subject: [PATCH] [subset] Add new subsetting API method to receive a user specified glyph mapping. --- src/hb-subset-input.cc | 16 ++++++++++++++++ src/hb-subset-input.hh | 1 + src/hb-subset.h | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/src/hb-subset-input.cc b/src/hb-subset-input.cc index 5f001ac25..66feef1b1 100644 --- a/src/hb-subset-input.cc +++ b/src/hb-subset-input.cc @@ -520,6 +520,22 @@ hb_subset_preprocess (hb_face_t *source) return new_source; } +HB_EXTERN hb_bool_t +hb_subset_input_set_old_to_new_glyph_mapping (hb_subset_input_t *input, + const hb_map_t* mapping) +{ + hb_set_t new_gids; + for (auto gid : mapping->values()) + { + // Mapping cannot map multiple old gids to the same new gid. + if (new_gids.has(gid)) return false; + new_gids.add(gid); + } + + input->glyph_map = *mapping; + return true; +} + #ifdef HB_EXPERIMENTAL_API /** * hb_subset_input_override_name_table: diff --git a/src/hb-subset-input.hh b/src/hb-subset-input.hh index 1550e8b2c..1970f795b 100644 --- a/src/hb-subset-input.hh +++ b/src/hb-subset-input.hh @@ -119,6 +119,7 @@ struct hb_subset_input_t bool force_long_loca = false; hb_hashmap_t axes_location; + hb_map_t glyph_map; #ifdef HB_EXPERIMENTAL_API hb_hashmap_t name_table_overrides; #endif diff --git a/src/hb-subset.h b/src/hb-subset.h index 41d958705..84f4e76ba 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -172,6 +172,11 @@ hb_subset_input_pin_axis_location (hb_subset_input_t *input, hb_tag_t axis_tag, float axis_value); +HB_EXTERN hb_bool_t +hb_subset_input_set_old_to_new_glyph_mapping (hb_subset_input_t *input, + const hb_map_t* mapping); + + #ifdef HB_EXPERIMENTAL_API HB_EXTERN hb_bool_t hb_subset_input_override_name_table (hb_subset_input_t *input,