Skip to main content

lightweight_pdf/
lib.rs

1//! Public facade for `lightweight-pdf`: re-exports the `lightweight-pdf-core` builder API
2//! and adds `Document::render()` (ADR-002 — this is the crate users add to
3//! `Cargo.toml`, the place `render()` becomes public).
4
5mod fonts;
6mod images;
7mod render;
8
9pub use fonts::FontRegistry;
10pub use images::ImageEmbedError;
11pub use lightweight_pdf_core::*;
12pub use lightweight_pdf_fonts::FontError;
13pub use lightweight_pdf_layout::{LayoutWarning, LayoutWarningKind};
14pub use render::{DocumentExt, RenderError};
15
16#[cfg(all(feature = "wasm-size-probe", not(feature = "default-fonts")))]
17compile_error!(
18    "wasm-size-probe needs a font source: enable `default-fonts` alongside it (see plan/00a-contracts-and-artifacts.md, point 2)"
19);
20
21/// Internal, non-public measurement export (`plan/00a-contracts-and-artifacts.md`
22/// point 1): renders a small but complete document end-to-end so the real
23/// render path isn't dead-code-eliminated from the size measurement. Not a
24/// public runtime API (ADR-009: no JS-facing API in V1).
25#[cfg(feature = "wasm-size-probe")]
26#[no_mangle]
27pub extern "C" fn lightweight_pdf_wasm_size_probe() -> i32 {
28    let mut doc = Document::new(PageFormat::A4).margin(Margin::symmetric(20.0, 18.0));
29    doc.add(Text::new("Hallo Rechnung").size(18.0).bold());
30    doc.add(
31        Row::new()
32            .gap(8.0)
33            .child(Text::new("Menge").size(10.0))
34            .child(Text::new("Preis").size(10.0)),
35    );
36    doc.add(Line::new());
37    match doc.render() {
38        Ok(bytes) => bytes.len() as i32,
39        Err(_) => -1,
40    }
41}