Invalidate existing paragraphs when new fonts are loaded

This commit is contained in:
Héctor Ramón Jiménez 2023-09-09 11:21:32 +02:00
parent 837529bc99
commit 3450987355
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
6 changed files with 127 additions and 33 deletions

View file

@ -19,6 +19,7 @@ struct Internal {
vertical_alignment: alignment::Vertical,
bounds: Size,
min_bounds: Size,
version: text::Version,
}
impl Paragraph {
@ -27,9 +28,9 @@ impl Paragraph {
}
pub fn with_text(text: Text<'_, Font>, font_system: &FontSystem) -> Self {
log::trace!("\nAllocating paragraph: {}", text.content);
log::trace!("Allocating paragraph: {}", text.content);
let mut font_system = font_system.write();
let (mut font_system, version) = font_system.write();
let mut buffer = cosmic_text::Buffer::new(
&mut font_system,
@ -63,6 +64,7 @@ impl Paragraph {
shaping: text.shaping,
bounds: text.bounds,
min_bounds,
version,
})))
}
@ -70,6 +72,10 @@ impl Paragraph {
&self.internal().buffer
}
pub fn version(&self) -> text::Version {
self.internal().version
}
pub fn downgrade(&self) -> Weak {
let paragraph = self.internal();
@ -89,8 +95,10 @@ impl Paragraph {
match Arc::try_unwrap(paragraph) {
Ok(mut internal) => {
let (mut font_system, _) = font_system.write();
internal.buffer.set_size(
&mut font_system.write(),
&mut font_system,
new_bounds.width,
new_bounds.height,
);
@ -246,6 +254,7 @@ impl Default for Internal {
vertical_alignment: alignment::Vertical::Top,
bounds: Size::ZERO,
min_bounds: Size::ZERO,
version: text::Version::default(),
}
}
}