diff --git a/src/pixie/fontformats/opentype.nim b/src/pixie/fontformats/opentype.nim index 3f5e94b..98b7d74 100644 --- a/src/pixie/fontformats/opentype.nim +++ b/src/pixie/fontformats/opentype.nim @@ -2415,6 +2415,12 @@ proc getKerningAdjustment*( elif opentype.kern != nil: result = opentype.kern.kerningPairs.getOrDefault(glyphPair, 0) +proc getWindingOrder*(opentype: OpenType): bool = + ## Returns the expected winding order of a font. + ## Gyph - false - clockwise + ## CFF - true - counterclockwise + return opentype.cff == nil + proc parseOpenType*(buf: string): OpenType {.raises: [PixieError].} = result = OpenType() result.buf = buf diff --git a/src/pixie/fonts.nim b/src/pixie/fonts.nim index f80667d..2482cb5 100644 --- a/src/pixie/fonts.nim +++ b/src/pixie/fonts.nim @@ -92,6 +92,12 @@ proc strikeoutThickness(typeface: Typeface): float32 = if typeface.opentype != nil: result = typeface.opentype.os2.yStrikeoutSize.float32 +proc getWindingOrder(typeface: Typeface): bool = + ## Returns the expected winding order of a font. + if typeface.opentype != nil: + return typeface.opentype.getWindingOrder() + return true + proc getGlyphPath*( typeface: Typeface, rune: Rune ): Path {.inline, raises: [PixieError].} = @@ -478,14 +484,16 @@ proc textUber( arrangement.selectionRects[runeIndex].x, position.y - underlinePosition + underlineThickness / 2, arrangement.selectionRects[runeIndex].w, - underlineThickness + underlineThickness, + font.typeface.getWindingOrder() ) if font.strikethrough: path.rect( arrangement.selectionRects[runeIndex].x, position.y - strikeoutPosition, arrangement.selectionRects[runeIndex].w, - strikeoutThickness + strikeoutThickness, + font.typeface.getWindingOrder() ) when stroke: diff --git a/tests/fonts/diffs/cff_strikethrough.png b/tests/fonts/diffs/cff_strikethrough.png index ef7d4da..a037a16 100644 Binary files a/tests/fonts/diffs/cff_strikethrough.png and b/tests/fonts/diffs/cff_strikethrough.png differ diff --git a/tests/fonts/diffs/cff_underline.png b/tests/fonts/diffs/cff_underline.png index a2b521e..d77ca9e 100644 Binary files a/tests/fonts/diffs/cff_underline.png and b/tests/fonts/diffs/cff_underline.png differ diff --git a/tests/fonts/rendered/cff_strikethrough.png b/tests/fonts/rendered/cff_strikethrough.png index 85e655d..a7a380c 100644 Binary files a/tests/fonts/rendered/cff_strikethrough.png and b/tests/fonts/rendered/cff_strikethrough.png differ diff --git a/tests/fonts/rendered/cff_underline.png b/tests/fonts/rendered/cff_underline.png index 61acca4..a9271eb 100644 Binary files a/tests/fonts/rendered/cff_underline.png and b/tests/fonts/rendered/cff_underline.png differ