PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
M5: leave measuring form text in its own font to #2900
Eric Kaden24a45db0459c
diff --git a/crates/forms/src/appearance.rs b/crates/forms/src/appearance.rsindex 57dd0d479..502bd9dbf 100644--- a/crates/forms/src/appearance.rs+++ b/crates/forms/src/appearance.rs@@ -191,12 +191,6 @@ impl FontText {fn width(&self, s: &str, size: f64) -> f64 {match self {- // A simple font's own widths (its /Widths, or a standard font's published ones: a- // bold face is wider than Helvetica), one byte per code.- Self::Simple(m) if !m.composite => match m.encode(&s.replace('\t', " ")) {- Some(codes) => codes.iter().map(|&c| m.width(u32::from(c))).sum::<f64>() * size,- None => helvetica_width(s, size),- },Self::WinAnsi | Self::Simple(_) => helvetica_width(s, size),Self::Unicode(_) => cjk_width(s, size),}diff --git a/crates/forms/src/tests.rs b/crates/forms/src/tests.rsindex 668db6332..0942a52e6 100644--- a/crates/forms/src/tests.rs+++ b/crates/forms/src/tests.rs@@ -109,10 +109,6 @@ fn a_button_caption_is_drawn_in_its_fields_font_size_and_color() {assert!(menu.contains("/HeBo 9.00 Tf") && menu.contains("0 0 1 rg"), "{menu}");let auto = ap(&doc, &field(&all, "auto").widgets[0]);assert!(auto.contains("/Helv 14.00 Tf") && auto.contains(" 0 g"), "{auto}");- // Centered by the bold face's own widths (wider than regular Helvetica's).- let bold: f64 = "Menu".bytes().map(|c| pdfcraft_fonts::Std14::HelveticaBold.width(c)).sum::<f64>() / 1000.0 * 9.0;- let x = (90.0 - bold) / 2.0;- assert!(menu.contains(&format!("1 0 0 1 {x:.3} ")), "centered at {x:.3}: {menu}");}#[test]diff --git a/parity/acrobat-features.toml b/parity/acrobat-features.tomlindex 64208a0c8..af2a04bba 100644--- a/parity/acrobat-features.toml+++ b/parity/acrobat-features.toml@@ -4921,7 +4921,7 @@ status = "shipped"commands = ["form.field.properties"]tools = ["form_set_props"]evidence = ["crates/forms/src/tests.rs::button_caption_preserves_other_widgets_and_shared_dictionaries", "crates/forms/src/tests.rs::a_button_caption_is_drawn_in_its_fields_font_size_and_color", "crates/ui-egui/tests/prepare.rs::button_label_is_editable_without_renaming_the_field", "crates/automation/tests/button_caption.rs::button_caption_can_be_changed_after_creation", "crates/forms/src/tests.rs::properties_rename_and_delete", "crates/automation/tests/automation.rs::preparing_a_form_through_tools", "crates/forms/src/tests.rs::options_tab_flags_alignment_and_defaults", "crates/ui-egui/tests/prepare.rs::options_tab_sets_flags_alignment_and_defaults", "crates/automation/tests/form_bulk.rs::bulk_options_apply_per_field_and_refuse_an_invalid_comb_atomically"]-notes = "push buttons: per-widget normal label independent of the field name, including clearing and save/reopen, drawn in the font, size and color of the button's /DA (the form's /DR font, else Helvetica; an automatic size fits the button) and centered by the font's own widths; icon-only layout retained, rollover/down labels and icon layout editing remain unavailable; text: alignment, default, multi-line, scroll, rich text flag, limit, password, file selection, spell check, comb; choices: items, default, sort, custom text, multiple selection, commit immediately; check boxes and radios: checked by default, radios in unison. Shared GUI offers applicable text/choice flags, alignment, text limits and check styles; choices/defaults remain individual GUI edits"+notes = "push buttons: per-widget normal label independent of the field name, including clearing and save/reopen, drawn in the font, size and color of the button's /DA (the form's /DR font, else Helvetica; an automatic size fits the button) and centered by Helvetica's widths; icon-only layout retained, rollover/down labels and icon layout editing remain unavailable; text: alignment, default, multi-line, scroll, rich text flag, limit, password, file selection, spell check, comb; choices: items, default, sort, custom text, multiple selection, commit immediately; check boxes and radios: checked by default, radios in unison. Shared GUI offers applicable text/choice flags, alignment, text limits and check styles; choices/defaults remain individual GUI edits"[[feature]]id = "form.props-actions"