Merge PR #1709: Rows: a big font isn't counted twice when the sheet's default height already fits it

This commit is contained in:
aiongg
2026-10-22 02:35:02 +00:00
2 changed files with 23 additions and 1 deletions
+3 -1
View File
@@ -488,7 +488,9 @@ pub fn auto_row_height(wb: &mut Workbook, si: usize, row: u32) {
}
let st = wb.styles.get(cell.style);
let size = st.font.size;
let line = (size * 1.8).round().max(default * size / gridcraft_model::DEFAULT_FONT_SIZE);
// Scaled from an 11pt row's height, not the sheet's default: a sheet whose default
// already fits a bigger font (21pt rows for 16pt text) would otherwise scale it twice.
let line = (size * 1.8).round().max(gridcraft_model::DEFAULT_ROW_HEIGHT * size / gridcraft_model::DEFAULT_FONT_SIZE);
let mut lines = 1.0f32;
if !cell.value.is_empty() || cell.formula.is_some() {
let text = crate::display::cell_text(wb, sh, CellRef::new(row, c));
+20
View File
@@ -1193,6 +1193,26 @@ fn autofit_skips_merged_cells() {
assert!(xml.contains("<mergeCell ref=\"A1:E1\"/>"), "the merge itself is saved");
}
#[test]
fn open_fits_big_font_rows_from_the_font_not_the_sheet_default() {
// Excel saves a sheet whose rows hold 16pt text with a 21pt (28px) default row height and no
// `ht` on rows of that height. Those rows already fit their font: they open at about 28px,
// not scaled up again by 16/11 to 41px.
let mut wb = gridcraft_model::Workbook::new();
let big = wb.styles.derive(gridcraft_model::StyleId::DEFAULT, |s| s.font.size = 16.0);
let sh = wb.sheet_mut(0).unwrap();
sh.default_row_height = 28.0;
sh.set_value(CellRef::new(4, 0), Value::text("SANTANDER"));
sh.set_style(CellRef::new(4, 0), big);
let bytes = gridcraft_xlsx::write_xlsx(&wb).unwrap();
let mut s = Session::new();
s.execute("file.open", json!({"name": "tall-default.xlsx", "base64": crate::io::base64_encode(&bytes)})).unwrap();
let sh = s.doc().unwrap().wb.active().unwrap();
assert_eq!(sh.default_row_height, 28.0);
let h = sh.row_height(4);
assert!((28.0..30.0).contains(&h), "a 16pt row on a 28px-default sheet opens at about 28px, got {h}");
}
#[test]
fn tables_and_structured_refs() {
let mut s = s();