Add hasGlyph
This commit is contained in:
parent
8d1a84efea
commit
cba533e737
3 changed files with 25 additions and 7 deletions
|
@ -1070,6 +1070,9 @@ proc parseCFFCharstring(cff: CffTable, code: string, glyphIndex: int): Path =
|
||||||
x += stack.pop()
|
x += stack.pop()
|
||||||
p.moveTo(x, y)
|
p.moveTo(x, y)
|
||||||
|
|
||||||
|
of 23: # vstemhm
|
||||||
|
parseStems()
|
||||||
|
|
||||||
of 24: # rcurveline
|
of 24: # rcurveline
|
||||||
while stack.len > 2:
|
while stack.len > 2:
|
||||||
let
|
let
|
||||||
|
@ -2084,6 +2087,9 @@ proc parsePostTable(buf: string, offset: int): PostTable =
|
||||||
proc getGlyphId(opentype: OpenType, rune: Rune): uint16 =
|
proc getGlyphId(opentype: OpenType, rune: Rune): uint16 =
|
||||||
result = opentype.cmap.runeToGlyphId.getOrDefault(rune, 0)
|
result = opentype.cmap.runeToGlyphId.getOrDefault(rune, 0)
|
||||||
|
|
||||||
|
proc hasGlyph*(opentype: OpenType, rune: Rune): bool =
|
||||||
|
rune in opentype.cmap.runeToGlyphId
|
||||||
|
|
||||||
proc parseGlyfGlyph(opentype: OpenType, glyphId: uint16): Path {.raises: [PixieError].}
|
proc parseGlyfGlyph(opentype: OpenType, glyphId: uint16): Path {.raises: [PixieError].}
|
||||||
|
|
||||||
proc parseGlyphPath(
|
proc parseGlyphPath(
|
||||||
|
@ -2415,11 +2421,11 @@ proc getKerningAdjustment*(
|
||||||
elif opentype.kern != nil:
|
elif opentype.kern != nil:
|
||||||
result = opentype.kern.kerningPairs.getOrDefault(glyphPair, 0)
|
result = opentype.kern.kerningPairs.getOrDefault(glyphPair, 0)
|
||||||
|
|
||||||
proc getWindingOrder*(opentype: OpenType): bool =
|
proc isCCW*(opentype: OpenType): bool {.inline.} =
|
||||||
## Returns the expected winding order of a font.
|
## Returns the expected winding order of a font.
|
||||||
## Gyph - false - clockwise
|
## Gyph - false - clockwise
|
||||||
## CFF - true - counterclockwise
|
## CFF - true - counterclockwise
|
||||||
return opentype.cff == nil
|
opentype.cff == nil
|
||||||
|
|
||||||
proc parseOpenType*(buf: string): OpenType {.raises: [PixieError].} =
|
proc parseOpenType*(buf: string): OpenType {.raises: [PixieError].} =
|
||||||
result = OpenType()
|
result = OpenType()
|
||||||
|
|
|
@ -11,6 +11,9 @@ type SvgFont* = ref object
|
||||||
proc getGlyphPath*(svgFont: SvgFont, rune: Rune): Path {.raises: [].} =
|
proc getGlyphPath*(svgFont: SvgFont, rune: Rune): Path {.raises: [].} =
|
||||||
svgFont.glyphPaths.getOrDefault(rune, svgFont.missingGlyphPath)
|
svgFont.glyphPaths.getOrDefault(rune, svgFont.missingGlyphPath)
|
||||||
|
|
||||||
|
proc hasGlyph*(svgFont: SvgFont, rune: Rune): bool =
|
||||||
|
rune in svgFont.glyphPaths
|
||||||
|
|
||||||
proc getAdvance*(svgFont: SvgFont, rune: Rune): float32 {.raises: [].} =
|
proc getAdvance*(svgFont: SvgFont, rune: Rune): float32 {.raises: [].} =
|
||||||
svgFont.advances.getOrDefault(rune, svgFont.missingGlyphAdvance)
|
svgFont.advances.getOrDefault(rune, svgFont.missingGlyphAdvance)
|
||||||
|
|
||||||
|
|
|
@ -92,11 +92,10 @@ proc strikeoutThickness(typeface: Typeface): float32 =
|
||||||
if typeface.opentype != nil:
|
if typeface.opentype != nil:
|
||||||
result = typeface.opentype.os2.yStrikeoutSize.float32
|
result = typeface.opentype.os2.yStrikeoutSize.float32
|
||||||
|
|
||||||
proc getWindingOrder(typeface: Typeface): bool =
|
proc isCCW(typeface: Typeface): bool {.inline.} =
|
||||||
## Returns the expected winding order of a font.
|
## Returns the expected winding order of a font.
|
||||||
if typeface.opentype != nil:
|
if typeface.opentype != nil:
|
||||||
return typeface.opentype.getWindingOrder()
|
return typeface.opentype.isCCW()
|
||||||
return true
|
|
||||||
|
|
||||||
proc getGlyphPath*(
|
proc getGlyphPath*(
|
||||||
typeface: Typeface, rune: Rune
|
typeface: Typeface, rune: Rune
|
||||||
|
@ -109,6 +108,16 @@ proc getGlyphPath*(
|
||||||
else:
|
else:
|
||||||
result.addPath(typeface.svgFont.getGlyphPath(rune))
|
result.addPath(typeface.svgFont.getGlyphPath(rune))
|
||||||
|
|
||||||
|
proc hasGlyph*(typeface: Typeface, rune: Rune): bool {.inline.} =
|
||||||
|
## Returns if there is a glyph for this rune.
|
||||||
|
if rune.uint32 > SP.uint32: # Empty paths for control runes (not tofu)
|
||||||
|
if typeface.opentype != nil:
|
||||||
|
typeface.opentype.hasGlyph(rune)
|
||||||
|
else:
|
||||||
|
typeface.svgFont.hasGlyph(rune)
|
||||||
|
else:
|
||||||
|
false
|
||||||
|
|
||||||
proc getAdvance*(typeface: Typeface, rune: Rune): float32 {.inline, raises: [].} =
|
proc getAdvance*(typeface: Typeface, rune: Rune): float32 {.inline, raises: [].} =
|
||||||
## The advance for the rune in pixels.
|
## The advance for the rune in pixels.
|
||||||
if typeface.opentype != nil:
|
if typeface.opentype != nil:
|
||||||
|
@ -485,7 +494,7 @@ proc textUber(
|
||||||
position.y - underlinePosition + underlineThickness / 2,
|
position.y - underlinePosition + underlineThickness / 2,
|
||||||
arrangement.selectionRects[runeIndex].w,
|
arrangement.selectionRects[runeIndex].w,
|
||||||
underlineThickness,
|
underlineThickness,
|
||||||
font.typeface.getWindingOrder()
|
font.typeface.isCCW()
|
||||||
)
|
)
|
||||||
if font.strikethrough:
|
if font.strikethrough:
|
||||||
path.rect(
|
path.rect(
|
||||||
|
@ -493,7 +502,7 @@ proc textUber(
|
||||||
position.y - strikeoutPosition,
|
position.y - strikeoutPosition,
|
||||||
arrangement.selectionRects[runeIndex].w,
|
arrangement.selectionRects[runeIndex].w,
|
||||||
strikeoutThickness,
|
strikeoutThickness,
|
||||||
font.typeface.getWindingOrder()
|
font.typeface.isCCW()
|
||||||
)
|
)
|
||||||
|
|
||||||
when stroke:
|
when stroke:
|
||||||
|
|
Loading…
Reference in a new issue