Skip to main content

Crate rustyfi_html

Crate rustyfi_html 

Source
Expand description

HTML output backends. There are two, and they answer different questions.

This module is the LAYOUT-FAITHFUL one (--format html-fixed, render_html_fixed): it serializes the SAME post-page-break Page/PlacedLine model the PDF writer (rustyfi-pdf’s lib.rs) consumes — the design doc’s “Option A”, a non-reflowing “PDF-in-a-div” twin of the PDF output. Its use is visual diffing: putting this port’s layout in a browser where a run’s coordinates can be inspected, rather than eyeballing two renderings side by side. It is not a web page and is not meant to be read as one.

The [reflow] submodule is the readable one (--format html, render_html_reflow): one continuous, semantic document with no pages in it, built from the flat block stream as it stood BEFORE page breaking. See its own doc comment.

Everything below concerns the faithful backend.

Slice 1 (§Slice 1, “text + block layout of a single-page document”): InnerString runs as positioned <span>s, plus the <div class="page"> wrapper. Slice 2 (§Slice 2, “graphics (inline SVG)”), this revision: Graphics as inline SVG (svg.rs) and the Tabular/EmbeddedBlock/ Frame composite recursions, mirroring the PDF writer’s own emit_box (lib.rs:646-671). Image/Math and DocExtras::page_graphics remain Slice 3+ territory — see emit_box’s doc comment below.

Slice 3 (§Slice 3, “real fonts + math”): @font-face data-URI embedding (fonts.rs) so text/math runs use the SAME TrueType face the rustyfi_pdf::TtfFontStore PDF path embeds (metric-faithful positioning — see this module’s Ctx/render_html_fixed_ttf_with), Image boxes as <img> data URIs (image.rs, a hand-rolled uncompressed BMP container — no PNG/image-codec dependency), and Math glyphs as positioned <span>s (reusing the same run-emission path as InnerString, per the design doc’s math row) with Math.rules (the fraction bar/radical) through the Slice-2 SVG path. The base-14 (no font store) path is UNCHANGED from Slice 1/2: render_html_fixed still emits the generic .run CSS default font-family, no @font-face block at all.

Slice 4 (§Slice 4, “multi-page + print pagination”), this revision: print pagination CSS (a @page { size: …; margin: 0 } rule matching geometry.paper_width/paper_height, plus .page:not(:last-child) { page-break-after: always; break-after: page } so a browser print/ print-to-PDF paginates 1:1 with the document — a single-page document has no non-last .page, so this selector matches nothing and its output is byte-identical to Slice 1-3’s, per the design doc’s “keep single-page docs looking identical” requirement) and DocExtras::page_graphics (the per-page deco-graphics underlay this doc comment had flagged as deferred since Slice 1/2 — see render_html_impl’s per-page loop below for the coordinate-frame reconciliation).

Location. This is its own rustyfi-html crate, a peer of rustyfi-pdf (per the design doc’s original spec, survey #6). It depends on rustyfi-backend for every box/geometry type used below, plus rustyfi-pdf for rustyfi_pdf::TtfFontStore (the one type this module reuses rather than re-implements — only its pub file_index/ file_bytes accessors are used, so this is a plain one-way dependency, not a cycle: rustyfi-pdf does not depend on rustyfi-html). Nothing here touches pdf_writer or any other PDF-specific type, only rustyfi_backend/rustyfi_pdf::TtfFontStore types and String building.

Enums§

HtmlError
Slice 1 never actually constructs this — every text run is valid UTF-8/HTML-escapable, and no font/image embedding (the error-prone parts, per the design doc’s later slices) happens yet. The Result return shape is kept anyway so render_html_fixed is argument-for-argument (module signature, not module fallibility) with render_pdf_with (lib.rs:459), and so Slices 2/3 (SVG graphics, real fonts/@font-face, image data-URIs) can surface a real error without a breaking signature change.

Functions§

render_html_fixed
Serialize typeset pages to a single, self-contained HTML document, using generic system-font fallback (Slice 1/2 behavior, unchanged): no @font-face block, every run styled by the plain .run CSS class. This is the base-14 twin of rustyfi_pdf::render_pdf_with — pass render_html_fixed_ttf_with a real TtfFontStore instead when the document was typeset against real embedded fonts, for metric-faithful output (Slice 3, see this module’s doc comment).
render_html_fixed_ttf_with
Same as render_html_fixed, but rendering under a real TtfFontStore — the HTML twin of rustyfi_pdf::render_pdf_ttf_with (cid.rs). Every text and math run’s <span> gets an explicit font-family naming the @font-face embedding this function adds to the <style> block for every physical font file the document actually referenced, so the browser lays text out in the SAME face whose metrics the layout was computed with (the design doc’s §Risks “font-metric fidelity” mitigation, Slice 3’s whole point).
render_html_reflow
Serialize the pre-page-break Vec<VertBox> (sourceDocumentValue::reflow_source, None when unavailable, e.g. a hand-built DocumentValue in a test) to a single, self-contained, REFLOWABLE HTML document, using generic system-font fallback (no @font-face block) — the base-14 twin of render_html_reflow_ttf_with, exactly mirroring crate::render_html_fixed’s relationship to crate::render_html_fixed_ttf_with.
render_html_reflow_ttf_with
Same as render_html_reflow, but rendering under a real TtfFontStore — every inline run’s <span> gets an explicit font-family naming the @font-face this function’s <style> block embeds for every physical font file actually referenced, exactly crate::render_html_fixed_ttf_with’s Slice-3 fidelity mitigation.
render_html_reflow_ttf_with_decos
render_html_reflow_ttf_with plus the frame decorations — the full-fidelity entry point the CLI uses.
render_html_reflow_with_decos
render_html_reflow plus the frame decorations (DocumentValue::reflow_frame_decos), so framed blocks draw their own decoration instead of nothing.