Fix image support

This commit is contained in:
Isaac Mills 2024-04-19 11:06:46 -04:00
parent dfd8e5d86c
commit a0355d2c71
Signed by: fnmain
GPG key ID: B67D7410F33A0F61

View file

@ -252,16 +252,21 @@ pub fn resolve_paragraphs<'a>(
buffer.relative_bounds.translate(Vec2::new(ls.x, 0.0)); buffer.relative_bounds.translate(Vec2::new(ls.x, 0.0));
} }
} else { } else {
if image_size.x > viewbox.x { if image_size.x <= viewbox.x {
let max_size = Vec2::new(viewbox.x, image_size.y);
let new_size = scale_to_fit(image_size, max_size, true);
buffer.relative_bounds =
Rect::from_min_size(Pos2::new(buffer.indent.indent, size.y), new_size);
size.y += new_size.y
} else {
last_image_size = Some(image_size + Vec2::new(IMAGE_PADDING, margin)); last_image_size = Some(image_size + Vec2::new(IMAGE_PADDING, margin));
} }
} }
if image_size.x > viewbox.x {
let max_size = Vec2::new(viewbox.x, image_size.y);
let new_size = scale_to_fit(image_size, max_size, true);
buffer.relative_bounds =
Rect::from_min_size(Pos2::new(buffer.indent.indent, size.y), new_size);
if last_image_size.is_none() {
size.y += new_size.y
}
}
[Some(buffer), None] [Some(buffer), None]
} else if let Some(mut list_kind) = buffer.indent.modifier { } else if let Some(mut list_kind) = buffer.indent.modifier {
if let Some(image_size) = last_image_size { if let Some(image_size) = last_image_size {
@ -319,8 +324,6 @@ pub fn resolve_paragraphs<'a>(
}), }),
]; ];
size.y += buffer_size.y + (margin_top + margin); size.y += buffer_size.y + (margin_top + margin);
last_margin = margin;
first = false;
size.x = size.x.max(buffer_size.x + buffer_indent); size.x = size.x.max(buffer_size.x + buffer_indent);
res res
} else { } else {
@ -335,13 +338,14 @@ pub fn resolve_paragraphs<'a>(
in_list = false; in_list = false;
size.y += buffer_size.y + (margin_top + margin); size.y += buffer_size.y + (margin_top + margin);
last_margin = margin;
first = false;
size.x = size.x.max(buffer_size.x + buffer_indent); size.x = size.x.max(buffer_size.x + buffer_indent);
[Some(buffer), None] [Some(buffer), None]
}; };
last_margin = margin;
first = false;
result_buffers result_buffers
}) })
.filter_map(|p| p) .filter_map(|p| p)