diff options
| author | Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> | 2024-06-11 13:12:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-11 11:12:03 +0000 |
| commit | 20b8d2c121c713cb32f6048df6435735a0c0262f (patch) | |
| tree | 814200144bc59fea2ad9d10d8920883218958334 | |
| parent | 2b064ba197b4a286ce40cc12db08ae8cf4f4b246 (diff) | |
Don't change DPI in resvg (#4354)
| -rw-r--r-- | crates/typst/src/visualize/image/mod.rs | 5 | ||||
| -rw-r--r-- | crates/typst/src/visualize/image/svg.rs | 8 | ||||
| -rw-r--r-- | tests/ref/figure-table.png | bin | 2973 -> 2851 bytes | |||
| -rw-r--r-- | tests/ref/image-svg-text-font.png | bin | 1363 -> 1225 bytes |
4 files changed, 8 insertions, 5 deletions
diff --git a/crates/typst/src/visualize/image/mod.rs b/crates/typst/src/visualize/image/mod.rs index e5916f1d..fbbedfb3 100644 --- a/crates/typst/src/visualize/image/mod.rs +++ b/crates/typst/src/visualize/image/mod.rs @@ -329,6 +329,9 @@ impl Image { /// if the image doesn't contain DPI metadata. pub const DEFAULT_DPI: f64 = 72.0; + /// Should always be the same as the default DPI used by usvg. + pub const USVG_DEFAULT_DPI: f64 = 96.0; + /// Create an image from a buffer and a format. #[comemo::memoize] #[typst_macros::time(name = "load image")] @@ -407,7 +410,7 @@ impl Image { pub fn dpi(&self) -> Option<f64> { match &self.0.kind { ImageKind::Raster(raster) => raster.dpi(), - ImageKind::Svg(_) => None, + ImageKind::Svg(_) => Some(Image::USVG_DEFAULT_DPI), } } diff --git a/crates/typst/src/visualize/image/svg.rs b/crates/typst/src/visualize/image/svg.rs index 399d8d5a..09319ccd 100644 --- a/crates/typst/src/visualize/image/svg.rs +++ b/crates/typst/src/visualize/image/svg.rs @@ -12,7 +12,6 @@ use crate::layout::Axes; use crate::text::{ Font, FontBook, FontFlags, FontStretch, FontStyle, FontVariant, FontWeight, }; -use crate::visualize::Image; use crate::World; /// A decoded SVG. @@ -102,9 +101,10 @@ fn base_options() -> usvg::Options<'static> { // Disable usvg's default to "Times New Roman". font_family: String::new(), - // We override the DPI here so that we get the correct the size when - // scaling the image to its natural size. - dpi: Image::DEFAULT_DPI as f32, + // We don't override the DPI here, because we already + // force the image into the corresponding DPI by setting + // the width and height. Changing the DPI only trips up + // the logic in `resvg`. // Override usvg's resource loading defaults. resources_dir: None, diff --git a/tests/ref/figure-table.png b/tests/ref/figure-table.png Binary files differindex 9a09f659..5e013f42 100644 --- a/tests/ref/figure-table.png +++ b/tests/ref/figure-table.png diff --git a/tests/ref/image-svg-text-font.png b/tests/ref/image-svg-text-font.png Binary files differindex 2e3b0a0f..972c0564 100644 --- a/tests/ref/image-svg-text-font.png +++ b/tests/ref/image-svg-text-font.png |
