Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/pixie/fontformats/opentype.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 =
Expand Down
15 changes: 15 additions & 0 deletions tests/test_fonts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down