using System; using System.Collections.Generic; using System.IO; namespace Orvid.Graphics.FontSupport.bdf { public class BDFFontProvider : AbstractFontProvider { private List containers = new List(); public BDFFontProvider() : base("bdf") { } /// /// The built-in fonts. /// private static List BuiltInFonts = new List { #warning TODO: Add some fonts here. }; protected override FontMetrics CreateFontMetrics(Font font) { Font bdfFont; GetCompatibleFont(font, out bdfFont); return ((BDFFont)bdfFont).getFontMetrics(); } protected override void LoadFontsImpl() { foreach (BDFFontContainer container in getContainers()) { addFont(new BDFFont(container)); } } private List getContainers() { if (containers == null) { containers = new List(); foreach (byte[] fontResource in BuiltInFonts) { MemoryStream m = new MemoryStream(fontResource); containers.Add(((BDFFont)LoadFont(m)).getContainer()); } } return containers; } protected override ITextRenderer CreateTextRenderer(Image renderCache, Font font) { BDFFont bdfFont = (BDFFont)font; ITextRenderer renderer = new BDFTextRenderer(bdfFont.getContainer()); return renderer; } protected override AbstractFontProvider.Size GetMaxCharSize(object fontData) { BDFFontContainer container = (BDFFontContainer)fontData; Size size = new Size(); foreach (BDFGlyph g in container.getGlyphs()) { if (g != null) { size.maxCharWidth += g.getDWidth().width; size.maxCharHeight = Math.Max(g.getDWidth().height, size.maxCharHeight); } } return size; } public override Font LoadFont(System.IO.Stream s) { BDFFontContainer container = BDFFontContainer.CreateFont(s); addUserFontData(container); return new BDFFont(container); } } }