} // The path of the font sheet. public bool TryGetSheet(int index, out FontSheet sheet) { sheet = null; if (!Sheets.Any(x => x.Index == index)) { return(false); } sheet = Sheets.Where(x => x.Index == index).First(); return(true); }
public static Bitmap RenderChar(char c, PixelRenderingOptions options) { FontFace fallback = FontManager.FontMap.GetFont(0); if (c == ' ') { throw new Exception("A space cannot be rendered in the TextEngine."); } FontSheet sheet = options.Font.Search(c, options.FontType, out (int i, int x, int y)index) ?? fallback.Search(c, options.FontType, out index); Rectangle crop = new Rectangle( options.Font.Ppu.Width * index.x, options.Font.Ppu.Height * index.y, options.Font.Ppu.Width, options.Font.Ppu.Height); using (Bitmap b = new Bitmap(sheet.Path)) { using (Bitmap tmp = b.Clone(crop, b.PixelFormat)) { if (!options.Font.AutoCrop.HasValue) { crop.Width = TextConfiguration.GetWidth(tmp, tmp.Width); } else { if (options.Font.AutoCrop.Value) { crop.Width = TextConfiguration.GetWidth(tmp, tmp.Width); } } crop.Debug(); return(b.Clone(crop, b.PixelFormat)); } } }