public FontSize(Font font, int size, string charset) { if (font.Disposed) { throw new Exception("Cannot get Font data as it is disposed"); } Font = font; Size = size; Scale = font.GetScale(size); Ascent = font.Ascent * Scale; Descent = font.Descent * Scale; LineGap = font.LineGap * Scale; Height = Ascent - Descent; LineHeight = Height + LineGap; for (int i = 0; i < charset.Length; i++) { // get font info var unicode = charset[i]; var glyph = font.GetGlyph(unicode); if (glyph > 0) { unsafe { int advance, offsetX, x0, y0, x1, y1; StbTrueType.stbtt_GetGlyphHMetrics(font.fontInfo, glyph, &advance, &offsetX); StbTrueType.stbtt_GetGlyphBitmapBox(font.fontInfo, glyph, Scale, Scale, &x0, &y0, &x1, &y1); int w = (x1 - x0); int h = (y1 - y0); // define character var ch = new Character { Unicode = unicode, Glyph = glyph, Width = w, Height = h, Advance = advance * Scale, OffsetX = offsetX * Scale, OffsetY = y0 }; ch.HasGlyph = (w > 0 && h > 0 && StbTrueType.stbtt_IsGlyphEmpty(font.fontInfo, ch.Glyph) == 0); Charset[unicode] = ch; } } } }