Inject raw PDF specials from display lists
This commit is contained in:
1 parent
da7f580bf0
commit
eac5bd649a
4 files changed
+32
No files matched your search
@@ -1334,6 +1334,19 @@ mod tests {
|
|||||||
assert_eq!(text.matches("/Type /Page ").count(), 2);
|
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]
|
#[test]
|
||||||
fn link_rectangles_become_pdf_annotations() {
|
fn link_rectangles_become_pdf_annotations() {
|
||||||
use crate::render::DisplayList;
|
use crate::render::DisplayList;
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ fn page_content(list: &DisplayList, height: i64, image_names: &BTreeMap<usize, S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DisplayItem::Link { .. } => {}
|
DisplayItem::Link { .. } => {}
|
||||||
|
DisplayItem::Special(special) => {
|
||||||
|
content.push_str(special);
|
||||||
|
content.push('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content.push_str("Q\n");
|
content.push_str("Q\n");
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ pub enum DisplayItem {
|
|||||||
height: i64,
|
height: i64,
|
||||||
url: String,
|
url: String,
|
||||||
},
|
},
|
||||||
|
Special(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A raw RGB image that can be painted as a PDF XObject.
|
/// A raw RGB image that can be painted as a PDF XObject.
|
||||||
@@ -62,6 +63,10 @@ impl DisplayList {
|
|||||||
self.items.push(item);
|
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) {
|
pub fn link(&mut self, x: i64, y: i64, width: i64, height: i64, url: &str) {
|
||||||
self.items.push(DisplayItem::Link {
|
self.items.push(DisplayItem::Link {
|
||||||
x,
|
x,
|
||||||
@@ -93,6 +98,7 @@ impl DisplayList {
|
|||||||
*x += dx;
|
*x += dx;
|
||||||
*y += dy;
|
*y += dy;
|
||||||
}
|
}
|
||||||
|
DisplayItem::Special(_) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,6 +151,13 @@ impl DisplayList {
|
|||||||
"
|
"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
DisplayItem::Special(content) => {
|
||||||
|
out.push_str(&format!(
|
||||||
|
"<!-- special: {} -->
|
||||||
|
",
|
||||||
|
escape(content)
|
||||||
|
));
|
||||||
|
}
|
||||||
DisplayItem::Image {
|
DisplayItem::Image {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
|
|||||||
@@ -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.
|
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.
|
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.
|
||||||
Reference in new issue
Block a user