Fix tofu advance.

This commit is contained in:
treeform 2021-10-01 10:53:56 -07:00
parent a1659198e3
commit 052eeb5a18
5 changed files with 13 additions and 2 deletions

View file

@ -143,9 +143,10 @@ proc getGlyphPath*(
proc getAdvance*(typeface: Typeface, rune: Rune): float32 {.inline, raises: [].} =
## The advance for the rune in pixels.
let typeface2 = typeface.fallbackTypeface(rune)
var typeface2 = typeface.fallbackTypeface(rune)
if typeface2 == nil:
return
# Get tofu advance, see tofu_advance test.
typeface2 = typeface
if typeface2.opentype != nil:
result = typeface2.opentype.getAdvance(rune)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

View file

@ -1091,3 +1091,13 @@ block:
image.fillText(font, "Grumpy ウィザード make 有毒な醸造 for the 悪い女王 and Jack.")
doDiff(image, "fallback2")
block:
var font = readFont("tests/fonts/Inter-Regular.ttf")
font.size = 26
let image = newImage(800, 100)
image.fill(rgba(255, 255, 255, 255))
image.fillText(font, "This[]Advance!")
doDiff(image, "tofu_advance")