Embed image XObjects in route-D PDF output
This commit is contained in:
1 parent
7dd3961e21
commit
431bbd14d4
3 files changed
+169
-34
No files matched your search
@@ -24,6 +24,21 @@ pub enum DisplayItem {
|
||||
width: i64,
|
||||
height: i64,
|
||||
},
|
||||
Image {
|
||||
x: i64,
|
||||
y: i64,
|
||||
width: i64,
|
||||
height: i64,
|
||||
index: usize,
|
||||
},
|
||||
}
|
||||
|
||||
/// A raw RGB image that can be painted as a PDF XObject.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct PdfImage {
|
||||
pub width: u32,
|
||||
pub height: u32,
|
||||
pub rgb: Vec<u8>,
|
||||
}
|
||||
|
||||
/// A page-local list of drawing primitives.
|
||||
@@ -32,6 +47,7 @@ pub struct DisplayList {
|
||||
pub width: i64,
|
||||
pub height: i64,
|
||||
pub items: Vec<DisplayItem>,
|
||||
pub images: Vec<PdfImage>,
|
||||
}
|
||||
|
||||
impl DisplayList {
|
||||
@@ -39,6 +55,11 @@ impl DisplayList {
|
||||
self.items.push(item);
|
||||
}
|
||||
|
||||
pub fn add_image(&mut self, image: PdfImage) -> usize {
|
||||
self.images.push(image);
|
||||
self.images.len() - 1
|
||||
}
|
||||
|
||||
/// Offset every primitive, used when placing a nested table on a page.
|
||||
pub fn place(&mut self, dx: i64, dy: i64) {
|
||||
for item in &mut self.items {
|
||||
@@ -51,6 +72,10 @@ impl DisplayList {
|
||||
*x += dx;
|
||||
*y += dy;
|
||||
}
|
||||
DisplayItem::Image { x, y, .. } => {
|
||||
*x += dx;
|
||||
*y += dy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,6 +112,21 @@ impl DisplayList {
|
||||
"<rect x=\"{x:.3}\" y=\"{y:.3}\" width=\"{width:.3}\" height=\"{height:.3}\" fill=\"black\"/>\n"
|
||||
));
|
||||
}
|
||||
DisplayItem::Image {
|
||||
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=\"#cccccc\"/>\n"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
out.push_str("</svg>\n");
|
||||
@@ -108,6 +148,7 @@ impl Halign {
|
||||
width: self.width,
|
||||
height: self.height,
|
||||
items: Vec::new(),
|
||||
images: Vec::new(),
|
||||
};
|
||||
let mut y = 0_i64;
|
||||
for (row_index, row) in self.rows.iter().enumerate() {
|
||||
|
||||
Reference in new issue
Block a user