Skip to content

Commit

Permalink
Merge pull request #4 from harfbuzz/cargo_skrifa
Browse files Browse the repository at this point in the history
Use a published version of skrifa
  • Loading branch information
rsheeter authored Jul 25, 2024
2 parents 4c03aec + 577da49 commit 940cc74
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 21 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ unicode-bidi-mirroring = "0.3.0"
unicode-ccc = "0.3.0"
unicode-properties = { version = "0.1.0", default-features = false, features = ["general-category"] }
unicode-script = "0.5.2"
# Use git rev to handle 'true' font header
# TODO: replace with read-fonts
skrifa = { git = "https://github.com/googlefonts/fontations", rev = "2eb4b1c" }

skrifa = "0.20" # TODO: read-fonts instead
wasmi = { version = "0.34.0", optional = true }
log = "0.4.22"

Expand Down
7 changes: 7 additions & 0 deletions src/hb/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,19 @@ impl hb_glyph_info_t {
GlyphId(self.glyph_id as u16)
}

// TODO: delete me and my bad u16 assumptions
#[inline]
pub(crate) fn as_skrifa_glyph(&self) -> skrifa::GlyphId {
debug_assert!(self.glyph_id <= u32::from(u16::MAX));
(self.glyph_id as u16).into()
}

#[inline]
pub(crate) fn as_skrifa_glyph16(&self) -> skrifa::GlyphId16 {
debug_assert!(self.glyph_id <= u32::from(u16::MAX));
(self.glyph_id as u16).into()
}

// Var allocation: unicode_props
// Used during the entire shaping process to store unicode properties

Expand Down
6 changes: 4 additions & 2 deletions src/hb/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ impl<'a> hb_font_t<'a> {
}

pub(crate) fn get_nominal_glyph(&self, c: u32) -> Option<GlyphId> {
self.font.nominal_glyph(c).map(|gid| GlyphId(gid.to_u16()))
self.font
.nominal_glyph(c)
.map(|gid| GlyphId(gid.to_u32() as u16)) // TODO: remove as u16 when fully on read-fonts GlyphId
}

pub(crate) fn glyph_variation_index(&self, c: char, vs: char) -> Option<GlyphId> {
self.font
.nominal_variant_glyph(c as u32, vs as u32)
.map(|gid| GlyphId(gid.to_u16()))
.map(|gid| GlyphId(gid.to_u32() as u16)) // TODO: remove as u16 when fully on read-fonts GlyphId
}

pub(crate) fn glyph_h_advance(&self, glyph: GlyphId) -> i32 {
Expand Down
2 changes: 1 addition & 1 deletion src/hb/fonta/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use skrifa::{
},
ReadError, TableProvider,
},
GlyphId, MetadataProvider,
GlyphId,
};
use ttf_parser::NormalizedCoordinate;

Expand Down
2 changes: 0 additions & 2 deletions src/hb/fonta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ pub mod ot;
mod font;
mod set_digest;

use set_digest::SetDigest;

pub use font::Font;
6 changes: 3 additions & 3 deletions src/hb/fonta/ot/contextual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn match_class<'a>(
|glyph, value| {
class_def
.as_ref()
.map(|class_def| class_def.get(skrifa::GlyphId::from(glyph.0)) == value)
.map(|class_def| class_def.get(skrifa::GlyphId16::new(glyph.0)) == value)
.unwrap_or(false)
}
}
Expand All @@ -69,7 +69,7 @@ impl Apply for ChainedSequenceContextFormat2<'_> {
let backtrack_classes = self.backtrack_class_def().ok();
let input_classes = self.input_class_def().ok();
let lookahead_classes = self.lookahead_class_def().ok();
let glyph = skrifa::GlyphId::from(ctx.buffer.cur(0).as_glyph().0);
let glyph = ctx.buffer.cur(0).as_skrifa_glyph16();
self.coverage().ok()?.get(glyph)?;
let index = input_classes.as_ref()?.get(glyph) as usize;
let set = self.chained_class_seq_rule_sets().get(index)?.ok()?;
Expand Down Expand Up @@ -223,7 +223,7 @@ trait ToU16: Copy {
fn to_u16(self) -> u16;
}

