diff --git a/crates/typst/src/visualize/image/mod.rs b/crates/typst/src/visualize/image/mod.rs index e5916f1d4..fbbedfb3e 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 { 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 399d8d5ad..09319ccde 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 index 9a09f6590..5e013f422 100644 Binary files a/tests/ref/figure-table.png and b/tests/ref/figure-table.png differ diff --git a/tests/ref/image-svg-text-font.png b/tests/ref/image-svg-text-font.png index 2e3b0a0f5..972c0564b 100644 Binary files a/tests/ref/image-svg-text-font.png and b/tests/ref/image-svg-text-font.png differ