compute_auto_scale

Function compute_auto_scale 

Source
pub(crate) fn compute_auto_scale(
    svg: &str,
    candidate_scale: f32,
    max_ratio: f32,
    page_size: Size,
) -> (f32, Option<Image>)
Expand description

Given an SVG and a candidate scale, determine the final scale so that the rendered image does not exceed the specified maximum ratio of the provided page width/height. The function returns a scale that is at most candidate_scale.

This implementation prefers a fast string-based extraction of width/height or viewBox to avoid invoking the slow SVG parser on every diagram. Only if these heuristics fail do we fall back to a full parse.