text/v2: bug fix: glyph image sizes might not be enough

Hajime found that one glyph 'ら' was not rendered correctly in a
vertical Japanese text in examples/texti18n. This was due to an
incorrect calculation of the image sizes.

This change fixes this issue by always adding +1 to the sizes no matter
what the glyph size is or the position is. It is in theory possible to
determine whether this addition is necessary, but this is pretty
complicated and might cause other issues.
This commit is contained in:
Hajime Hoshi 2023-11-25 01:24:52 +09:00
parent b9b365a576
commit 20c216b2b1
2 changed files with 9 additions and 12 deletions

View File

@ -85,12 +85,10 @@ func segmentsToImage(segs []api.Segment, subpixelOffset fixed.Point26_6, glyphBo
return nil return nil
} }
if glyphBounds.Min.X&((1<<6)-1) != 0 { // Add always 1 to the size.
w++ // In theory, it is possible to determine whether +1 is necessary or not, but the calculation is pretty complicated.
} w++
if glyphBounds.Min.Y&((1<<6)-1) != 0 { h++
h++
}
biasX := fixed26_6ToFloat32(-glyphBounds.Min.X + subpixelOffset.X) biasX := fixed26_6ToFloat32(-glyphBounds.Min.X + subpixelOffset.X)
biasY := fixed26_6ToFloat32(-glyphBounds.Min.Y + subpixelOffset.Y) biasY := fixed26_6ToFloat32(-glyphBounds.Min.Y + subpixelOffset.Y)

View File

@ -147,12 +147,11 @@ func (s *StdFace) glyphImageImpl(r rune, subpixelOffset fixed.Point26_6, glyphBo
return nil return nil
} }
if glyphBounds.Min.X&((1<<6)-1) != 0 { // Add always 1 to the size.
w++ // In theory, it is possible to determine whether +1 is necessary or not, but the calculation is pretty complicated.
} w++
if glyphBounds.Min.Y&((1<<6)-1) != 0 { h++
h++
}
rgba := image.NewRGBA(image.Rect(0, 0, w, h)) rgba := image.NewRGBA(image.Rect(0, 0, w, h))
d := font.Drawer{ d := font.Drawer{