From 5dd22a240dd3df24b467c7d984d6a300e731ee9b Mon Sep 17 00:00:00 2001 From: Henrik Lievonen Date: Sun, 12 Nov 2023 18:41:01 +0200 Subject: [PATCH] feat: Add old_to_new_glyph_mapping to SubsetInput --- src/subset.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/subset.rs b/src/subset.rs index 53859f7..8b18300 100644 --- a/src/subset.rs +++ b/src/subset.rs @@ -1,6 +1,6 @@ use std::ops::{Deref, DerefMut}; -use crate::{sys, AllocationError, CharSet, FontFace, Set, SubsettingError, TagSet, U32Set}; +use crate::{sys, AllocationError, CharSet, FontFace, Map, Set, SubsettingError, TagSet, U32Set}; /// A description of how a font should be subset. /// @@ -173,6 +173,27 @@ impl SubsetInput { } } + /// Returns a map which can be used to provide an explicit mapping from old to new glyph id's in the produced + /// subset. The caller should populate the map as desired. If this map is left empty then glyph ids will be + /// automatically mapped to new values by the subsetter. If populated, the mapping must be unique. That is no two + /// original glyph ids can be mapped to the same new id. Additionally, if a mapping is provided then the retain gids + /// option cannot be enabled. + /// + /// Any glyphs that are retained in the subset which are not specified in this mapping will be assigned glyph ids + /// after the highest glyph id in the mapping. + /// + /// Note: this will accept and apply non-monotonic mappings, however this may result in unsorted Coverage tables. + /// Such fonts may not work for all use cases (for example ots will reject unsorted coverage tables). So it's + /// recommended, if possible, to supply a monotonic mapping. + #[doc(alias = "hb_subset_input_old_to_new_glyph_mapping")] + pub fn old_to_new_glyph_mapping(&mut self) -> Map<'_, u32, u32> { + unsafe { + Map::from_raw(sys::hb_map_reference( + sys::hb_subset_input_old_to_new_glyph_mapping(self.as_raw()), + )) + } + } + /// Subsets a font according to provided input. #[doc(alias = "hb_subset_or_fail")] pub fn subset_font(&self, font: &FontFace<'_>) -> Result, SubsettingError> { @@ -434,6 +455,12 @@ mod tests { // Currently just assuming [empty], f, i, fi, ffi, and ff } + #[test] + #[ignore] + fn old_to_new_glyph_mapping() { + todo!() + } + #[test] fn convert_into_raw_and_back() { let subset = SubsetInput::new().unwrap();