Ship XDV annotations from measured page ranges

This commit is contained in:
gloamxun committed 2026-11-25 21:12:44 +08:00
1 parent 515dbe6181
commit 20986b2fd5
16 files changed
+873 -54

No files matched your search

+13 -2
View File
@@ -62,6 +62,8 @@ pub(crate) struct XdvPdfPlacement {
matrix: [u64; 6],
#[serde(default, skip_serializing_if = "Option::is_none")]
clip: Option<[u64; 4]>,
#[serde(default, skip_serializing_if = "Option::is_none")]
annotation_box: Option<[u64; 4]>,
#[serde(default)]
pub(crate) layout_offset: [i64; 2],
}
@@ -74,6 +76,11 @@ impl XdvPdfPlacement {
pub(crate) fn clip(&self) -> Option<[f64; 4]> {
self.clip.map(|rect| rect.map(f64::from_bits))
}
pub(crate) fn annotation_box(&self) -> [f64; 4] {
self.annotation_box.or(self.clip)
.map_or([0.0, 0.0, 1.0, 1.0], |rect| rect.map(f64::from_bits))
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
@@ -175,6 +182,7 @@ impl PdfImageUse {
page_request,
matrix: matrix.map(f64::to_bits),
clip: None,
annotation_box: None,
layout_offset: [0, 0],
}),
})
@@ -184,13 +192,15 @@ impl PdfImageUse {
id: usize,
image: Arc<PdfImage>,
matrix: Affine,
clip: Option<[f64; 4]>,
annotation_box: Option<[f64; 4]>,
clip: bool,
) -> Result<Self, String> {
if matrix.0.iter().any(|value| !value.is_finite())
|| clip.is_some_and(|rect| rect.iter().any(|value| !value.is_finite()))
|| annotation_box.is_some_and(|rect| rect.iter().any(|value| !value.is_finite()))
{
return Err("XDV raster image transform exceeds capacity".into());
}
let clip = if clip { annotation_box } else { None };
let [x, y, w, h] = clip.unwrap_or([0.0, 0.0, 1.0, 1.0]);
let [x0, y0, x1, y1] = [x, y, x + w, y + h].map(|value| value.clamp(0.0, 1.0));
let [left, bottom] = matrix.point(x0, y0);
@@ -217,6 +227,7 @@ impl PdfImageUse {
page_request: 0,
matrix: matrix.map(f64::to_bits),
clip: clip.map(|rect| rect.map(f64::to_bits)),
annotation_box: annotation_box.map(|rect| rect.map(f64::to_bits)),
layout_offset: [left as i64, bottom as i64],
}),
})