fix: top align fonts

typescript_changes
flop 3 weeks ago
parent 6e169930f7
commit 9a1d9c1d6a
  1. 4
      ts/src/font/u8g2.ts

@ -265,11 +265,11 @@ export function rasterizeText(
const pixels = new Uint8Array(totalW * cellHeight); const pixels = new Uint8Array(totalW * cellHeight);
// Centre the full font (ascent + |descent|) vertically in the cell. // Top-align the full font (ascent + |descent|) within the cell.
// header byte 14 is descent of 'g' - stored as a negative signed value. // header byte 14 is descent of 'g' - stored as a negative signed value.
const descent = font.FONT_DATA[14]! > 127 ? font.FONT_DATA[14]! - 256 : font.FONT_DATA[14]!; const descent = font.FONT_DATA[14]! > 127 ? font.FONT_DATA[14]! - 256 : font.FONT_DATA[14]!;
const fontH = hdr.ascentA - descent; // total font height in pixels const fontH = hdr.ascentA - descent; // total font height in pixels
const topPad = Math.floor((cellHeight - fontH) / 2); const topPad = 0;
const baseline = topPad + hdr.ascentA; const baseline = topPad + hdr.ascentA;
let x = 0; let x = 0;

Loading…
Cancel
Save