From e5b0a385964ae3feddc2b8a6208eb99d6c303045 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Mon, 11 Dec 2023 23:24:43 +0100 Subject: [PATCH 1/2] Initial --- lib/python/qmk/painter_qff.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/python/qmk/painter_qff.py b/lib/python/qmk/painter_qff.py index 746bb166e52..ecf1347b9cf 100644 --- a/lib/python/qmk/painter_qff.py +++ b/lib/python/qmk/painter_qff.py @@ -22,6 +22,11 @@ def o24(i): class QFFGlyphInfo(AttrDict): + GLYPH_WIDTH_BITS = 6 + GLYPH_WIDTH_MASK = (1 << GLYPH_WIDTH_BITS) - 1 + GLYPH_OFFSET_BITS = 18 + GLYPH_OFFSET_MASK = ((1 << GLYPH_OFFSET_BITS) - 1) << GLYPH_WIDTH_BITS + def __init__(self, *args, **kwargs): super().__init__() @@ -35,7 +40,7 @@ class QFFGlyphInfo(AttrDict): if include_code_point is True: fp.write(o24(ord(self.code_point))) - value = ((self.data_offset << 6) & 0xFFFFC0) | (self.w & 0x3F) + value = ((self.data_offset << self.GLYPH_WIDTH_BITS) & self.GLYPH_OFFSET_MASK) | (self.w & self.GLYPH_WIDTH_MASK) fp.write(o24(value)) @@ -228,8 +233,18 @@ class QFFFont: last_offset = 0 for x in range(1, width): if pixels[x, 0] == glyph_split_color: + if x > ((1 << QFFGlyphInfo.GLYPH_OFFSET_BITS) - 1): + self.logger.error("A glyph has too big of an offset for QFF's encoding") + exit(1) glyph_pixel_offsets.append(x) - glyph_pixel_widths.append(x - last_offset) + + + width = x - last_offset + if width > QFFGlyphInfo.GLYPH_WIDTH_MASK: + self.logger.error("A glyph is too wide for QFF's encoding") + exit(1) + glyph_pixel_widths.append(width) + last_offset = x glyph_pixel_widths.append(width - last_offset) From fa08bf3545e28fc0f89e9befc14d81a17853c488 Mon Sep 17 00:00:00 2001 From: elpekenin Date: Mon, 11 Dec 2023 23:29:46 +0100 Subject: [PATCH 2/2] Remove extra newline --- lib/python/qmk/painter_qff.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/python/qmk/painter_qff.py b/lib/python/qmk/painter_qff.py index ecf1347b9cf..f7f8a264930 100644 --- a/lib/python/qmk/painter_qff.py +++ b/lib/python/qmk/painter_qff.py @@ -238,7 +238,6 @@ class QFFFont: exit(1) glyph_pixel_offsets.append(x) - width = x - last_offset if width > QFFGlyphInfo.GLYPH_WIDTH_MASK: self.logger.error("A glyph is too wide for QFF's encoding")