public Bitmap getGlyph(Color BGColor, Color FGColor, TerminalFrameBuffer.GraphicAttributeElements Elements, Char glyph) { var key = new Tuple <Color, Color, TerminalFrameBuffer.GraphicAttributeElements, Char>(BGColor, FGColor, Elements, glyph); if (glyphCache.TryGetValue(key, out Bitmap bits)) { return(bits); } Rectangle rect = new Rectangle(new Point(0, 0), charSize); bits = new Bitmap(charSize.Width, charSize.Height, terminalCanvasBitmapGraphic); using (var gr = Graphics.FromImage((Image)bits)) { gr.FillRectangle(_getSolid(BGColor), rect); if (!fontCache.TryGetValue(Elements, out Font procFont)) { procFont = buildFont(Elements); } String text = new String(glyph, 1); gr.DrawString(text, procFont, _getSolid(FGColor), rect, StringFormat.GenericTypographic); } glyphCache.Add(key, bits); return(bits); }
private Font setFont(TerminalFrameBuffer.GraphicAttributeElements elements, FontStyle style) { var _font = new Font(TerminalFont.FontFamily, TerminalFont.Size, style); fontCache.Add(elements, _font); return(_font); }
private Font buildFont(TerminalFrameBuffer.GraphicAttributeElements Elements) { if (Elements == TerminalFrameBuffer.GraphicAttributeElements.None) { return(TerminalFont); } if (fontCache.TryGetValue(Elements, out Font font)) { return(font); } var bold = Elements.HasFlag(TerminalFrameBuffer.GraphicAttributeElements.Bold); var italic = Elements.HasFlag(TerminalFrameBuffer.GraphicAttributeElements.Italic); var under = Elements.HasFlag(TerminalFrameBuffer.GraphicAttributeElements.Underline_Single) || Elements.HasFlag(TerminalFrameBuffer.GraphicAttributeElements.Underline_Double); if (bold && italic && under) { return(setFont(Elements, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline)); } if (bold && italic) { return(setFont(Elements, FontStyle.Bold | FontStyle.Italic)); } if (bold && under) { return(setFont(Elements, FontStyle.Bold | FontStyle.Underline)); } if (italic && under) { return(setFont(Elements, FontStyle.Italic | FontStyle.Underline)); } if (bold) { return(setFont(Elements, FontStyle.Bold)); } if (italic) { return(setFont(Elements, FontStyle.Italic)); } if (under) { return(setFont(Elements, FontStyle.Underline)); } return(setFont(Elements, FontStyle.Regular)); }