Update glyphon and cosmic-text

This commit is contained in:
Héctor Ramón Jiménez 2023-06-16 15:50:03 +02:00
parent 267dbf34e9
commit 0c65936664
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
3 changed files with 15 additions and 20 deletions

View file

@ -45,7 +45,7 @@ path = "../graphics"
[dependencies.glyphon]
version = "0.2"
git = "https://github.com/hecrj/glyphon.git"
rev = "26f92369da3704988e3e27f0b35e705c6b2de203"
rev = "8dbf36020e5759fa9144517b321372266160113e"
[dependencies.glam]
version = "0.24"

View file

@ -53,7 +53,7 @@ impl Pipeline {
}
pub fn load_font(&mut self, bytes: Cow<'static, [u8]>) {
self.font_system.get_mut().db_mut().load_font_source(
let _ = self.font_system.get_mut().db_mut().load_font_source(
glyphon::fontdb::Source::Binary(Arc::new(bytes.into_owned())),
);
}
@ -116,15 +116,7 @@ impl Pipeline {
let buffer =
self.render_cache.get(key).expect("Get cached buffer");
let (total_lines, max_width) = buffer
.layout_runs()
.enumerate()
.fold((0, 0.0), |(_, max), (i, buffer)| {
(i + 1, buffer.line_w.max(max))
});
let total_height =
total_lines as f32 * buffer.metrics().line_height;
let (max_width, total_height) = measure(buffer);
let x = section.bounds.x * scale_factor;
let y = section.bounds.y * scale_factor;
@ -265,14 +257,7 @@ impl Pipeline {
},
);
let (total_lines, max_width) = paragraph
.layout_runs()
.enumerate()
.fold((0, 0.0), |(_, max), (i, buffer)| {
(i + 1, buffer.line_w.max(max))
});
(max_width, line_height * total_lines as f32)
measure(paragraph)
}
pub fn hit_test(
@ -312,6 +297,16 @@ impl Pipeline {
}
}
fn measure(buffer: &glyphon::Buffer) -> (f32, f32) {
let (width, total_lines) = buffer
.layout_runs()
.fold((0.0, 0usize), |(width, total_lines), run| {
(run.line_w.max(width), total_lines + 1)
});
(width, total_lines as f32 * buffer.metrics().line_height)
}
fn to_family(family: font::Family) -> glyphon::Family<'static> {
match family {
font::Family::Name(name) => glyphon::Family::Name(name),