From 20c216b2b1c8a5276b08a643a92bb8c8e38dd616 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 25 Nov 2023 01:24:52 +0900 Subject: [PATCH] text/v2: bug fix: glyph image sizes might not be enough MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- text/v2/gotextseg.go | 10 ++++------ text/v2/std.go | 11 +++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/text/v2/gotextseg.go b/text/v2/gotextseg.go index 32ec42326..f19edebf6 100644 --- a/text/v2/gotextseg.go +++ b/text/v2/gotextseg.go @@ -85,12 +85,10 @@ func segmentsToImage(segs []api.Segment, subpixelOffset fixed.Point26_6, glyphBo return nil } - if glyphBounds.Min.X&((1<<6)-1) != 0 { - w++ - } - if glyphBounds.Min.Y&((1<<6)-1) != 0 { - h++ - } + // Add always 1 to the size. + // In theory, it is possible to determine whether +1 is necessary or not, but the calculation is pretty complicated. + w++ + h++ biasX := fixed26_6ToFloat32(-glyphBounds.Min.X + subpixelOffset.X) biasY := fixed26_6ToFloat32(-glyphBounds.Min.Y + subpixelOffset.Y) diff --git a/text/v2/std.go b/text/v2/std.go index b7113812f..b687255b3 100644 --- a/text/v2/std.go +++ b/text/v2/std.go @@ -147,12 +147,11 @@ func (s *StdFace) glyphImageImpl(r rune, subpixelOffset fixed.Point26_6, glyphBo return nil } - if glyphBounds.Min.X&((1<<6)-1) != 0 { - w++ - } - if glyphBounds.Min.Y&((1<<6)-1) != 0 { - h++ - } + // Add always 1 to the size. + // In theory, it is possible to determine whether +1 is necessary or not, but the calculation is pretty complicated. + w++ + h++ + rgba := image.NewRGBA(image.Rect(0, 0, w, h)) d := font.Drawer{