public int ComputeVisibleGlyphs(CharSequence str, int start, int end, float availableWidth) { BitmapFontData data = Data; int index = start; float width = 0; Glyph lastGlyph = null; availableWidth /= data.ScaleX; for (; index < end; index++) { char ch = str[index]; Glyph g = data[ch]; if (g != null) { if (lastGlyph != null) { width += lastGlyph.GetKerning(ch); } if ((width + g.XAdvance) - availableWidth > .001f) { break; } width += g.XAdvance; lastGlyph = g; } } return(index - start); }
public TextBounds GetBounds(CharSequence str, int start, int end) { BitmapFontData data = Data; int width = 0; Glyph lastGlyph = null; while (start < end) { lastGlyph = data[str[start++]]; if (lastGlyph != null) { width = lastGlyph.XAdvance; break; } } while (start < end) { char ch = str[start++]; Glyph g = data[ch]; if (g != null) { width += lastGlyph.GetKerning(ch); lastGlyph = g; width += g.XAdvance; } } return(new TextBounds() { Width = width * data.ScaleX, Height = data.CapHeight, }); }
private float AddToCache(CharSequence str, float x, float y, int start, int end) { float startX = x; BitmapFont font = Font; Glyph lastGlyph = null; BitmapFontData data = font.Data; if (data.ScaleX == 1 && data.ScaleY == 1) { while (start < end) { lastGlyph = data[str[start++]]; if (lastGlyph != null) { AddGlyph(lastGlyph, x + lastGlyph.XOffset, y + lastGlyph.YOffset, lastGlyph.Width, lastGlyph.Height); x += lastGlyph.XAdvance; break; } } while (start < end) { char ch = str[start++]; Glyph g = data[ch]; if (g != null) { x += lastGlyph.GetKerning(ch); lastGlyph = g; AddGlyph(lastGlyph, x + g.XOffset, y + g.YOffset, g.Width, g.Height); x += g.XAdvance; } } } else { float scaleX = data.ScaleX; float scaleY = data.ScaleY; while (start < end) { lastGlyph = data[str[start++]]; if (lastGlyph != null) { AddGlyph(lastGlyph, x + lastGlyph.XOffset * scaleX, y + lastGlyph.YOffset * scaleY, lastGlyph.Width * scaleX, lastGlyph.Height * scaleY); x += lastGlyph.XAdvance * scaleX; } } while (start < end) { char ch = str[start++]; Glyph g = data[ch]; if (g != null) { x += lastGlyph.GetKerning(ch) * scaleX; lastGlyph = g; AddGlyph(lastGlyph, x + g.XOffset * scaleX, y + g.YOffset * scaleY, lastGlyph.Width * scaleX, lastGlyph.Height * scaleY); x += g.XAdvance * scaleX; } } } return(x - startX); }
public void ComputeGlyphAdvancesAndPositions(CharSequence str, IList <float> glyphAdvances, IList <float> glyphPositions) { glyphAdvances.Clear(); glyphPositions.Clear(); int index = 0; int end = str.Length; float width = 0; Glyph lastGlyph = null; BitmapFontData data = Data; if (data.ScaleX == 1) { for (; index < end; index++) { char ch = str[index]; Glyph g = data[ch]; if (g != null) { if (lastGlyph != null) { width += lastGlyph.GetKerning(ch); } lastGlyph = g; glyphAdvances.Add(g.XAdvance); glyphPositions.Add(width); width += g.XAdvance; } } glyphAdvances.Add(0); glyphPositions.Add(width); } else { float scaleX = data.ScaleX; for (; index < end; index++) { char ch = str[index]; Glyph g = data[ch]; if (g != null) { if (lastGlyph != null) { width += lastGlyph.GetKerning(ch) * scaleX; } lastGlyph = g; float xAdvance = g.XAdvance * scaleX; glyphAdvances.Add(xAdvance); glyphPositions.Add(width); width += xAdvance; } } glyphAdvances.Add(0); glyphPositions.Add(width); } }