diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-10-05 20:05:15 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-10-05 20:05:15 +0200 |
| commit | b69c0355ecda6a2da275cac42fcb0dfa9e31581b (patch) | |
| tree | 7cc9ee9de4ce834f4b123459acbdd65fc65d8713 /src/layout | |
| parent | 3d0dcbea182f6a81539c12c9d5156cf0f6863b67 (diff) | |
Don't fit images to remaining height
Makes them really small if there's only little space left ...
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/image.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/layout/image.rs b/src/layout/image.rs index 94f57167..81c48b3e 100644 --- a/src/layout/image.rs +++ b/src/layout/image.rs @@ -1,8 +1,6 @@ use super::*; use crate::image::ImageId; -use ::image::GenericImageView; - /// An image node. #[derive(Debug)] #[cfg_attr(feature = "layout-cache", derive(Hash))] @@ -27,27 +25,22 @@ impl Layout for ImageNode { let width = self.width.map(|w| w.resolve(base.w)); let height = self.height.map(|w| w.resolve(base.h)); - let dimensions = ctx.images.get(self.id).buf.dimensions(); - let pixel_width = dimensions.0 as f64; - let pixel_height = dimensions.1 as f64; - let pixel_ratio = pixel_width / pixel_height; + let img = ctx.images.get(self.id); + let pixel_size = Spec::new(img.width() as f64, img.height() as f64); + let pixel_ratio = pixel_size.x / pixel_size.y; let size = match (width, height) { (Some(width), Some(height)) => Size::new(width, height), (Some(width), None) => Size::new(width, width / pixel_ratio), (None, Some(height)) => Size::new(height * pixel_ratio, height), (None, None) => { - constraints.exact = current.to_spec().map(Some); - - let ratio = current.w / current.h; - if ratio < pixel_ratio && current.w.is_finite() { + constraints.exact.x = Some(current.w); + if current.w.is_finite() { Size::new(current.w, current.w / pixel_ratio) - } else if current.h.is_finite() { - // TODO: Fix issue with line spacing. - Size::new(current.h * pixel_ratio, current.h) } else { - // Totally unbounded region, we have to make up something. - Size::new(Length::pt(pixel_width), Length::pt(pixel_height)) + // Totally unbounded region, we have to make up something, + // so it is 1pt per pixel. + pixel_size.map(Length::pt).to_size() } } }; |