impl ToU16 for BigEndian<skrifa::GlyphId> {
impl ToU16 for BigEndian<skrifa::GlyphId16> {
fn to_u16(self) -> u16 {
self.get().to_u16()
}
Expand Down
8 changes: 4 additions & 4 deletions src/hb/fonta/ot/gpos/pair.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::hb::ot_layout_gpos_table::ValueRecordExt;
use crate::hb::ot_layout_gsubgpos::OT::hb_ot_apply_context_t;
use crate::hb::ot_layout_gsubgpos::{skipping_iterator_t, Apply};
use skrifa::raw::tables::gpos::{PairPosFormat1, PairPosFormat2, PairSet, PairValueRecord};
use skrifa::raw::tables::gpos::{PairPosFormat1, PairPosFormat2, PairValueRecord};
use skrifa::raw::FontData;

use super::Value;
Expand Down Expand Up @@ -104,7 +104,7 @@ fn find_second_glyph<'a>(
while lo < hi {
let mid = (lo + hi) / 2;
let record_offset = set_offset + 2 + mid * record_size;
let glyph_id = base_data.read_at::<skrifa::GlyphId>(record_offset).ok()?;
let glyph_id = base_data.read_at::<skrifa::GlyphId16>(record_offset).ok()?;
if glyph_id < second_glyph {
lo = mid + 1
} else if glyph_id > second_glyph {
Expand All @@ -119,7 +119,7 @@ fn find_second_glyph<'a>(

impl Apply for PairPosFormat2<'_> {
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
let first_glyph = ctx.buffer.cur(0).as_skrifa_glyph();
let first_glyph = ctx.buffer.cur(0).as_skrifa_glyph16();
self.coverage().ok()?.get(first_glyph)?;

let mut iter = skipping_iterator_t::new(ctx, ctx.buffer.idx, false);
Expand All @@ -132,7 +132,7 @@ impl Apply for PairPosFormat2<'_> {
}

let second_glyph_index = iter.index();
let second_glyph = ctx.buffer.info[second_glyph_index].as_skrifa_glyph();
let second_glyph = ctx.buffer.info[second_glyph_index].as_skrifa_glyph16();

let finish = |ctx: &mut hb_ot_apply_context_t, iter_index: &mut usize, has_record2| {
if has_record2 {
Expand Down
4 changes: 2 additions & 2 deletions src/hb/fonta/ot/gsub/multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ impl WouldApply for MultipleSubstFormat1<'_> {

impl Apply for MultipleSubstFormat1<'_> {
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
let glyph = ctx.buffer.cur(0).as_glyph().0;
let index = self.coverage().ok()?.get(skrifa::GlyphId::new(glyph))? as usize;
let gid = ctx.buffer.cur(0).as_skrifa_glyph16();
let index = self.coverage().ok()?.get(gid)? as usize;
let substs = self.sequences().get(index).ok()?.substitute_glyph_ids();
match substs.len() {
// Spec disallows this, but Uniscribe allows it.
Expand Down
5 changes: 3 additions & 2 deletions src/hb/fonta/ot/gsub/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ use ttf_parser::GlyphId;

impl WouldApply for SingleSubstFormat1<'_> {
fn would_apply(&self, ctx: &WouldApplyContext) -> bool {
let gid = skrifa::GlyphId::from(ctx.glyphs[0].0);
ctx.glyphs.len() == 1
&& self
.coverage()
.map(|cov| cov.get(ctx.glyphs[0].0.into()).is_some())
.map(|cov| cov.get(gid).is_some())
.unwrap_or_default()
}
}

impl Apply for SingleSubstFormat1<'_> {
fn apply(&self, ctx: &mut hb_ot_apply_context_t) -> Option<()> {
let glyph = ctx.buffer.cur(0).as_skrifa_glyph();
let glyph = ctx.buffer.cur(0).as_skrifa_glyph16();
self.coverage().ok()?.get(glyph)?;
let subst = (glyph.to_u16() as i32 + self.delta_glyph_id() as i32) as u16;
ctx.replace_glyph(GlyphId(subst));
Expand Down
3 changes: 1 addition & 2 deletions src/hb/fonta/ot/lookup_cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::hb::set_digest::{hb_set_digest_ext, hb_set_digest_t};

use super::super::SetDigest;
use alloc::vec::Vec;
use core::ops::Range;
use skrifa::raw::{
Expand Down Expand Up @@ -146,7 +145,7 @@ impl LookupCache {
let lookup_flag = lookup.lookup_flag();
entry.props = u32::from(lookup.lookup_flag().to_bits());
if lookup_flag.to_bits() & LookupFlag::USE_MARK_FILTERING_SET.to_bits() != 0 {
entry.props |= u32::from(lookup.mark_filtering_set()) << 16;
entry.props |= (lookup.mark_filtering_set().unwrap_or_default() as u32) << 16;
}
entry.is_rtl = lookup_flag.to_bits() & LookupFlag::RIGHT_TO_LEFT.to_bits() != 0;
if data.is_subst {
Expand Down

0 comments on commit 940cc74

Please sign in to comment.