public int GetGlyphKernAdvance(int codepoint1, int codepoint2) { var key = KerningKey(codepoint1, codepoint2); int result = 0; _kernings.TryGetValue(key, out result); return(result); }
public DynamicSpriteFont GetFont(int fontSize) { DynamicSpriteFont result; if (_fonts.TryGetValue(fontSize, out result)) { return(result); } result = new DynamicSpriteFont(this, fontSize); _fonts[fontSize] = result; return(result); }
public int GetGlyphKernAdvance(int glyph1, int glyph2) { var key = ((glyph1 << 16) | (glyph1 >> 16)) ^ glyph2; int result; if (_kernings.TryGetValue(key, out result)) { return(result); } result = stbtt_GetGlyphKernAdvance(_font, glyph1, glyph2); _kernings[key] = result; return(result); }
GlyphCollection GetGlyphsCollection(int size) { GlyphCollection result; if (_glyphs.TryGetValue(size, out result)) { return(result); } result = new GlyphCollection(); _glyphs[size] = result; return(result); }
public int GetGlyphKernAdvance(int glyph1, int glyph2, int fontSize) { var scale = CalculateScale(fontSize); var key = ((glyph1 << 16) | (glyph1 >> 16)) ^ glyph2; int result; if (!_kernings.TryGetValue(key, out result)) { result = stbtt_GetGlyphKernAdvance(_font, glyph1, glyph2); _kernings[key] = result; } return((int)(result * scale)); }
private DynamicFontGlyph GetGlyphWithoutBitmap(int codepoint) { DynamicFontGlyph glyph; if (Glyphs.TryGetValue(codepoint, out glyph)) { return(glyph); } int fontSourceIndex; var g = FontSystem.GetCodepointIndex(codepoint, out fontSourceIndex); if (g == null) { Glyphs[codepoint] = null; return(null); } var fontSize = (int)(FontSize * FontSystem.FontResolutionFactor); var font = FontSystem.FontSources[fontSourceIndex]; int advance, x0, y0, x1, y1; font.GetGlyphMetrics(g.Value, fontSize, out advance, out x0, out y0, out x1, out y1); var pad = Math.Max(DynamicFontGlyph.PadFromBlur(FontSystem.BlurAmount), DynamicFontGlyph.PadFromBlur(FontSystem.StrokeAmount)); var gw = (x1 - x0) + pad * 2; var gh = (y1 - y0) + pad * 2; var offset = DynamicFontGlyph.PadFromBlur(FontSystem.BlurAmount); glyph = new DynamicFontGlyph { Codepoint = codepoint, Id = g.Value, Size = fontSize, FontSourceIndex = fontSourceIndex, Bounds = new Rectangle(0, 0, gw, gh), XAdvance = advance, XOffset = x0 - offset, YOffset = y0 - offset }; Glyphs[codepoint] = glyph; return(glyph); }
private DynamicFontGlyph GetGlyphWithoutBitmap(int codepoint) { DynamicFontGlyph glyph = null; if (_glyphs.TryGetValue(codepoint, out glyph)) { return(glyph); } IFontSource font; var g = FontSystem.GetCodepointIndex(codepoint, out font); if (g == null) { return(null); } int advance = 0, x0 = 0, y0 = 0, x1 = 0, y1 = 0; font.GetGlyphMetrics(g.Value, FontSize, out advance, out x0, out y0, out x1, out y1); var pad = Math.Max(DynamicFontGlyph.PadFromBlur(FontSystem.BlurAmount), DynamicFontGlyph.PadFromBlur(FontSystem.StrokeAmount)); var gw = x1 - x0 + pad * 2; var gh = y1 - y0 + pad * 2; var offset = DynamicFontGlyph.PadFromBlur(FontSystem.BlurAmount); glyph = new DynamicFontGlyph { Codepoint = codepoint, Id = g.Value, Size = FontSize, Font = font, Bounds = new Rectangle(0, 0, gw, gh), XAdvance = advance, XOffset = x0 - offset, YOffset = y0 - offset }; _glyphs[codepoint] = glyph; return(glyph); }
public DynamicSpriteFont GetFont(int fontSize) { DynamicSpriteFont result; if (_fonts.TryGetValue(fontSize, out result)) { return(result); } if (_fontSources.Count == 0) { throw new Exception("Could not create a font without a single font source. Use AddFont to add at least one font source."); } var fontSource = _fontSources[0]; int ascent, descent, lineHeight; fontSource.GetMetricsForSize(fontSize, out ascent, out descent, out lineHeight); result = new DynamicSpriteFont(this, fontSize, lineHeight); _fonts[fontSize] = result; return(result); }
internal override void GetQuad(FontGlyph glyph, FontGlyph prevGlyph, ref float x, float y, ref FontGlyphSquad q) { if (prevGlyph != null) { var adv = 0; var dynamicGlyph = (DynamicFontGlyph)glyph; var dynamicPrevGlyph = (DynamicFontGlyph)prevGlyph; if (FontSystem.UseKernings && dynamicGlyph.FontSourceIndex == dynamicPrevGlyph.FontSourceIndex) { var key = GetKerningsKey(prevGlyph.Id, dynamicGlyph.Id); if (!Kernings.TryGetValue(key, out adv)) { var fontSource = FontSystem.FontSources[dynamicGlyph.FontSourceIndex]; adv = fontSource.GetGlyphKernAdvance(prevGlyph.Id, dynamicGlyph.Id, dynamicGlyph.Size); Kernings[key] = adv; } } x += adv + FontSystem.CharacterSpacing; } base.GetQuad(glyph, prevGlyph, ref x, y, ref q); }