feedback addressed
This commit is contained in:
parent
b42b9d649a
commit
f325633a9b
|
@ -2,11 +2,28 @@ import pixie/common, pixie/paths, strutils, tables, unicode, vmath, xmlparser, x
|
|||
|
||||
type SvgFont* = ref object
|
||||
unitsPerEm*, ascent*, descent*: float32
|
||||
glyphAdvances*: Table[Rune, float32]
|
||||
glyphPaths*: Table[Rune, Path]
|
||||
kerningPairs*: Table[(Rune, Rune), float32]
|
||||
missingGlyphAdvance*: float32
|
||||
missingGlyphPath*: Path
|
||||
glyphAdvances: Table[Rune, float32]
|
||||
glyphPaths: Table[Rune, Path]
|
||||
kerningPairs: Table[(Rune, Rune), float32]
|
||||
missingGlyphAdvance: float32
|
||||
missingGlyphPath: Path
|
||||
|
||||
proc getGlyphPath*(svgFont: SvgFont, rune: Rune): Path =
|
||||
if rune in svgFont.glyphPaths:
|
||||
svgFont.glyphPaths[rune]
|
||||
else:
|
||||
svgFont.missingGlyphPath
|
||||
|
||||
proc getGlyphAdvance*(svgFont: SvgFont, rune: Rune): float32 =
|
||||
if rune in svgFont.glyphAdvances:
|
||||
svgFont.glyphAdvances[rune]
|
||||
else:
|
||||
svgFont.missingGlyphAdvance
|
||||
|
||||
proc getKerningAdjustment*(svgFont: SvgFont, left, right: Rune): float32 =
|
||||
let pair = (left, right)
|
||||
if pair in svgFont.kerningPairs:
|
||||
result = svgFont.kerningPairs[pair]
|
||||
|
||||
proc failInvalid() =
|
||||
raise newException(PixieError, "Invalid SVG font data")
|
||||
|
|
|
@ -52,29 +52,21 @@ proc getGlyphPath*(font: Font, rune: Rune): Path =
|
|||
if font.opentype != nil:
|
||||
font.opentype.getGlyphPath(rune)
|
||||
else:
|
||||
if rune in font.svgFont.glyphPaths:
|
||||
font.svgFont.glyphPaths[rune]
|
||||
else:
|
||||
font.svgFont.missingGlyphPath
|
||||
font.svgFont.getGlyphPath(rune)
|
||||
|
||||
proc getGlyphAdvance(font: Font, rune: Rune): float32 =
|
||||
## The advance for the rune in pixels.
|
||||
if font.opentype != nil:
|
||||
font.opentype.getGlyphAdvance(rune)
|
||||
else:
|
||||
if rune in font.svgFont.glyphAdvances:
|
||||
font.svgFont.glyphAdvances[rune]
|
||||
else:
|
||||
font.svgFont.missingGlyphAdvance
|
||||
font.svgFont.getGlyphAdvance(rune)
|
||||
|
||||
proc getKerningAdjustment(font: Font, left, right: Rune): float32 =
|
||||
## The kerning adjustment for the rune pair, in pixels.
|
||||
let pair = (left, right)
|
||||
if font.opentype != nil:
|
||||
result = font.opentype.getKerningAdjustment(left, right)
|
||||
font.opentype.getKerningAdjustment(left, right)
|
||||
else:
|
||||
if pair in font.svgFont.kerningPairs:
|
||||
result = font.svgFont.kerningPairs[pair]
|
||||
font.svgfont.getKerningAdjustment(left, right)
|
||||
|
||||
proc scale*(font: Font): float32 =
|
||||
## The scale factor to transform font units into pixels.
|
||||
|
|
Loading…
Reference in a new issue