Include PDF graphics in the native XeTeX device

This commit is contained in:
gloamxun committed 2026-11-21 13:34:55 +08:00
1 parent facecbf790
commit 794c2f9b2c
19 files changed
+545 -37

No files matched your search

+28 -2
View File
@@ -1020,6 +1020,24 @@ fn page_content(
height: image_height,
image,
} => {
if let Some(placement) = &image.xdv {
let [a, b, c, d, tx, ty] = placement.paint_matrix();
let inch = 72.0 * 1000.0 / f64::from(list.magnification);
let [origin_x, origin_y] = [inch, list.units.bp(height) - inch];
// The XDV driver rounds the image translation relative
// to its page origin, with three decimals by default.
let round = |value: f64| (value * 1000.0).round() / 1000.0;
let x = round(list.units.bp(*x) + tx - origin_x) + round(origin_x)
- list.units.bp(h);
let y = round(list.units.bp(height - *y - *image_height) + ty - origin_y)
+ round(origin_y) - list.units.bp(v);
let [a, b, c, d, x, y] = [a, b, c, d, x, y].map(crate::pdf_image::real);
content.push_str(&format!(
"q {a} {b} {c} {d} {x} {y} cm /PI{} Do Q\n",
image.id
));
continue;
}
let [sx, sy] = if image.image.raster_frame().is_some()
&& list.units == crate::render::DisplayUnits::TeX
{
@@ -1092,9 +1110,12 @@ fn page_content(
content.push(b'\n');
}
DisplayItem::PdfGraphics { x, y, operation } => {
let device_origin = list.units == DisplayUnits::TeX;
let xdv = list.pdf.as_ref().is_some_and(|pdf| pdf.driver == PdfDriver::Xdv);
let device_origin = list.units == DisplayUnits::TeX && !xdv;
if device_origin {
content.move_origin([*x, height - *y], list.units, digits);
} else if xdv {
content.move_origin([0, 0], list.units, digits);
}
match operation {
PdfGraphics::Save => content.push_str("q\n"),
@@ -1106,9 +1127,14 @@ fn page_content(
));
}
}
PdfGraphics::Matrix(matrix) => {
PdfGraphics::Matrix(matrix) | PdfGraphics::SaveMatrix(matrix) => {
if matches!(operation, PdfGraphics::SaveMatrix(_)) {
content.push_str("q\n");
}
let coordinates = if device_origin {
[0.0, 0.0]
} else if xdv {
[list.units.bp(*x), list.units.bp(height - *y)]
} else {
[*x, height - *y].map(|coordinate| {
pt(coordinate).parse::<f64>().expect("formatted PDF dimension")