From c974b4ef4300bd7c3ccea510dd05b3f3dd6325f4 Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Wed, 15 Jul 2026 23:21:40 +0300 Subject: [PATCH] Support Unicode cmap platform records --- src/pixie/fontformats/opentype.nim | 6 +++--- tests/test_fonts.nim | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/pixie/fontformats/opentype.nim b/src/pixie/fontformats/opentype.nim index 537257a6..05d2bad2 100644 --- a/src/pixie/fontformats/opentype.nim +++ b/src/pixie/fontformats/opentype.nim @@ -450,8 +450,8 @@ proc parseCmapTable(buf: string, offset: int): CmapTable = encodingRecord.offset = buf.readUint32(i + 4).swap() i += 8 - if encodingRecord.platformID == 3: - # Windows + if encodingRecord.platformID in [0'u16, 3'u16]: + # Unicode or Windows var i = offset + encodingRecord.offset.int buf.eofCheck(i + 2) @@ -563,7 +563,7 @@ proc parseCmapTable(buf: string, offset: int): CmapTable = # TODO implement other windows formats discard else: - # TODO implement other cmap platformIDs + # TODO implement legacy cmap platform IDs. discard proc parseHeadTable(buf: string, offset: int): HeadTable = diff --git a/tests/test_fonts.nim b/tests/test_fonts.nim index debaaa78..0c87491a 100644 --- a/tests/test_fonts.nim +++ b/tests/test_fonts.nim @@ -4,6 +4,21 @@ proc wh(image: Image): Vec2 = ## Return with and height as a size vector. vec2(image.width.float32, image.height.float32) +block: + var data = readFile("tests/fonts/Ubuntu-Regular_1.ttf") + let + original = parseOpenType(data) + cmapOffset = original.tableRecords["cmap"].offset.int + encodingCount = data[cmapOffset + 2].ord shl 8 or data[cmapOffset + 3].ord + + for index in 0 ..< encodingCount: + let recordOffset = cmapOffset + 4 + index * 8 + data[recordOffset] = '\0' + data[recordOffset + 1] = '\0' + + let unicodeOnly = parseOpenType(data) + doAssert unicodeOnly.hasGlyph('A'.Rune) + block: var font = readFont("tests/fonts/NotoEmoji.otf") font.size = 26