PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M12: an XFA button without a height is as tall as its caption
Eric Kadenda38e0da6f28
diff --git a/crates/xfa/src/layout.rs b/crates/xfa/src/layout.rsindex f44a23478..72b515137 100644--- a/crates/xfa/src/layout.rs+++ b/crates/xfa/src/layout.rs@@ -1060,6 +1060,18 @@ impl Layouter<'_> {let lines = if f.multiline { 3.0 } else { 1.0 };let ui = match f.ui {Ui::CheckButton => f.check_size.unwrap_or(10.0).max(text::line_height(font.size)),+ // A button shows its caption: as tall as the caption's text in its own font.+ Ui::Button if f.caption.as_ref().is_some_and(|c| !c.value.is_empty()) => {+ let cap = f.caption.as_ref().map_or(0.0, |c| {+ let rich = match &c.value {+ Value::Rich(r) => r.clone(),+ other => text::plain(&other.plain().unwrap_or_default()),+ };+ let w = (inner_w - f.ui_margin.horizontal()).max(1.0);+ text::measure_height(&rich, w, &ctx.para.apply(&c.para), &Face::of(&ctx.font.apply(&c.font)), &|id| self.embed(id))+ });+ cap + f.ui_margin.vertical()+ }_ => (text::line_height(font.size) * lines).max(self.grown_text_height(f, inner_w, ctx)) + 4.0 + f.ui_margin.vertical(),};match self.caption_reserve(f, inner_w, ctx) {diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rsindex 02bb07dfc..e14917b7e 100644--- a/crates/xfa/src/tests.rs+++ b/crates/xfa/src/tests.rs@@ -1252,6 +1252,20 @@ fn a_button_without_a_width_is_as_wide_as_its_caption() {assert!((button.rect.w - 200.0).abs() < 0.05, "{}", button.rect.w);}+#[test]+fn a_button_without_a_height_is_as_tall_as_its_caption() {+ // A 10pt field font, an 8pt caption: the button is as tall as its caption's line (no+ // text-field padding), and never below its minimum height.+ let button = |min_h: &str| {+ let items = positioned(&format!(+ r#"<field name="help" x="1in" y="0" w="100pt" minH="{min_h}"><ui><button/></ui><font typeface="Times New Roman" size="10pt"/><caption><value><text>Help</text></value><font typeface="Arial" size="8pt"/></caption></field>"#+ ));+ items.iter().find_map(|i| if let Item::Widget(w) = i { Some(w.rect.h) } else { None }).expect("the button")+ };+ assert!((button("2pt") - text::line_height(8.0)).abs() < 0.05, "{}", button("2pt"));+ assert!((button("10.5pt") - 10.5).abs() < 0.05, "{}", button("10.5pt"));+}+#[test]fn page_area_without_occur_serves_every_body_page() {let section = |n: u32| {