From c3ec45184ad39af2c432f63069239e17976dc323 Mon Sep 17 00:00:00 2001 From: Bluekey Date: Fri, 7 Jun 2024 02:04:35 +0200 Subject: [PATCH] improved draw_text_mut performance --- src/drawing/text.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/drawing/text.rs b/src/drawing/text.rs index 3706b820..cf126df8 100644 --- a/src/drawing/text.rs +++ b/src/drawing/text.rs @@ -84,15 +84,17 @@ pub fn draw_text_mut( let image_height = canvas.height() as i32; layout_glyphs(scale, font, text, |g, bb| { + let bbx = x + bb.min.x.round() as i32; + let bby = y + bb.min.y.round() as i32; g.draw(|gx, gy, gv| { - let image_x = gx as i32 + x + bb.min.x.round() as i32; - let image_y = gy as i32 + y + bb.min.y.round() as i32; - let gv = gv.clamp(0.0, 1.0); + let image_x = gx as i32 + bbx; + let image_y = gy as i32 + bby; if (0..image_width).contains(&image_x) && (0..image_height).contains(&image_y) { let image_x = image_x as u32; let image_y = image_y as u32; let pixel = canvas.get_pixel(image_x, image_y); + let gv = gv.clamp(0.0, 1.0); let weighted_color = weighted_sum(pixel, color, 1.0 - gv, gv); canvas.draw_pixel(image_x, image_y, weighted_color); }