From b5033b6213edfd91fd3558ff757d1320981bc2b2 Mon Sep 17 00:00:00 2001 From: Naseq Date: Sun, 1 Nov 2026 13:38:14 +0430 Subject: [PATCH] Text: preserve signed insets and scale only when both are non-negative Address review finding: keep signed insets unchanged when their sum fits, scaling opposing insets proportionally only when both in the pair are non-negative and their sum exceeds the box dimension. --- crates/text/src/layout.rs | 8 ++++---- crates/text/src/tests.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index 94a0b5f2..c0422815 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -94,18 +94,18 @@ impl BoxGeom { text_rect }; // Insets wider than the shape scale down proportionally to fit inside it (#1632). - let (mut ins_l, mut ins_r) = (bp.inset_l.unwrap_or(7.2).max(0.0), bp.inset_r.unwrap_or(7.2).max(0.0)); - let (mut ins_t, mut ins_b) = (bp.inset_t.unwrap_or(3.6).max(0.0), bp.inset_b.unwrap_or(3.6).max(0.0)); + let (mut ins_l, mut ins_r) = (bp.inset_l.unwrap_or(7.2), bp.inset_r.unwrap_or(7.2)); + let (mut ins_t, mut ins_b) = (bp.inset_t.unwrap_or(3.6), bp.inset_b.unwrap_or(3.6)); let w = r.width().max(0.0); let total_x = ins_l + ins_r; - if total_x > w && total_x > 0.0 { + if ins_l >= 0.0 && ins_r >= 0.0 && total_x > w && total_x > 0.0 { let s = w / total_x; ins_l *= s; ins_r *= s; } let h = r.height().max(0.0); let total_y = ins_t + ins_b; - if total_y > h && total_y > 0.0 { + if ins_t >= 0.0 && ins_b >= 0.0 && total_y > h && total_y > 0.0 { let s = h / total_y; ins_t *= s; ins_b *= s; diff --git a/crates/text/src/tests.rs b/crates/text/src/tests.rs index a5d3b324..cb1be0e2 100644 --- a/crates/text/src/tests.rs +++ b/crates/text/src/tests.rs @@ -1949,3 +1949,18 @@ fn insets_wider_than_the_shape_scale_down_within_the_shape_bounds() { // The text center must remain inside the 14.17 pt wide shape, not pushed ~127.5 pt to the right. assert!((0.0..=14.17).contains(&mid), "line center {mid} should be within [0, 14.17]"); } + +/// #1632: signed insets (e.g. negative left inset with positive right inset) are preserved when +/// their sum fits within the shape bounds. +#[test] +fn signed_insets_are_preserved_when_they_fit() { + let (p, mut sh) = setup("Text", 100.0, 50.0); + sh.ph = None; + let bp = &mut sh.text.as_mut().unwrap().body; + bp.inset_l = Some(-10.0); + bp.inset_r = Some(10.0); + sh.text.as_mut().unwrap().paragraphs[0].props = deckcraft_model::text::ParaProps { align: Some(Align::Left), ..Default::default() }; + let l = lay(&p, &sh, 100.0, 50.0); + assert_eq!(l.lines.len(), 1); + assert_eq!(l.inner.x0, -10.0); +}