From afb453dc31de8241553f3964d8f8cf93af758d6a Mon Sep 17 00:00:00 2001 From: Matthias Gabriel Date: Wed, 20 Mar 2024 07:59:37 +0100 Subject: [PATCH] fix bug on text rendering --- src/tools/text.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/text.rs b/src/tools/text.rs index 2741853..99ff584 100644 --- a/src/tools/text.rs +++ b/src/tools/text.rs @@ -39,9 +39,12 @@ impl Drawable for Text { let mut paint: Paint = self.style.into(); paint.set_font(&[font]); - let font_metrics = canvas.measure_font(&paint)?; + // get some metrics + let canva_scale = canvas.transform().average_scale(); + let canvas_offset_x = canvas.transform()[4]; + let canvas_width = canvas.width() as f32; - let width = (canvas.width() as f32) / canvas.transform().average_scale() - self.pos.x; + let width = canvas_width / canva_scale - self.pos.x - canvas_offset_x; let mut y = self.pos.y; let mut metrics = Vec::::new(); @@ -53,7 +56,7 @@ impl Drawable for Text { metrics.push(text_metrics); } } - + let font_metrics = canvas.measure_font(&paint)?; if self.editing { // GTK is working with UTF-8 and character positions, pango is working with UTF-8 but byte positions. // here we transform one into the other!