From 3450987355be7fe029db112474d06613929b54c7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 9 Sep 2023 11:21:32 +0200 Subject: Invalidate existing paragraphs when new fonts are loaded --- graphics/src/renderer.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'graphics/src/renderer.rs') diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index f93f4a6d..d4df29a5 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -162,6 +162,29 @@ where text::Paragraph::with_text(text, self.backend.font_system()) } + fn update_paragraph( + &self, + paragraph: &mut Self::Paragraph, + text: Text<'_, Self::Font>, + ) { + let font_system = self.backend.font_system(); + + if paragraph.version() != font_system.version() { + // The font system has changed, paragraph fonts may be outdated + *paragraph = self.create_paragraph(text); + } else { + match core::text::compare(paragraph, text) { + core::text::Difference::None => {} + core::text::Difference::Bounds => { + self.resize_paragraph(paragraph, text.bounds); + } + core::text::Difference::Shape => { + *paragraph = self.create_paragraph(text); + } + } + } + } + fn resize_paragraph( &self, paragraph: &mut Self::Paragraph, -- cgit