Fix: transform `TextShape` underline width (#5865)

Minor bug fix when transforming a `TextShape` with a `underline` (used
for e.g. hyperlinks). Before the underline width would not scale
properly; now it will.
This commit is contained in:
Emil Ernerfeldt 2025-03-30 16:36:03 +02:00 committed by GitHub
parent e3acd71090
commit e275409eb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 7 deletions

View File

@ -456,19 +456,39 @@ impl Shape {
rect_shape.blur_width *= transform.scaling;
}
Self::Text(text_shape) => {
text_shape.pos = transform * text_shape.pos;
let TextShape {
pos,
galley,
underline,
fallback_color: _,
override_text_color: _,
opacity_factor: _,
angle: _,
} = text_shape;
// Scale text:
let galley = Arc::make_mut(&mut text_shape.galley);
for row in &mut galley.rows {
*pos = transform * *pos;
underline.width *= transform.scaling;
let Galley {
job: _,
rows,
elided: _,
rect,
mesh_bounds,
num_vertices: _,
num_indices: _,
pixels_per_point: _,
} = Arc::make_mut(galley);
for row in rows {
row.visuals.mesh_bounds = transform.scaling * row.visuals.mesh_bounds;
for v in &mut row.visuals.mesh.vertices {
v.pos = Pos2::new(transform.scaling * v.pos.x, transform.scaling * v.pos.y);
}
}
galley.mesh_bounds = transform.scaling * galley.mesh_bounds;
galley.rect = transform.scaling * galley.rect;
*mesh_bounds = transform.scaling * *mesh_bounds;
*rect = transform.scaling * *rect;
}
Self::Mesh(mesh) => {
Arc::make_mut(mesh).transform(transform);

View File

@ -8,7 +8,9 @@ use crate::*;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct TextShape {
/// Top left corner of the first character.
/// Where the origin of [`Self::galley`] is.
///
/// Usually the top left corner of the first character.
pub pos: Pos2,
/// The laid out text, from [`Fonts::layout_job`].