Skip to content

Commit 1340a49

Browse files
authored
swrenderer: Always use an offset in the image when rednering glyphs (#6673)
Instead of using the trick of taking a sub-slice and pretending the image was smaller than it is. Then this is more uniform with all the other rendering path. And this should prevent the panic in #6643 Fixes #6643
1 parent 6bb0e60 commit 1340a49

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

internal/core/software_renderer.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,25 +1520,26 @@ impl<'a, T: ProcessScene> SceneBuilder<'a, T> {
15201520
};
15211521
let geometry = clipped_target.translate(offset).round();
15221522
let origin = (geometry.origin - offset.round()).round().cast::<i16>();
1523-
let actual_x = (origin.x - target_rect.origin.x as i16) as usize;
1524-
let actual_y = (origin.y - target_rect.origin.y as i16) as usize;
1523+
let off_x = origin.x - target_rect.origin.x as i16;
1524+
let off_y = origin.y - target_rect.origin.y as i16;
15251525
let pixel_stride = glyph.pixel_stride;
15261526
let mut geometry = geometry.cast();
1527-
if geometry.size.width > glyph.width.get() - (actual_x as i16) {
1528-
geometry.size.width = glyph.width.get() - (actual_x as i16)
1527+
if geometry.size.width > glyph.width.get() - off_x {
1528+
geometry.size.width = glyph.width.get() - off_x
15291529
}
1530-
if geometry.size.height > glyph.height.get() - (actual_y as i16) {
1531-
geometry.size.height = glyph.height.get() - (actual_y as i16)
1530+
if geometry.size.height > glyph.height.get() - off_y {
1531+
geometry.size.height = glyph.height.get() - off_y
15321532
}
15331533
let source_size = geometry.size;
15341534
if source_size.is_empty() {
15351535
continue;
15361536
}
1537+
15371538
match &glyph.alpha_map {
15381539
fonts::GlyphAlphaMap::Static(data) => {
15391540
let texture = if !glyph.sdf {
15401541
SceneTexture {
1541-
data: &data[actual_x + actual_y * pixel_stride as usize..],
1542+
data,
15421543
pixel_stride,
15431544
format: PixelFormat::AlphaMap,
15441545
extra: SceneTextureExtra {
@@ -1548,8 +1549,8 @@ impl<'a, T: ProcessScene> SceneBuilder<'a, T> {
15481549
rotation: self.rotation.orientation,
15491550
dx: Fixed::from_integer(1),
15501551
dy: Fixed::from_integer(1),
1551-
off_x: Fixed::from_integer(0),
1552-
off_y: Fixed::from_integer(0),
1552+
off_x: Fixed::from_integer(off_x as u16),
1553+
off_y: Fixed::from_integer(off_y as u16),
15531554
},
15541555
}
15551556
} else {
@@ -1558,12 +1559,10 @@ impl<'a, T: ProcessScene> SceneBuilder<'a, T> {
15581559
let dy = Fixed::from_integer(
15591560
(data.len() as u16 - 1) / pixel_stride - 1,
15601561
) / (glyph.height.get() as u16 - 1);
1561-
let off_x = Fixed::<i32, 8>::from_fixed(dx)
1562-
* (clipped_target.origin.x - target_rect.origin.x) as i32;
1563-
let off_y = Fixed::<i32, 8>::from_fixed(dy)
1564-
* (clipped_target.origin.y - target_rect.origin.y) as i32;
1562+
let off_x = Fixed::<i32, 8>::from_fixed(dx) * off_x as i32;
1563+
let off_y = Fixed::<i32, 8>::from_fixed(dy) * off_y as i32;
15651564
SceneTexture {
1566-
data: data,
1565+
data,
15671566
pixel_stride,
15681567
format: PixelFormat::SignedDistanceField,
15691568
extra: SceneTextureExtra {
@@ -1589,19 +1588,16 @@ impl<'a, T: ProcessScene> SceneBuilder<'a, T> {
15891588
data: data.clone(),
15901589
width: pixel_stride,
15911590
},
1592-
source_rect: PhysicalRect::new(
1593-
PhysicalPoint::new(actual_x as _, actual_y as _),
1594-
source_size,
1595-
),
1591+
source_rect: PhysicalRect::from_size(source_size),
15961592
extra: SceneTextureExtra {
15971593
colorize: color,
15981594
// color already is mixed with global alpha
15991595
alpha: color.alpha(),
16001596
rotation: self.rotation.orientation,
16011597
dx: Fixed::from_integer(1),
16021598
dy: Fixed::from_integer(1),
1603-
off_x: Fixed::from_integer(0),
1604-
off_y: Fixed::from_integer(0),
1599+
off_x: Fixed::from_integer(off_x as u16),
1600+
off_y: Fixed::from_integer(off_y as u16),
16051601
},
16061602
},
16071603
);

0 commit comments

Comments
 (0)