diff --git a/crates/epaint/src/text/fonts.rs b/crates/epaint/src/text/fonts.rs index dbd2fa3c0..df6547428 100644 --- a/crates/epaint/src/text/fonts.rs +++ b/crates/epaint/src/text/fonts.rs @@ -841,6 +841,13 @@ impl GalleyCache { } } + if merged_galley.job.round_output_size_to_nearest_ui_point { + super::round_output_size_to_nearest_ui_point( + &mut merged_galley.rect, + &merged_galley.job, + ); + } + merged_galley } diff --git a/crates/epaint/src/text/mod.rs b/crates/epaint/src/text/mod.rs index 3cb0e98cb..cf5c8ebfc 100644 --- a/crates/epaint/src/text/mod.rs +++ b/crates/epaint/src/text/mod.rs @@ -14,7 +14,7 @@ pub use { FontData, FontDefinitions, FontFamily, FontId, FontInsert, FontPriority, FontTweak, Fonts, FontsImpl, InsertFontFamily, }, - text_layout::layout, + text_layout::*, text_layout_types::*, }; diff --git a/crates/epaint/src/text/text_layout.rs b/crates/epaint/src/text/text_layout.rs index 798fa1d3b..5f52235c5 100644 --- a/crates/epaint/src/text/text_layout.rs +++ b/crates/epaint/src/text/text_layout.rs @@ -679,20 +679,7 @@ fn galley_from_rows( let mut rect = Rect::from_min_max(pos2(min_x, 0.0), pos2(max_x, cursor_y)); if job.round_output_size_to_nearest_ui_point { - let did_exceed_wrap_width_by_a_lot = rect.width() > job.wrap.max_width + 1.0; - - // We round the size to whole ui points here (not pixels!) so that the egui layout code - // can have the advantage of working in integer units, avoiding rounding errors. - rect.min = rect.min.round(); - rect.max = rect.max.round(); - - if did_exceed_wrap_width_by_a_lot { - // If the user picked a too aggressive wrap width (e.g. more narrow than any individual glyph), - // we should let the user know by reporting that our width is wider than the wrap width. - } else { - // Make sure we don't report being wider than the wrap width the user picked: - rect.max.x = rect.max.x.at_most(rect.min.x + job.wrap.max_width).floor(); - } + round_output_size_to_nearest_ui_point(&mut rect, &job); } Galley { @@ -707,6 +694,23 @@ fn galley_from_rows( } } +pub(crate) fn round_output_size_to_nearest_ui_point(rect: &mut Rect, job: &LayoutJob) { + let did_exceed_wrap_width_by_a_lot = rect.width() > job.wrap.max_width + 1.0; + + // We round the size to whole ui points here (not pixels!) so that the egui layout code + // can have the advantage of working in integer units, avoiding rounding errors. + rect.min = rect.min.round(); + rect.max = rect.max.round(); + + if did_exceed_wrap_width_by_a_lot { + // If the user picked a too aggressive wrap width (e.g. more narrow than any individual glyph), + // we should let the user know by reporting that our width is wider than the wrap width. + } else { + // Make sure we don't report being wider than the wrap width the user picked: + rect.max.x = rect.max.x.at_most(rect.min.x + job.wrap.max_width).floor(); + } +} + #[derive(Default)] struct FormatSummary { any_background: bool,