@@ -4,7 +4,9 @@ package shaping
44
55import (
66 "github.com/go-text/typesetting/di"
7+ ft "github.com/go-text/typesetting/font"
78 "github.com/go-text/typesetting/harfbuzz"
9+ ucd "github.com/go-text/typesetting/internal/unicodedata"
810 "golang.org/x/image/math/fixed"
911)
1012
@@ -166,6 +168,9 @@ func (t *HarfbuzzShaper) Shape(input Input) Output {
166168 Gap : fixed .I (int (fontExtents .LineGap )) >> scaleShift ,
167169 }
168170 out .RecalculateAll ()
171+
172+ replaceNotSupportedSpaces (input .Text , out .Glyphs )
173+
169174 return out
170175}
171176
@@ -209,3 +214,21 @@ func countClusters(glyphs []Glyph, textLen int, dir di.Progression) {
209214 glyphs [i ].RuneCount = runesInCluster
210215 }
211216}
217+
218+ // special handling of non supported white space :
219+ // our face selection process assumes all fonts contains the ASCII space,
220+ // but it turns out to be sometimes incorrect, for instance for the
221+ // NotoSansSymbols-Regular-Subsetted.ttf (found on Android)
222+ func replaceNotSupportedSpaces (text []rune , glyphs []Glyph ) {
223+ for i , g := range glyphs {
224+ const NotFound ft.GID = 0 // this is the default value used by Harfbuzz
225+ if ! (g .GlyphID == NotFound && g .GlyphsCount () == 1 && g .RunesCount () == 1 ) {
226+ continue
227+ }
228+ // only replace glyph corresponding to a space
229+ if r := text [g .TextIndex ()]; ucd .LookupGeneralCategory (r ) == ucd .Zs {
230+ glyphs [i ].GlyphID = ft .EmptyGlyph
231+ glyphs [i ].Width , glyphs [i ].Height = 0 , 0
232+ }
233+ }
234+ }
0 commit comments