From 272a4c228976466e9fa6cc100ad89f93dc5cc371 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 13 Jan 2021 23:19:44 +0100 Subject: =?UTF-8?q?Unbounded=20pages=20=F0=9F=8C=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/library/insert.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/library/insert.rs') diff --git a/src/library/insert.rs b/src/library/insert.rs index 8d60927a..51cbbf52 100644 --- a/src/library/insert.rs +++ b/src/library/insert.rs @@ -55,8 +55,11 @@ struct NodeImage { impl Layout for NodeImage { fn layout(&self, _: &mut LayoutContext, areas: &Areas) -> Layouted { - let Area { rem, full } = areas.current; - let pixel_ratio = (self.dimensions.0 as f64) / (self.dimensions.1 as f64); + let Areas { current, full, .. } = areas; + + let pixel_width = self.dimensions.0 as f64; + let pixel_height = self.dimensions.1 as f64; + let pixel_ratio = pixel_width / pixel_height; let width = self.width.map(|w| w.resolve(full.width)); let height = self.height.map(|w| w.resolve(full.height)); @@ -66,12 +69,15 @@ impl Layout for NodeImage { (Some(width), None) => Size::new(width, width / pixel_ratio), (None, Some(height)) => Size::new(height * pixel_ratio, height), (None, None) => { - let ratio = rem.width / rem.height; - if ratio < pixel_ratio { - Size::new(rem.width, rem.width / pixel_ratio) - } else { + let ratio = current.width / current.height; + if ratio < pixel_ratio && current.width.is_finite() { + Size::new(current.width, current.width / pixel_ratio) + } else if current.height.is_finite() { // TODO: Fix issue with line spacing. - Size::new(rem.height * pixel_ratio, rem.height) + Size::new(current.height * pixel_ratio, current.height) + } else { + // Totally unbounded area, we have to make up something. + Size::new(Length::pt(pixel_width), Length::pt(pixel_height)) } } }; -- cgit v1.2.3