resumark 0.1.1

ATS-safe resume typesetting from Markdown — extraction order as a verified contract
Documentation
//! Auto-fit: shrink the type scale in small steps until the resume fits the
//! page budget, exactly like the reference renderer — but by measuring the
//! layout directly instead of rendering and counting pages.

use crate::fonts::FontBook;
use crate::layout::{Layout, PageGeom, layout_doc};
use crate::parse::ResumeDoc;

pub const MIN_SCALE: f32 = 0.78;
pub const STEP: f32 = 0.02;

pub fn autofit(
    doc: &ResumeDoc,
    book: &FontBook,
    geom: PageGeom,
    max_pages: usize,
    fixed_scale: Option<f32>,
) -> Layout {
    if let Some(s) = fixed_scale {
        return layout_doc(doc, book, geom, s);
    }
    let mut s = 1.0f32;
    while s > MIN_SCALE + 1e-6 {
        let l = layout_doc(doc, book, geom, s);
        if l.pages.len() <= max_pages && !l.overflow {
            return l;
        }
        s -= STEP;
    }
    // Content is too long even at minimum scale; the caller reports it.
    layout_doc(doc, book, geom, MIN_SCALE)
}