Emit PDF link annotations from display lists
This commit is contained in:
1 parent
431bbd14d4
commit
da7f580bf0
4 files changed
+103
-2
No files matched your search
@@ -31,6 +31,13 @@ pub enum DisplayItem {
|
||||
height: i64,
|
||||
index: usize,
|
||||
},
|
||||
Link {
|
||||
x: i64,
|
||||
y: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
url: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// A raw RGB image that can be painted as a PDF XObject.
|
||||
@@ -55,6 +62,16 @@ impl DisplayList {
|
||||
self.items.push(item);
|
||||
}
|
||||
|
||||
pub fn link(&mut self, x: i64, y: i64, width: i64, height: i64, url: &str) {
|
||||
self.items.push(DisplayItem::Link {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
url: url.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn add_image(&mut self, image: PdfImage) -> usize {
|
||||
self.images.push(image);
|
||||
self.images.len() - 1
|
||||
@@ -72,7 +89,7 @@ impl DisplayList {
|
||||
*x += dx;
|
||||
*y += dy;
|
||||
}
|
||||
DisplayItem::Image { x, y, .. } => {
|
||||
DisplayItem::Image { x, y, .. } | DisplayItem::Link { x, y, .. } => {
|
||||
*x += dx;
|
||||
*y += dy;
|
||||
}
|
||||
@@ -112,6 +129,22 @@ impl DisplayList {
|
||||
"<rect x=\"{x:.3}\" y=\"{y:.3}\" width=\"{width:.3}\" height=\"{height:.3}\" fill=\"black\"/>\n"
|
||||
));
|
||||
}
|
||||
DisplayItem::Link {
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
..
|
||||
} => {
|
||||
let x = *x as f64 / 65_536.0;
|
||||
let y = *y as f64 / 65_536.0;
|
||||
let width = *width as f64 / 65_536.0;
|
||||
let height = *height as f64 / 65_536.0;
|
||||
out.push_str(&format!(
|
||||
"<rect x=\"{x:.3}\" y=\"{y:.3}\" width=\"{width:.3}\" height=\"{height:.3}\" fill=\"none\" stroke=\"#008000\"/>
|
||||
"
|
||||
));
|
||||
}
|
||||
DisplayItem::Image {
|
||||
x,
|
||||
y,
|
||||
|
||||
Reference in new issue
Block a user