Expand description
image file helpers — port of LaTeXML::Util::Image
Image helpers — port of LaTeXML::Util::Image.
Perl counterpart: lib/LaTeXML/Util/Image.pm.
Provides filesystem search for image candidates, minimal header-based
image size detection (PNG / JPEG / EPS) and the graphicx sizer that
converts keyval option strings into box dimensions. The Rust port is
intentionally narrower than the Perl original — Image::Magick is not
used at all; LaTeXML::Post::Graphics carries out any heavy-duty image
operations in a post-processing pass.
Structs§
- Post
Script Boxes - The DSC bounding-box comments of a PostScript file (Adobe DSC 3.0:
%%BoundingBox:,%%HiResBoundingBox:,(atend)), as(llx, lly, urx, ury)in bp.
Enums§
- Graphic
Content - What a graphic file holds, by its first bytes: drawn (PDF, PostScript), so a converter renders it at a density, or
a raster’s pixels (PNG, JPEG, GIF, TIFF, BMP, WebP), which
-densitydoes not resample. - Graphicx
Op - One graphicx transformation, as compiled from the option string.
- Image
Size - What
read_image_sizemeasures: a raster’s pixel count, or a PostScript file’s bounding box in bp — a physical size, which needs no resolution.
Functions§
- apply_
graphicx_ ops - Apply a compiled transformation sequence to a natural size.
- clear_
image_ size_ memo - Clear the per-thread image size memos. Called at the start of every
conversion, beside
clear_kpsewhich_memo: a long-lived worker thread converts many papers, and a file may change between them. - graphic_
content GraphicContentof the file atpath, whatever its name (a PDF or EPS saved as.pstex, cond-mat0603250’sloop.pstex);Nonewhen the head is none of them (a compressed.eps.gzamong them).- graphicx_
crop_ rect - The pixel rectangle a
trim/viewportop keeps of aw×hraster, as(x, y, width, height)from its top-left corner;Nonewhen the box keeps the whole image or no pixel of it. Port of Perlimage_graphicx_complex’s trim/clip arm (Util/Image.pmL400-418): TeX measures the box from the lower-left corner and ImageMagick from the upper-left, and the box is clamped to the image, never padded.px_per_bpis the raster’s own resolution over 72 (DIVERGENCES #337: Perl divides by 72.27 and reads the resolution without its unit). - image_
candidates - Perl:
image_candidates($path)(Util::Image L43-57). - image_
graphicx_ sizer - Perl:
image_graphicx_sizer($whatsit)(Util::Image L259-272). - natural_
display_ size_ pt - The figure’s TRUE natural (typeset) size in TeX pt, for the VECTOR formats
whose intrinsic size is a real physical dimension: a PDF page box, an EPS/PS
%%BoundingBox(both bp), or an SVG’s lengths/viewBox.Nonefor raster formats — a pixel count is not a physical size without a DPI — and when the geometry can’t be recovered. - natural_
display_ size_ pt_ of_ candidates natural_display_size_ptof the candidate the box is sized from: the first of a comma-joinedcandidatesstring (the<ltx:graphics candidates=…>attribute, resolved againstsource_dir) that any reader sizes (first_natural_size),Nonewhen that one is a raster — so aq.pngbefore aq.epsgives noemsize, as any raster does, rather than the eps’s size for the png pdflatex prints (review rev78z finding 1).- parse_
bbox - Parse
"llx lly urx ury"from a BoundingBox comment body. - parse_
graphicx_ options - Compile a graphicx option string into the transformation sequence.
- pdf_
image_ resolution \pdfimageresolutionas pdftex.web:34511-34515 applies it to a raster stating no usable resolution: the register clamped to 0..65535, and 72 dpi when that is 0 (ext_xn_over_d(one_hundred_inch, x, 7200)).- raster_
resolution_ dpi - A raster’s own resolution in dots per inch,
(x, y), as pdfTeX reads it to size an image: a PNG’spHYschunk (unit 1 is per metre), rounded to whole dpi, or a JPEG’s density from the segment right after SOI (jpeg_resolution_dpi) — pdflatex measures an 11811 px/m PNG at 300 dpi and a 118 px/cm JPEG at 299.Nonewhen the file states none, only an aspect ratio (unit 0), or one pdfTeX ignores for a raster ofpixels(width, height;pdftex_raster_resolution): pdfTeX then takes\pdfimageresolution(raster_sizing_dpi). Reads the head only: both come before the pixels. - raster_
sizing_ dpi - The resolution pdfTeX sizes a raster of
pixelsat, as\pdfximagedoes (pdftex.web:34488-34515): its own (raster_resolution_dpi), else\pdfimageresolution(pdf_image_resolution), with pdfTeX’s Warning, whenwarn, if it ignores one the file states. - read_
image_ dimensions - Read image dimensions (width, height) in pixels from a file. Supports PNG, JPEG, and EPS (PostScript BoundingBox, its bp rounded to whole units).
- read_
image_ size - The size of a PNG, JPEG or EPS/PS file, sniffed from its header (
ImageSize), read once per path and conversion. - read_
pdf_ page_ box - Read a PDF’s page box (width, height) in bp — CropBox (pdfTeX’s default),
else MediaBox. Pure Rust, no external tool (this is what pdfTeX’s built-in
reader does). Shared with
LaTeXML::Post::Graphics. - read_
pdf_ page_ box_ corners - The page box
read_pdf_page_boxreads, as its corners[llx, lly, urx, ury]in bp — what pdfTeX’s\pdfximagebboxreports for an image (pdftex.webpdf_ximage_bbox). - read_
pdf_ page_ count - The page count of a PDF, as pdfTeX’s
\pdflastximagepagesreports it after\pdfximage: the root/Type /Pagesnode’s/Count. Without a full parser, the root is the/Pagesdictionary with the LARGEST/Count(intermediate nodes count only their subtree); raw bytes first, then the inflated object streams (PDF 1.5+, seeread_pdf_page_box). A PDF with no/Pagesdictionary at all falls back to counting/Type /Pageobjects. - read_
postscript_ boxes - See
PostScriptBoxes;Nonewhen the file cannot be read. - read_
postscript_ size_ bp - A PostScript file’s size in bp, as TeX reads it: the
%%BoundingBox, graphics.sty’s\Gread@epsreading (\Gread@BBox, graphics.sty:52, read at :365-399; thehiresbboption, :56-57, aside) and epstopdf’s, which pdflatex then reads as the page; a%%HiResBoundingBoxonly when there is no%%BoundingBox(where TeX finds no size at all), as post reads the file (latexml_post graphics.rsread_postscript_bounding_box_full).Nonefor an empty box. Until 78z the high-resolution box came first, rounded: a file with%%BoundingBox: 0 0 200 100and%%HiResBoundingBox: 0.4 0.3 199.3 99.4was 199bp x 99bp where latex and pdflatex make it 200.75pt x 100.375pt; hep-ex0703011’seeggmet.epscarries a stale full-page%%HiResBoundingBox(612x792) beside its 540x522%%BoundingBox. - read_
svg_ viewport_ px - SVG viewport size in CSS px, the way a browser takes it: the root
width/height(a unitless value is CSS px), falling back to theviewBoxonly when the lengths are absent or relative (%).Nonewhen neither is usable, so the caller omits the dimensions and lets the browser size it. - svg_
attr_ len_ px - An SVG length attribute in CSS px. A unitless value is user units, i.e. px.
Nonefor anything that isn’t an absolute length (%,em,ex, …) — those are resolved against a viewport we don’t have, so the caller must fall back to the viewBox rather than treat the bare number as pixels. - svg_
attr_ value - Value of the
name="…"/name='…'attribute in an XML start tag. - svg_
root_ tag - The root
<svg …>start tag withinhead, quote-aware so a>inside an attribute value doesn’t end the tag early. Skipping to<svgalso steps over the<?xml …?>prolog, comments and any DOCTYPE — otherwise the prolog’s?>would be mistaken for the end of the start tag. - svg_
viewport_ px read_svg_viewport_pxof an SVG’s text (its head suffices) already in memory.- to_bp
- A TeX/graphicx length in bp. Port of Perl
to_bp+%BP_conversions(Util/Image.pmL198-210), including itstrue-prefix strip (truept) and its “unknown unit counts as bp” fallback. A value that is not a length at all yields 1, exactly as Perl’selse { return 1 }does. - xml_
start_ tag - The start tag that
textbegins with, up to (not including) its>, quote-aware.