From 8b330513550e05a0b8010b5bcf562b8975b2fbad Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 18:16:55 +0800 Subject: [PATCH] Add a route-D PDF backend smoke example --- .../texrra-tex-core/examples/pdf_display.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 crates/texrra-tex-core/examples/pdf_display.rs diff --git a/crates/texrra-tex-core/examples/pdf_display.rs b/crates/texrra-tex-core/examples/pdf_display.rs new file mode 100755 index 0000000..ce9213a --- /dev/null +++ b/crates/texrra-tex-core/examples/pdf_display.rs @@ -0,0 +1,49 @@ +//! Emit a small route-D PDF with text, a rule, an image XObject, and a link. +//! +//! Run with `cargo run -p texrra-tex-core --example pdf_display > /tmp/route-d.pdf`. + +use texrra_tex_core::render::{DisplayItem, DisplayList, PdfImage}; + +fn main() { + let mut list = DisplayList { + width: 612 * 65_536, + height: 792 * 65_536, + items: Vec::new(), + images: Vec::new(), + }; + list.push(DisplayItem::Text { + x: 72 * 65_536, + y: 100 * 65_536, + size: 12 * 65_536, + text: "route-D XObject".to_string(), + }); + list.push(DisplayItem::Rule { + x: 72 * 65_536, + y: 120 * 65_536, + width: 200 * 65_536, + height: 2 * 65_536, + }); + let index = list.add_image(PdfImage { + width: 2, + height: 2, + rgb: vec![255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 0], + }); + list.push(DisplayItem::Image { + x: 72 * 65_536, + y: 150 * 65_536, + width: 40 * 65_536, + height: 40 * 65_536, + index, + }); + list.link( + 72 * 65_536, + 220 * 65_536, + 120 * 65_536, + 12 * 65_536, + "https://example.com/route-d", + ); + + let pdf = texrra_tex_core::pdf::display_list_to_pdf(&list, 792 * 65_536); + use std::io::Write; + std::io::stdout().write_all(&pdf).expect("write pdf"); +}