diff --git a/crates/typst-pdf/src/image.rs b/crates/typst-pdf/src/image.rs index a4833e6e3..312c2abba 100644 --- a/crates/typst-pdf/src/image.rs +++ b/crates/typst-pdf/src/image.rs @@ -18,7 +18,7 @@ pub fn deferred_image(image: Image) -> Deferred { Deferred::new(move || match image.kind() { ImageKind::Raster(raster) => { let raster = raster.clone(); - let (width, height) = (image.width(), image.height()); + let (width, height) = (raster.width(), raster.height()); let (data, filter, has_color) = encode_raster_image(&raster); let icc = raster.icc().map(deflate); diff --git a/crates/typst-render/src/lib.rs b/crates/typst-render/src/lib.rs index afdfeeef1..8c519795e 100644 --- a/crates/typst-render/src/lib.rs +++ b/crates/typst-render/src/lib.rs @@ -352,7 +352,7 @@ fn render_bitmap_glyph( // and maybe also for Noto Color Emoji. And: Is the size calculation // correct? let h = text.size; - let w = (image.width() as f64 / image.height() as f64) * h; + let w = (image.width() / image.height()) * h; let dx = (raster.x as f32) / (image.width() as f32) * size; let dy = (raster.y as f32) / (image.height() as f32) * size; render_image( @@ -742,7 +742,7 @@ fn scaled_texture(image: &Image, w: u32, h: u32) -> Option> { let mut pixmap = sk::Pixmap::new(w, h)?; match image.kind() { ImageKind::Raster(raster) => { - let downscale = w < image.width(); + let downscale = w < raster.width(); let filter = if downscale { FilterType::Lanczos3 } else { FilterType::CatmullRom }; let buf = raster.dynamic().resize(w, h, filter); diff --git a/crates/typst-svg/src/lib.rs b/crates/typst-svg/src/lib.rs index 2c69e6d9a..4d5422964 100644 --- a/crates/typst-svg/src/lib.rs +++ b/crates/typst-svg/src/lib.rs @@ -409,8 +409,8 @@ impl SVGRenderer { let glyph_hash = hash128(&(&text.font, id)); let id = self.glyphs.insert_with(glyph_hash, || { - let width = image.width() as f64; - let height = image.height() as f64; + let width = image.width(); + let height = image.height(); let url = convert_image_to_base64_url(&image); let ts = Transform::translate( Abs::pt(bitmap_x_offset), @@ -426,7 +426,7 @@ impl SVGRenderer { // The image is stored with the height of `image.height()`, but we want // to render it with a height of `target_height`. So we need to scale // it. - let scale_factor = target_height / image.height() as f64; + let scale_factor = target_height / image.height(); self.xml.write_attribute("x", &(x_offset / scale_factor)); self.xml.write_attribute_fmt( "transform", diff --git a/crates/typst/src/visualize/image/mod.rs b/crates/typst/src/visualize/image/mod.rs index abf7a77fd..dc58bf801 100644 --- a/crates/typst/src/visualize/image/mod.rs +++ b/crates/typst/src/visualize/image/mod.rs @@ -379,17 +379,17 @@ impl Image { } /// The width of the image in pixels. - pub fn width(&self) -> u32 { + pub fn width(&self) -> f64 { match &self.0.kind { - ImageKind::Raster(raster) => raster.width(), + ImageKind::Raster(raster) => raster.width() as f64, ImageKind::Svg(svg) => svg.width(), } } /// The height of the image in pixels. - pub fn height(&self) -> u32 { + pub fn height(&self) -> f64 { match &self.0.kind { - ImageKind::Raster(raster) => raster.height(), + ImageKind::Raster(raster) => raster.height() as f64, ImageKind::Svg(svg) => svg.height(), } } diff --git a/crates/typst/src/visualize/image/svg.rs b/crates/typst/src/visualize/image/svg.rs index 20e1b0b9a..fe4968077 100644 --- a/crates/typst/src/visualize/image/svg.rs +++ b/crates/typst/src/visualize/image/svg.rs @@ -20,7 +20,7 @@ pub struct SvgImage(Arc); /// The internal representation. struct Repr { data: Bytes, - size: Axes, + size: Axes, font_hash: u128, tree: sync::SyncTree, } @@ -76,12 +76,12 @@ impl SvgImage { } /// The SVG's width in pixels. - pub fn width(&self) -> u32 { + pub fn width(&self) -> f64 { self.0.size.x } /// The SVG's height in pixels. - pub fn height(&self) -> u32 { + pub fn height(&self) -> f64 { self.0.size.y } @@ -222,8 +222,8 @@ where } /// The ceiled pixel size of an SVG. -fn tree_size(tree: &usvg::Tree) -> Axes { - Axes::new(tree.size.width().ceil() as u32, tree.size.height().ceil() as u32) +fn tree_size(tree: &usvg::Tree) -> Axes { + Axes::new(tree.size.width() as f64, tree.size.height() as f64) } /// Format the user-facing SVG decoding error message.