Skip to content

Commit

Permalink
feat: Add old_to_new_glyph_mapping to SubsetInput
Browse files Browse the repository at this point in the history
  • Loading branch information
henkkuli committed Nov 12, 2023
1 parent d37ee26 commit 5dd22a2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/subset.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down Expand Up @@ -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<FontFace<'static>, SubsettingError> {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5dd22a2

Please sign in to comment.