/// <summary> /// Renders the Unicode character to a buffer at the Font Size, and returns true on success /// </summary> public unsafe bool Render(char unicode, Span <Color> buffer, out int width, out int height) { if (Charset.TryGetValue(unicode, out var ch) && ch.HasGlyph) { if (buffer.Length < ch.Width * ch.Height) { throw new Exception("Buffer provided isn't large enough to store rendered data"); } if (Font.Disposed) throw new Exception("Cannot get Font data as it is disposed"); fixed(Color *ptr = buffer) { // we actually use the bitmap buffer as our temporary buffer, and fill the pixels out backwards after // kinda weird but it works & saves creating more memory var input = (byte *)ptr; StbTrueType.stbtt_MakeGlyphBitmap(Font.fontInfo, input, ch.Width, ch.Height, ch.Width, Scale, Scale, ch.Glyph); for (int i = ch.Width * ch.Height - 1; i >= 0; i--) { ptr[i] = new Color(input[i], input[i], input[i], input[i]); } } width = ch.Width; height = ch.Height; return(true); } width = height = 0; return(false); }
public static void __tt_renderGlyphBitmap(this StbTrueType.stbtt_fontinfo font, byte *output, int outWidth, int outHeight, int outStride, float scaleX, float scaleY, int glyph) { StbTrueType.stbtt_MakeGlyphBitmap(font, output, (int)(outWidth), (int)(outHeight), (int)(outStride), (float)(scaleX), (float)(scaleY), (int)(glyph)); }