EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge pull request #298 from midasdf/fix/vertical-japanese-punctuation
Brandon Thomas1f5218378cf8
diff --cc crates/text/src/fonts.rsindex 58539c660,ea2dc4f08..77a929194--- a/crates/text/src/fonts.rs+++ b/crates/text/src/fonts.rs@@@ -207,13 -207,25 +207,29 @@@ impl Facepub fn glyph(&self, c: char) -> Option<u32> {self.font()?.charmap().map(c).map(|g| g.to_u32()).filter(|g| *g != 0)}+ /// Whether the face can draw `c`: it maps `c` to a glyph that has an outline, a colour glyph+ /// or a bitmap. Some fonts map whole scripts to empty glyphs (#285); those don't count, so+ /// fallback moves on to a face that draws the character. Characters that are blank by nature+ /// (spaces, format characters) count as covered by any mapping.pub fn has_char(&self, c: char) -> bool {- self.glyph(c).is_some()+ self.font().is_some_and(|f| covers(&f, c))}+ /// Horizontal advance and vertical origin above the baseline, in pixels.+ pub(crate) fn vertical_origin(&self, gid: u32, px: f32) -> Option<(f64, f64)> {+ use skrifa::raw::TableProvider;+ let font = self.font()?;+ let glyph = skrifa::GlyphId::new(gid);+ let metrics = font.glyph_metrics(Size::unscaled(), LocationRef::default());+ let origin = match font.vorg() {+ Ok(table) => f32::from(table.vertical_origin_y(glyph)),+ Err(_) => metrics.bounds(glyph)?.y_max + f32::from(font.vmtx().ok()?.side_bearing(glyph)?),+ };+ let scale = f64::from(px / self.units_per_em());+ let width = f64::from(metrics.advance_width(glyph)?) * scale;+ let top = f64::from(origin) * scale;+ (width.is_finite() && top.is_finite() && top.abs() < f64::from(px) * 4.0).then_some((width, top))+ }+pub fn metrics(&self, px: f32) -> VMetrics {let Some(f) = self.font() else {return VMetrics {