From 80d4728400277774298d64c4bcfe7c46016cc25f Mon Sep 17 00:00:00 2001 From: Billy Messenger <60663878+BillyDM@users.noreply.github.com> Date: Sun, 21 Jul 2024 17:26:56 -0500 Subject: [PATCH] add scale field to CustomGlyphInput --- examples/custom-glyphs.rs | 5 +++-- src/text_render.rs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/custom-glyphs.rs b/examples/custom-glyphs.rs index 7098cbf..3223137 100644 --- a/examples/custom-glyphs.rs +++ b/examples/custom-glyphs.rs @@ -105,10 +105,11 @@ async fn run() { _ => return None, }; - // Calculate the scale based on the "font size". + // Calculate the scale based on the "glyph size". + let glyph_size = input.size * input.scale; let svg_size = svg.size(); let max_side_len = svg_size.width().max(svg_size.height()); - let scale = input.size / max_side_len; + let scale = glyph_size / max_side_len; // Create a buffer to write pixels to. let width = (svg_size.width() * scale).ceil() as u32; diff --git a/src/text_render.rs b/src/text_render.rs index 1c1fcca..0be92af 100644 --- a/src/text_render.rs +++ b/src/text_render.rs @@ -171,6 +171,7 @@ impl TextRenderer { let input = CustomGlyphInput { id: glyph.id, size: glyph.size, + scale: text_area.scale, x_bin: cache_key.x_bin, y_bin: cache_key.y_bin, }; @@ -537,8 +538,10 @@ fn zero_depth(_: usize) -> f32 { pub struct CustomGlyphInput { /// The unique identifier of the glyph. pub id: crate::CustomGlyphID, - /// The size of the glyph. + /// The size of the glyph in points (not scaled by the text area's scaling factor) pub size: f32, + /// The scaling factor applied to the text area. + pub scale: f32, /// Binning of fractional X offset pub x_bin: cosmic_text::SubpixelBin, /// Binning of fractional Y offset