From 963a9ba1d1a97fc72e8c9bd65a95d2b8f0c4dd50 Mon Sep 17 00:00:00 2001 From: meehl <12648828+meehl@users.noreply.github.com> Date: Wed, 26 Aug 2026 11:59:01 +0200 Subject: [PATCH] Add comments about glyph baseline offset --- src/fonts/rasterizer.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fonts/rasterizer.rs b/src/fonts/rasterizer.rs index 3599e9f..fb48707 100644 --- a/src/fonts/rasterizer.rs +++ b/src/fonts/rasterizer.rs @@ -16,10 +16,12 @@ type SwashFontOffset = u32; #[derive(Clone, Copy, Debug, PartialEq)] pub struct CachedGlyph { + /// Size of the trimmed bitmap. Swash crops away transparant rows/columns so this is smaller + /// than the glyph's full advance box. pub size: PhysicalSize, pub uv: UvRect, pub texture_layer_idx: u32, - // offset from top/left to baseline + /// Offset from the glyph's origin (top-left) to the trimmed bitmap's top-left corner. pub baseline_offset: PhysicalVector, } @@ -164,6 +166,7 @@ impl GlyphRasterizer { size: glyph_size, uv: atlas_uv, texture_layer_idx: atlas_layer_idx, + // swash uses `Origin::BottomLeft` so we need to negate the vertical component baseline_offset: PhysicalVector::new(image.placement.left, -image.placement.top), }; cached_glyphs.insert(glyph_key, Some(cached_glyph));