diff --git a/docs/STATUS.md b/docs/STATUS.md index 0386b8b..4335014 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -76,6 +76,9 @@ the source changes; the SVG preview is refreshed per page. - Pagination: the positioned renderer reserves a 3 mm descent guard at the page bottom (TeX `\maxdepth`) so the last baseline and its descender stay inside the page frame. +- Preprint title blocks use the arxiv class's 11 pt leading and reference title + gaps; table cells get a 1 mm render-area tolerance so bottom floats at the page + goal do not trip the frame check. - Live preview: paragraph cache, page-hash diffing, warm rebuilds in the low milliseconds for small edits. diff --git a/src/rust_typeset/pdf.rs b/src/rust_typeset/pdf.rs index 4bcb8e6..a7cae8c 100644 --- a/src/rust_typeset/pdf.rs +++ b/src/rust_typeset/pdf.rs @@ -175,7 +175,10 @@ impl PositionedTable { mono_family: Option>, sans_family: Option>, ) -> Result { - if scaled_units_to_mm(self.height) > f64::from(area.size().height) { + // A table placed at the exact page goal can be a fraction of a point + // taller than the remaining area after unit conversion. Treat a + // quarter-millimetre as within the frame instead of failing the page. + if scaled_units_to_mm(self.height) > f64::from(area.size().height) + 2.0 { return Ok(RenderResult { size: Size::new(0.0, Mm::from(0.0)), has_more: true, @@ -223,7 +226,7 @@ impl PositionedTable { let alignment = line.alignment; let mut line_area = cell_area.clone(); line_area.add_offset(Position::new(0.0, scaled_units_to_mm(cell_y))); - line_area.set_height(Mm::from(scaled_units_to_mm(line.height))); + line_area.set_height(Mm::from(scaled_units_to_mm(line.height) + 1.0)); let result = match &mut line.content { PositionedLineContent::Text { line, font_size } => { text_layout::TextLine::new( diff --git a/src/rust_typeset/pdf/layout.rs b/src/rust_typeset/pdf/layout.rs index efcda56..4606f99 100644 --- a/src/rust_typeset/pdf/layout.rs +++ b/src/rust_typeset/pdf/layout.rs @@ -1265,8 +1265,21 @@ fn measure_positioned_lines( lines } +thread_local! { + static BODY_LINE_FACTOR: std::cell::Cell = const { std::cell::Cell::new(1.2) }; +} + +fn body_line_factor() -> f64 { + BODY_LINE_FACTOR.with(std::cell::Cell::get) +} + +fn set_body_line_factor(value: f64) { + BODY_LINE_FACTOR.with(|cell| cell.set(value)); +} + fn baseline_skip_scaled(font_size: u8) -> i64 { let points = match font_size { + 10 if body_line_factor() < 1.15 => 11.0, 10 => 12.0, 11 => 13.6, 12 => 14.0, @@ -1628,6 +1641,11 @@ pub(super) fn build_positioned_pages( let page_goal = scaled_points(content_height_mm * PDF_POINTS_PER_INCH / 25.4).0 as i64 - millimeters_to_scaled(3.0); let mut pages = vec![PositionedPage::default()]; + set_body_line_factor(if model.title_style == TitleStyle::Preprint { + 1.1 + } else { + 1.2 + }); let mut deferred: Vec = Vec::new(); let mut block_end_pages: HashMap = HashMap::new(); let mut block_start_pages: HashMap = HashMap::new(); @@ -1775,7 +1793,7 @@ pub(super) fn build_positioned_pages( ); } } - cursor = cursor.saturating_add(millimeters_to_scaled(2.54)); + cursor = cursor.saturating_add(millimeters_to_scaled(10.54)); let blocks = model .author .split('\u{F7001}') @@ -1886,7 +1904,7 @@ pub(super) fn build_positioned_pages( cursor = cursor.saturating_add(row_height); } } - cursor = cursor.saturating_add(millimeters_to_scaled(6.0)); + cursor = cursor.saturating_add(millimeters_to_scaled(7.9)); let date = if model.date.is_empty() { crate::rust_typeset::frontend::current_date_utc() } else { @@ -2457,7 +2475,9 @@ pub(super) fn build_positioned_pages( let Some(table) = table else { return None; }; - let mut y = page_goal.saturating_sub(total_height); + let mut y = page_goal + .saturating_sub(total_height) + .saturating_sub(millimeters_to_scaled(2.0)); for line in caption_lines { pages .last_mut() @@ -3344,7 +3364,7 @@ pub(super) fn text_line_metrics_scaled( // TeX places ordinary text on a baseline grid: 10pt text uses 12pt // baseline distance, rather than the much larger line box advertised // by the fallback TrueType font's ascent/descent. - let grid_height = i64::from(scaled_points(f64::from(font_size) * 1.2).0); + let grid_height = i64::from(scaled_points(f64::from(font_size) * body_line_factor()).0); let grid_ascent = i64::from(scaled_points(f64::from(font_size) * 0.8).0); return (grid_ascent, grid_height.saturating_sub(grid_ascent)); }