public static Font get(Style style) { Font font; if (!fontCache.TryGetValue(uidOf(style), out font)) { fontCache[uidOf(style)] = font = createFont(style); } return font; }
protected Document() { rows = new DocumentRowCollection(); style = new Style { FontName = Control.DefaultFont.Name, FontHeight = Control.DefaultFont.SizeInPoints, Foreground = Color.Black, Background = Color.White }; }
internal DocumentView(DocumentViewSurface surface) { this.surface = surface; renderStuff = new RenderStuff(this); trace = new ViewControlTrace(this); keyActionMap = new KeyActionMap(); renderList = new Dictionary<int, DocumentRowView>(); createKeyCommands(); ClearStuff(); selectionStyle = new Style { Foreground = Color.White, Background = Color.Blue }; viewStyle = new ViewStyle(); }
public virtual Style Combine(Style style) { var result = new Style { FontHeight = FontHeight, FontName = FontName, Foreground = Foreground, Background = Background }; if (style.FontName != null) result.FontName = style.FontName; if (style.FontHeight > 0) result.FontHeight = style.FontHeight; if (!style.Foreground.IsEmpty) result.Foreground = style.Foreground; if (!style.Background.IsEmpty) result.Background = style.Background; result.FontStyle |= style.FontStyle; return result; }
public Face(string name, IStylizer owner) { this.name = name; this.owner = owner; faceStyle = new Style(); }
public StylizedRowElement(CharacterRange range, Style style) { this.range = range; this.style = style; }
private static Font createFont(Style style) { return new Font(style.FontName, style.FontHeight, style.FontStyle); }
private static string uidOf(Style style) { return style.FontName + ", " + style.FontHeight + "pt, " + style.FontStyle; }
private RectangleF MeasureStringPart(CharacterRange range, string str, Style style) { return MeasureStringPart(range, surface.Graphics, str, style); }
private RectangleF MeasureStringPart(CharacterRange range, Graphics g, string str, Style style) { if (range.Length == 0) return RectangleF.Empty; return MeasureStringParts(new[] { range }, g, str, style)[0]; }
private RectangleF[] MeasureStringParts(CharacterRange[] range, Graphics g, string str, Style style) { UpdateTabStop(str, style); stringFormat.SetMeasurableCharacterRanges(range); Region[] regn = g.MeasureCharacterRanges(str, FontCache.get(style), RectangleF.Empty, stringFormat); return Array.ConvertAll(regn, rgn => rgn.GetBounds(g)); }
private void UpdateTabStop(string str, Style style) { var tabCount = countTabs(str); if (tabCount <= 0) { return; } var tabString = new string(' ', ViewStyle.TabSize); var tabSize = surface.Graphics.MeasureString(tabString, FontCache.get(style), 0, stringFormat); stringFormat.SetTabStops(0, new[] { tabSize.Width }); }
private RectangleF DrawStringPart(CharacterRange range, Graphics g, string str, Style style, float offset) { string part = str.Substring(range.First, range.Length); UpdateTabStop(part, style); RectangleF size = MeasureStringPart(range, g, str, style); if (!style.Background.IsEmpty) { RectangleF textRect = size; textRect.X = 0; textRect.Offset(offset, 0); g.FillRectangle(BrushCache.getSolid(style.Background), textRect); } g.DrawString(part, FontCache.get(style), BrushCache.getForeground(style), offset, 0, stringFormat); return size; }
private int drawCursor(int cursor, CharacterRange part, float offset, Graphics g, string atomRaw, Style thisStyle) { if (cursor < 0 || cursor >= part.Length) return part.Length; renderStuff.caretRect = MeasureStringPart(new CharacterRange(cursor, 1), g, atomRaw, thisStyle); var caretRect = renderStuff.caretRect; caretRect.Offset(offset, 0); var pen = PenCache.GetSolid(Color.Black); pen.Width = 2; g.DrawLine(pen, caretRect.Left, caretRect.Top, caretRect.Left, caretRect.Bottom); return part.Length; }
public static Brush getForeground(Style style) { return getSolid(style.Foreground); }