mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Don't change DPI in resvg (#4354)
This commit is contained in:
parent
2b064ba197
commit
20b8d2c121
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
x
Reference in New Issue
Block a user