diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 2adf974..00deace 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -1334,6 +1334,19 @@ mod tests { assert_eq!(text.matches("/Type /Page ").count(), 2); } + #[test] + fn special_content_reaches_the_pdf_stream() { + use crate::render::DisplayList; + let mut list = DisplayList { + width: 612 * 65_536, + height: 792 * 65_536, + items: Vec::new(), + images: Vec::new(), + }; + list.special("0.5 g 10 10 20 20 re f"); + let pdf = crate::pdf::display_list_to_pdf(&list, 792 * 65_536); + assert!(String::from_utf8_lossy(&pdf).contains("0.5 g 10 10 20 20 re f")); + } #[test] fn link_rectangles_become_pdf_annotations() { use crate::render::DisplayList; diff --git a/crates/texrra-tex-core/src/pdf.rs b/crates/texrra-tex-core/src/pdf.rs index fb639b4..f993955 100755 --- a/crates/texrra-tex-core/src/pdf.rs +++ b/crates/texrra-tex-core/src/pdf.rs @@ -70,6 +70,10 @@ fn page_content(list: &DisplayList, height: i64, image_names: &BTreeMap {} + DisplayItem::Special(special) => { + content.push_str(special); + content.push('\n'); + } } } content.push_str("Q\n"); diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index cf6e9c7..f075314 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -38,6 +38,7 @@ pub enum DisplayItem { height: i64, url: String, }, + Special(String), } /// A raw RGB image that can be painted as a PDF XObject. @@ -62,6 +63,10 @@ impl DisplayList { self.items.push(item); } + pub fn special(&mut self, content: &str) { + self.items.push(DisplayItem::Special(content.to_string())); + } + pub fn link(&mut self, x: i64, y: i64, width: i64, height: i64, url: &str) { self.items.push(DisplayItem::Link { x, @@ -93,6 +98,7 @@ impl DisplayList { *x += dx; *y += dy; } + DisplayItem::Special(_) => {} } } } @@ -145,6 +151,13 @@ impl DisplayList { " )); } + DisplayItem::Special(content) => { + out.push_str(&format!( + " +", + escape(content) + )); + } DisplayItem::Image { x, y, diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index c30232c..fb7585c 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -255,3 +255,5 @@ Math painter: stores ; paints symbols, rows, scripts, fractions (with a rule), PDF writer: `src/pdf.rs` emits a one-page PDF 1.4 for a `DisplayList` (Base-14 Times-Roman text, filled rectangle rules, US Letter media box). It is a structural backend spike; TFM/NFSS fonts, XObjects and multi-page output are still open. M6 (partial): display-list Link rectangles become PDF /Annots /Subtype /Link /URI dictionaries. Raw-RGB images are PDF XObjects; /special and embedded font subsets remain. + +M7 (partial): DisplayList::special injects raw PDF content-stream operators; SVG previews show a comment. Driver-level \special parsing and coordinate transforms remain.