Skip to contentSkip to conversation

lib/fonts: Fix bit position when rotating by 180 degrees

PATCH Applied Thomas Zimmermann 2 participants 2 messages Apr 28

Subsystems (2)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH 1/1 lib/fonts: Fix bit position when rotating by 180 degrees

Fix the horizontal bit position when rotating a glyph by 180°. The original code in rotate_ud() rounded the value in width up to a multiple of 8, aka the bit pitch, and calculated the rotated pixel from that value. The new code stores the glyph's pitch in bit_pitch, but fails to update the rotated pixel's output accordingly. Simply replacing the variable does this.

The bug can be reproduced by setting a font with an unaligned width, such as sun12x22, like this:

setfont sun12x22
echo 2 > /sys/class/graphics/fbcon/rotate

Without the fix, the font looks distorted.

---
 lib/fonts/font_rotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/fonts/font_rotate.c +1 -1
index 065e0fc0667b..275406008823 100644
@@ -106,7 +106,7 @@ static void __font_glyph_rotate_180(const unsigned char *glyph,
 	for (y = 0; y < height; y++) {
 		for (x = 0; x < width; x++) {
 			if (font_glyph_test_bit(glyph, x, y, bit_pitch)) {
-				font_glyph_set_bit(out, width - (1 + x + shift), height - (1 + y),
+				font_glyph_set_bit(out, bit_pitch - 1 - x - shift, height - 1 - y,
 						   bit_pitch);
 			}
 		}
Signature · 1 line
2.54.0
maintainer Applied
#1 lore raw
Quoted 15 lines · Thomas Zimmermann

Fix the horizontal bit position when rotating a glyph by 180°. The original code in rotate_ud() rounded the value in width up to a multiple of 8, aka the bit pitch, and calculated the rotated pixel from that value. The new code stores the glyph's pitch in bit_pitch, but fails to update the rotated pixel's output accordingly. Simply replacing the variable does this.

The bug can be reproduced by setting a font with an unaligned width, such as sun12x22, like this:

setfont sun12x22
echo 2 > /sys/class/graphics/fbcon/rotate

Without the fix, the font looks distorted.

Quoted 8 lines
---
  lib/fonts/font_rotate.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

applied.
Thanks!
Helge