Skip to content

Commit

Permalink
add scale field to CustomGlyphInput
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyDM committed Jul 24, 2024
1 parent 8756f86 commit a5d86e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/custom-glyphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/text_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a5d86e9

Please sign in to comment.