@@ -26,11 +26,19 @@ type Glyph struct {
2626 // YBearing is the distance between the dot (with offset applied) and
2727 // the top of the glyph content, typically positive
2828 YBearing fixed.Int26_6
29+ // Advance is the distance between the current dot (without offset applied) and the next dot.
30+ // It is typically positive for horizontal text, and negative for vertical text.
31+ Advance fixed.Int26_6
32+
2933 // XAdvance is the distance between the current dot (without offset applied) and the next dot.
3034 // It is typically positive for horizontal text, and always zero for vertical text.
35+ //
36+ // Deprecated: Use Advance instead.
3137 XAdvance fixed.Int26_6
3238 // YAdvance is the distance between the current dot (without offset applied) and the next dot.
3339 // It is typically negative for vertical text, and always zero for horizontal text.
40+ //
41+ // Deprecated: Use Advance instead.
3442 YAdvance fixed.Int26_6
3543
3644 // Offsets to be applied to the dot before actually drawing
@@ -43,11 +51,17 @@ type Glyph struct {
4351 // this glyph cluster. All glyphs sharing the same cluster value
4452 // are part of the same cluster and will have identical RuneCount
4553 // and GlyphCount fields.
54+ //
55+ // Deprecated: Use TextIndex() instead.
4656 ClusterIndex int
4757 // RuneCount is the number of input runes shaped into this output
4858 // glyph cluster.
59+ //
60+ // Deprecated: Use RunesCount() instead.
4961 RuneCount int
5062 // GlyphCount is the number of glyphs in this output glyph cluster.
63+ //
64+ // Deprecated: Use GlyphsCount() instead.
5165 GlyphCount int
5266 GlyphID font.GID
5367 Mask uint32
@@ -59,6 +73,19 @@ type Glyph struct {
5973 startLetterSpacing , endLetterSpacing fixed.Int26_6
6074}
6175
76+ // TextIndex is the lowest rune index of all runes shaped into
77+ // this glyph cluster. All glyphs sharing the same cluster value
78+ // are part of the same cluster and will have identical RunesCount
79+ // and GlyphsCount values.
80+ func (g Glyph ) TextIndex () int { return g .ClusterIndex }
81+
82+ // RuneCount is the number of input runes shaped into this output
83+ // glyph cluster.
84+ func (g Glyph ) RunesCount () int { return g .RuneCount }
85+
86+ // GlyphsCount is the number of glyphs in this output glyph cluster.
87+ func (g Glyph ) GlyphsCount () int { return g .GlyphCount }
88+
6289// LeftSideBearing returns the distance from the glyph's X origin to
6390// its leftmost edge. This value can be negative if the glyph extends
6491// across the origin.
@@ -70,7 +97,7 @@ func (g Glyph) LeftSideBearing() fixed.Int26_6 {
7097// the edge of the glyph's advance. This value can be negative if the glyph's
7198// right edge is after the end of its advance.
7299func (g Glyph ) RightSideBearing () fixed.Int26_6 {
73- return g .XAdvance - g .Width - g .XBearing
100+ return g .Advance - g .Width - g .XBearing
74101}
75102
76103// Bounds describes the minor-axis bounds of a line of text. In a LTR or RTL
@@ -169,14 +196,8 @@ func (o *Output) FromFontUnit(v float32) fixed.Int26_6 {
169196// and can be used to speed up line wrapping logic.
170197func (o * Output ) RecomputeAdvance () {
171198 advance := fixed .Int26_6 (0 )
172- if o .Direction .IsVertical () {
173- for _ , g := range o .Glyphs {
174- advance += g .YAdvance
175- }
176- } else { // horizontal
177- for _ , g := range o .Glyphs {
178- advance += g .XAdvance
179- }
199+ for _ , g := range o .Glyphs {
200+ advance += g .Advance
180201 }
181202 o .Advance = advance
182203}
@@ -204,11 +225,11 @@ func (o *Output) advanceSpaceAware(paragraphDir di.Direction) fixed.Int26_6 {
204225 }
205226 if o .Direction .IsVertical () {
206227 if lastG .Height == 0 {
207- return o .Advance - lastG .YAdvance
228+ return o .Advance - lastG .Advance
208229 }
209230 } else { // horizontal
210231 if lastG .Width == 0 {
211- return o .Advance - lastG .XAdvance
232+ return o .Advance - lastG .Advance
212233 }
213234 }
214235 return o .Advance - lastG .endLetterSpacing
@@ -228,7 +249,7 @@ func (o *Output) RecalculateAll() {
228249 if o .Direction .IsVertical () {
229250 for i := range o .Glyphs {
230251 g := & o .Glyphs [i ]
231- advance += g .YAdvance
252+ advance += g .Advance
232253 depth := g .XOffset + g .XBearing // start of the glyph
233254 if depth < descent {
234255 descent = depth
@@ -241,7 +262,7 @@ func (o *Output) RecalculateAll() {
241262 } else { // horizontal
242263 for i := range o .Glyphs {
243264 g := & o .Glyphs [i ]
244- advance += g .XAdvance
265+ advance += g .Advance
245266 height := g .YBearing + g .YOffset
246267 if height > ascent {
247268 ascent = height
@@ -276,8 +297,7 @@ func (out *Output) sideways() {
276297 out .Glyphs [i ].XBearing = g .YBearing + g .Height
277298 out .Glyphs [i ].YBearing = g .Width
278299 // switch advance direction
279- out .Glyphs [i ].XAdvance = 0
280- out .Glyphs [i ].YAdvance = - g .XAdvance // YAdvance is negative
300+ out .Glyphs [i ].Advance = - g .Advance // Advance for vertical text is negative
281301 // apply a rotation around the dot, and position the glyph
282302 // below the dot
283303 out .Glyphs [i ].XOffset = g .YOffset
0 commit comments