Skip to content

Commit

Permalink
[harfbuzz] properly scale glyph X and Y offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitkugler committed Dec 12, 2023
1 parent 6295f3c commit fea6bbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions harfbuzz/fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,25 @@ func (f *Font) getGlyphHOriginWithFallback(glyph GID) (Position, Position) {
if !ok {
x, y, ok = f.face.GlyphVOrigin(glyph)
if ok {
x, y := f.emScalefX(float32(x)), f.emScalefY(float32(y))
dx, dy := f.guessVOriginMinusHOrigin(glyph)
return x - dx, y - dy
}
}
return x, y
return f.emScalefX(float32(x)), f.emScalefY(float32(y))
}

func (f *Font) getGlyphVOriginWithFallback(glyph GID) (Position, Position) {
x, y, ok := f.face.GlyphVOrigin(glyph)
if !ok {
x, y, ok = f.face.GlyphHOrigin(glyph)
if ok {
x, y := f.emScalefX(float32(x)), f.emScalefY(float32(y))
dx, dy := f.guessVOriginMinusHOrigin(glyph)
return x + dx, y + dy
}
}
return x, y
return f.emScalefX(float32(x)), f.emScalefY(float32(y))
}

func (f *Font) guessVOriginMinusHOrigin(glyph GID) (x, y Position) {
Expand Down
8 changes: 8 additions & 0 deletions harfbuzz/harfbuzz_shape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ import (

func TestShapeExpected(t *testing.T) {
tests := collectTests(t)

// add tests based on the C++ binary
tests = append(tests,
// check we properly scale the offset values
newTestData(t, "", "perf_reference/fonts/Roboto-Regular.ttf;--direction=ttb --font-size=2000;U+0061,U+0062;[gid70=0@-544,-1700+0,-2343|gid71=1@-562,-1912+0,-2343]"),
newTestData(t, "", "perf_reference/fonts/Roboto-Regular.ttf;--direction=ttb --font-size=3000;U+0061,U+0062;[gid70=0@-816,-2550+0,-3515|gid71=1@-842,-2868+0,-3515]"),
)

fmt.Printf("Running %d tests...\n", len(tests))

for _, testD := range tests {
Expand Down

0 comments on commit fea6bbb

Please sign in to comment.