feedback addressed

This commit is contained in:
Ryan Oldenburg 2021-04-28 00:58:49 -05:00
parent b42b9d649a
commit f325633a9b
2 changed files with 26 additions and 17 deletions

View file

@ -2,11 +2,28 @@ import pixie/common, pixie/paths, strutils, tables, unicode, vmath, xmlparser, x
type SvgFont* = ref object type SvgFont* = ref object
unitsPerEm*, ascent*, descent*: float32 unitsPerEm*, ascent*, descent*: float32
glyphAdvances*: Table[Rune, float32] glyphAdvances: Table[Rune, float32]
glyphPaths*: Table[Rune, Path] glyphPaths: Table[Rune, Path]
kerningPairs*: Table[(Rune, Rune), float32] kerningPairs: Table[(Rune, Rune), float32]
missingGlyphAdvance*: float32 missingGlyphAdvance: float32
missingGlyphPath*: Path 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() = proc failInvalid() =
raise newException(PixieError, "Invalid SVG font data") raise newException(PixieError, "Invalid SVG font data")

View file

@ -52,29 +52,21 @@ proc getGlyphPath*(font: Font, rune: Rune): Path =
if font.opentype != nil: if font.opentype != nil:
font.opentype.getGlyphPath(rune) font.opentype.getGlyphPath(rune)
else: else:
if rune in font.svgFont.glyphPaths: font.svgFont.getGlyphPath(rune)
font.svgFont.glyphPaths[rune]
else:
font.svgFont.missingGlyphPath
proc getGlyphAdvance(font: Font, rune: Rune): float32 = proc getGlyphAdvance(font: Font, rune: Rune): float32 =
## The advance for the rune in pixels. ## The advance for the rune in pixels.
if font.opentype != nil: if font.opentype != nil:
font.opentype.getGlyphAdvance(rune) font.opentype.getGlyphAdvance(rune)
else: else:
if rune in font.svgFont.glyphAdvances: font.svgFont.getGlyphAdvance(rune)
font.svgFont.glyphAdvances[rune]
else:
font.svgFont.missingGlyphAdvance
proc getKerningAdjustment(font: Font, left, right: Rune): float32 = proc getKerningAdjustment(font: Font, left, right: Rune): float32 =
## The kerning adjustment for the rune pair, in pixels. ## The kerning adjustment for the rune pair, in pixels.
let pair = (left, right)
if font.opentype != nil: if font.opentype != nil:
result = font.opentype.getKerningAdjustment(left, right) font.opentype.getKerningAdjustment(left, right)
else: else:
if pair in font.svgFont.kerningPairs: font.svgfont.getKerningAdjustment(left, right)
result = font.svgFont.kerningPairs[pair]
proc scale*(font: Font): float32 = proc scale*(font: Font): float32 =
## The scale factor to transform font units into pixels. ## The scale factor to transform font units into pixels.