Apply native PDF page dictionaries and viewport projection
This commit is contained in:
1 parent
a6ba70aa46
commit
d1ddf4bfeb
19 files changed
+410
-40
No files matched your search
@@ -317,6 +317,11 @@ impl DisplayList {
|
||||
}))
|
||||
}
|
||||
|
||||
/// Physical size of one PDF user space unit, in big points.
|
||||
pub fn pdf_user_unit(&self) -> f64 {
|
||||
self.pdf_resources.viewport.as_ref().map_or(1.0, |viewport| viewport.unit())
|
||||
}
|
||||
|
||||
/// Compare the inputs consumed by SVG rendering. Font data for glyphs not
|
||||
/// present on this page and source locations do not affect its SVG.
|
||||
pub fn same_svg_paint(&self, other: &Self) -> bool {
|
||||
@@ -326,6 +331,7 @@ impl DisplayList {
|
||||
&& self.magnification == other.magnification
|
||||
&& self.images == other.images
|
||||
&& self.pdf_resources.opacity == other.pdf_resources.opacity
|
||||
&& self.pdf_resources.viewport == other.pdf_resources.viewport
|
||||
&& self.pdf_resources.needs_pdf_for_preview == other.pdf_resources.needs_pdf_for_preview
|
||||
&& self.items.len() == other.items.len()
|
||||
&& self.items.iter().zip(&other.items).all(|(left, right)| {
|
||||
@@ -435,10 +441,16 @@ impl DisplayList {
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let (physical_width, physical_height) = (width * mag, height * mag);
|
||||
let viewport = self.pdf_resources.viewport.as_ref();
|
||||
let [physical_width, physical_height] = viewport
|
||||
.map_or([width * mag, height * mag], |geometry| geometry.dimensions());
|
||||
let mut out = format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"{physical_width:.3}pt\" height=\"{physical_height:.3}pt\" viewBox=\"0 0 {physical_width:.3} {physical_height:.3}\">\n"
|
||||
);
|
||||
if let Some(viewport) = viewport {
|
||||
let [a, b, c, d, e, f] = viewport.transform(height * mag).0;
|
||||
out.push_str(&format!("<g transform=\"matrix({a} {b} {c} {d} {e} {f})\">\n"));
|
||||
}
|
||||
if self.magnification != 1000 || self.units == DisplayUnits::TeX {
|
||||
out.push_str(&format!("<g transform=\"scale({mag:.12})\">\n"));
|
||||
}
|
||||
@@ -761,6 +773,9 @@ impl DisplayList {
|
||||
if self.magnification != 1000 || self.units == DisplayUnits::TeX {
|
||||
out.push_str("</g>\n");
|
||||
}
|
||||
if viewport.is_some() {
|
||||
out.push_str("</g>\n");
|
||||
}
|
||||
out.push_str("</svg>\n");
|
||||
out
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user