Fix auto size rendering of SVG images in Markdown (#36663)
Release Notes: - Fixed auto size rendering of SVG images in Markdown. ## Before <img width="836" height="844" alt="image" src="https://github.com/user-attachments/assets/0782e17e-620f-4c29-a5bc-a2ffe877d220" /> <img width="691" height="678" alt="image" src="https://github.com/user-attachments/assets/dbe2dd5f-fd5b-48f9-bd09-0ee35e116aec" /> ## After <img width="873" height="1015" alt="image" src="https://github.com/user-attachments/assets/59cbb69f-6a81-43cb-989f-3bcea873d81e" /> <img width="647" height="598" alt="image" src="https://github.com/user-attachments/assets/11b67d8e-2b6c-4245-ad13-d4616fdabf22" /> For GPUI example ``` cargo run -p gpui --example image ``` <img width="1212" height="740" alt="SCR-20250821-ojoy" src="https://github.com/user-attachments/assets/62bb2847-c533-4c4d-b5f7-c9764796262a" />
This commit is contained in:
@@ -332,20 +332,18 @@ impl Element for Img {
|
||||
state.started_loading = None;
|
||||
}
|
||||
|
||||
let image_size = data.size(frame_index);
|
||||
style.aspect_ratio =
|
||||
Some(image_size.width.0 as f32 / image_size.height.0 as f32);
|
||||
let image_size = data.render_size(frame_index);
|
||||
style.aspect_ratio = Some(image_size.width / image_size.height);
|
||||
|
||||
if let Length::Auto = style.size.width {
|
||||
style.size.width = match style.size.height {
|
||||
Length::Definite(DefiniteLength::Absolute(
|
||||
AbsoluteLength::Pixels(height),
|
||||
)) => Length::Definite(
|
||||
px(image_size.width.0 as f32 * height.0
|
||||
/ image_size.height.0 as f32)
|
||||
.into(),
|
||||
px(image_size.width.0 * height.0 / image_size.height.0)
|
||||
.into(),
|
||||
),
|
||||
_ => Length::Definite(px(image_size.width.0 as f32).into()),
|
||||
_ => Length::Definite(image_size.width.into()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -354,11 +352,10 @@ impl Element for Img {
|
||||
Length::Definite(DefiniteLength::Absolute(
|
||||
AbsoluteLength::Pixels(width),
|
||||
)) => Length::Definite(
|
||||
px(image_size.height.0 as f32 * width.0
|
||||
/ image_size.width.0 as f32)
|
||||
.into(),
|
||||
px(image_size.height.0 * width.0 / image_size.width.0)
|
||||
.into(),
|
||||
),
|
||||
_ => Length::Definite(px(image_size.height.0 as f32).into()),
|
||||
_ => Length::Definite(image_size.height.into()),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -701,7 +698,9 @@ impl Asset for ImageAssetLoader {
|
||||
swap_rgba_pa_to_bgra(pixel);
|
||||
}
|
||||
|
||||
RenderImage::new(SmallVec::from_elem(Frame::new(buffer), 1))
|
||||
let mut image = RenderImage::new(SmallVec::from_elem(Frame::new(buffer), 1));
|
||||
image.scale_factor = SMOOTH_SVG_SCALE_FACTOR;
|
||||
image
|
||||
};
|
||||
|
||||
Ok(Arc::new(data))
|
||||
|
||||
Reference in New Issue
Block a user