1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 07:10:04 -04:00

Let Fonts handle multiple pixels_per_point

This commit is contained in:
valadaptive
2025-07-04 01:16:55 -04:00
parent 837fc7fef7
commit 9aaee3354d
13 changed files with 218 additions and 263 deletions

View File

@@ -166,7 +166,6 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let font_id = egui::FontId::default();
let text_color = egui::Color32::WHITE;
let mut fonts = egui::epaint::text::Fonts::new(
pixels_per_point,
max_texture_side,
egui::epaint::AlphaFromCoverage::default(),
egui::FontDefinitions::default(),
@@ -182,13 +181,13 @@ pub fn criterion_benchmark(c: &mut Criterion) {
text_color,
wrap_width,
);
layout(&mut fonts.fonts, job.into())
layout(&mut fonts.fonts, job.into(), pixels_per_point)
});
});
}
c.bench_function("text_layout_cached", |b| {
b.iter(|| {
fonts.layout(
fonts.with_pixels_per_point(pixels_per_point).layout(
LOREM_IPSUM_LONG.to_owned(),
font_id.clone(),
text_color,
@@ -210,22 +209,28 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let mut rng = rand::rng();
b.iter(|| {
fonts.begin_pass(
pixels_per_point,
max_texture_side,
egui::epaint::AlphaFromCoverage::default(),
);
fonts.begin_pass(max_texture_side, egui::epaint::AlphaFromCoverage::default());
// Delete a random character, simulating a user making an edit in a long file:
let mut new_string = string.clone();
let idx = rng.random_range(0..string.len());
new_string.remove(idx);
fonts.layout(new_string, font_id.clone(), text_color, wrap_width);
fonts.with_pixels_per_point(pixels_per_point).layout(
new_string,
font_id.clone(),
text_color,
wrap_width,
);
});
});
let galley = fonts.layout(LOREM_IPSUM_LONG.to_owned(), font_id, text_color, wrap_width);
let galley = fonts.with_pixels_per_point(pixels_per_point).layout(
LOREM_IPSUM_LONG.to_owned(),
font_id,
text_color,
wrap_width,
);
let font_image_size = fonts.font_image_size();
let prepared_discs = fonts.texture_atlas().prepared_discs();
let mut tessellator = egui::epaint::Tessellator::new(