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);
|
||||
}
|
||||
|
||||
#[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;
|
||||
|
||||
@@ -70,6 +70,10 @@ fn page_content(list: &DisplayList, height: i64, image_names: &BTreeMap<usize, S
|
||||
}
|
||||
}
|
||||
DisplayItem::Link { .. } => {}
|
||||
DisplayItem::Special(special) => {
|
||||
content.push_str(special);
|
||||
content.push('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
content.push_str("Q\n");
|
||||
|
||||
@@ -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!(
|
||||
"<!-- special: {} -->
|
||||
",
|
||||
escape(content)
|
||||
));
|
||||
}
|
||||
DisplayItem::Image {
|
||||
x,
|
||||
y,
|
||||
|
||||
Reference in new issue
Block a user