mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-24 10:08:00 -06:00
M12: an XFA button without a height is as tall as its caption
A button with no height was sized like a text field in its field font, with text-field padding, so DA Form 31's Instructions button (10 pt field font, 8 pt caption) came out about 17 pt tall and over the form below it. It is now as tall as its caption, never below its minimum.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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| {
|
||||
|
||||
Reference in New Issue
Block a user