Skip to content

Commit

Permalink
Merge pull request #65 from gabm/fix-text-renderig
Browse files Browse the repository at this point in the history
Fix text renderig
  • Loading branch information
gabm authored Mar 20, 2024
2 parents 4471469 + bd72ca0 commit a2675b0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/tools/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<TextMetrics>::new();

Expand All @@ -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!
Expand Down

0 comments on commit a2675b0

Please sign in to comment.