Skip to main content

read_svg_viewport_px

Function read_svg_viewport_px 

Source
pub fn read_svg_viewport_px(path: &Path) -> Option<(u32, u32)>
Expand description

SVG viewport size in CSS px, as a browser would take it: the viewBox extent when there is one, else the root width/height lengths.

This is the sizing basis for imagewidth/imageheight in LaTeXML::Post::Graphics — where Perl asks Image::Magick, which renders the SVG and reports the raster it produced.

The viewBox comes first here, and that is deliberate — the opposite of read_svg_size_pt, which wants the natural typeset size. Both of our own PDF→SVG converters emit a viewBox alongside pt-valued width/height (pdftocairo -svg: width="612pt" height="792pt" viewBox="0 0 612 792"; mutool draw -F svg: width="612" height="792" viewBox="0 0 612 792"), so preferring the lengths would silently rescale every PDF-derived figure in the corpus by 96/72 = 1.33×. The viewBox keeps them at their long-standing pixel size, and for a width=-ed inclusion only the aspect ratio matters anyway.