mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
font/opentype: fix kerning
Fixes gio#69 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -5,7 +5,6 @@
|
|||||||
package opentype
|
package opentype
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@@ -57,8 +56,7 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
|
|||||||
Bounds: f.Bounds(buf, ppem),
|
Bounds: f.Bounds(buf, ppem),
|
||||||
}
|
}
|
||||||
var lines []text.Line
|
var lines []text.Line
|
||||||
maxDotX := fixed.Int26_6(math.MaxInt32)
|
maxDotX := fixed.I(opts.MaxWidth)
|
||||||
maxDotX = fixed.I(opts.MaxWidth)
|
|
||||||
type state struct {
|
type state struct {
|
||||||
r rune
|
r rune
|
||||||
advs []fixed.Int26_6
|
advs []fixed.Int26_6
|
||||||
@@ -91,6 +89,7 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
|
|||||||
advs: prev.advs,
|
advs: prev.advs,
|
||||||
idx: prev.idx + s,
|
idx: prev.idx + s,
|
||||||
x: prev.x + prev.adv,
|
x: prev.x + prev.adv,
|
||||||
|
adv: a,
|
||||||
valid: true,
|
valid: true,
|
||||||
}
|
}
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
@@ -101,13 +100,12 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
|
|||||||
endLine()
|
endLine()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
next.adv = a
|
|
||||||
var k fixed.Int26_6
|
var k fixed.Int26_6
|
||||||
if prev.valid {
|
if prev.valid {
|
||||||
k = f.Kern(buf, ppem, prev.r, next.r)
|
k = f.Kern(buf, ppem, prev.r, next.r)
|
||||||
}
|
}
|
||||||
// Break the line if we're out of space.
|
// Break the line if we're out of space.
|
||||||
if prev.idx > 0 && next.x+next.adv+k >= maxDotX {
|
if prev.idx > 0 && next.x+next.adv+k > maxDotX {
|
||||||
// If the line contains no word breaks, break off the last rune.
|
// If the line contains no word breaks, break off the last rune.
|
||||||
if word.idx == 0 {
|
if word.idx == 0 {
|
||||||
word = prev
|
word = prev
|
||||||
@@ -117,8 +115,9 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
|
|||||||
next.advs = next.advs[len(word.advs):]
|
next.advs = next.advs[len(word.advs):]
|
||||||
prev = word
|
prev = word
|
||||||
endLine()
|
endLine()
|
||||||
} else {
|
} else if k != 0 {
|
||||||
next.adv += k
|
next.advs[len(next.advs)-1] += k
|
||||||
|
next.x += k
|
||||||
}
|
}
|
||||||
next.advs = append(next.advs, next.adv)
|
next.advs = append(next.advs, next.adv)
|
||||||
if unicode.IsSpace(next.r) {
|
if unicode.IsSpace(next.r) {
|
||||||
|
|||||||
Reference in New Issue
Block a user