public Builder(TextViewModel model, Graphics g, StyleStack styleStack, Font defaultFont) { this.model = model; this.g = g; this.styleStack = styleStack; this.defaultFont = defaultFont; this.visibleLines = new SortedList <float, LayoutLine>(); }
private StyleStack GetStyleStack() { if (styleStack == null) { styleStack = new StyleStack(Services.RequireService <IUiPreferencesService>()); } return(styleStack); }
public TextViewPainter(TextViewLayout outer, Graphics g, Color fgColor, Color bgColor, Font defaultFont, StyleStack styleStack) { this.outer = outer; this.graphics = g; this.defaultFgColor = fgColor; this.defaultBgColor = bgColor; this.defaultFont = defaultFont; this.styleStack = styleStack; this.useGdiPlus = false; }
public RectangleF LogicalPositionToClient(Graphics g, TextPointer pos, StyleStack styleStack) { foreach (var line in this.visibleLines.Values) { if (line.Position == pos.Line) { return(SpanPositionToClient(g, pos, line, styleStack)); } } return(new RectangleF(new PointF(0, 0), CalculateExtent())); }
public TextPointer ClientToLogicalPosition(Graphics g, Point pt, StyleStack styleStack) { foreach (var line in this.visibleLines.Values) { if (line.Extent.Top <= pt.Y && pt.Y < line.Extent.Bottom) { return(FindSpanPosition(g, pt, line, styleStack)); } } return(new TextPointer(model.EndPosition, 0, 0)); }
private int GetCharPosition(Graphics g, Point ptClient, LayoutSpan span, StyleStack styleStack) { var x = ptClient.X - span.ContentExtent.Left; var textStub = span.Text; int iLow = 0; int iHigh = textStub.Length; styleStack.PushStyle(span.Style); var font = styleStack.GetFont(defaultFont); var sz = MeasureText(g, textStub, font); float xLow = 0; float xHigh = sz.Width; while (iLow < iHigh - 1) { int iMid = iLow + (iHigh - iLow) / 2; textStub = span.Text.Substring(0, iMid); sz = MeasureText(g, textStub, font); if (x < sz.Width) { iHigh = iMid; xHigh = sz.Width; } else { iLow = iMid; xLow = sz.Width; } } styleStack.PopStyle(); var cx = xHigh - xLow; if (x - xLow > cx) { return(iHigh); } else { return(iLow); } }
public static TextViewLayout VisibleLines(TextViewModel model, Size size, Graphics g, Font defaultFont, StyleStack styleStack) { var szClient = new SizeF(size); var rcLine = new RectangleF(0, 0, szClient.Width, 0); var builder = new Builder(model, g, styleStack, defaultFont); while (rcLine.Top < szClient.Height) { var lines = model.GetLineSpans(1); if (lines.Length == 0) { break; } builder.AddLayoutLine(lines[0], ref rcLine); } return(builder.Build()); }
/// <summary> /// Generates a TextViewLayout from all the lines in the model. /// </summary> /// <param name="model"></param> /// <param name="g"></param> /// <param name="defaultFont"></param> /// <param name="styleStack"></param> /// <returns></returns> public static TextViewLayout AllLines(TextViewModel model, Graphics g, Font defaultFont, StyleStack styleStack) { model.MoveToLine(model.StartPosition, 0); var rcLine = new RectangleF(); var builder = new Builder(model, g, styleStack, defaultFont); for (;;) { var lines = model.GetLineSpans(1); if (lines.Length == 0) { break; } builder.AddLayoutLine(lines[0], ref rcLine); } var layout = builder.Build(); return(layout); }
private RectangleF CharPositionToClient(Graphics g, TextPointer pos, LayoutSpan span, StyleStack styleStack) { var iChar = pos.Character; styleStack.PushStyle(span.Style); var font = styleStack.GetFont(defaultFont); var textStub = span.Text.Substring(0, iChar); var sz = MeasureText(g, textStub, font); var x = sz.Width + span.ContentExtent.Left; var width = 1; styleStack.PopStyle(); return(new RectangleF(x, span.ContentExtent.Top, width, span.ContentExtent.Height)); }
private RectangleF SpanPositionToClient(Graphics g, TextPointer pos, LayoutLine line, StyleStack styleStack) { var iSpan = pos.Span; if (iSpan < 0 || iSpan >= line.Spans.Length) { return(line.Extent); } var span = line.Spans[iSpan]; return(CharPositionToClient(g, pos, span, styleStack)); }
private TextPointer FindSpanPosition(Graphics g, Point ptClient, LayoutLine line, StyleStack styleStack) { int iSpan = 0; foreach (var span in line.Spans) { if (span.ContentExtent.Contains(ptClient)) { int iChar = GetCharPosition(g, ptClient, span, styleStack); return(new TextPointer(line.Position, iSpan, iChar)); } ++iSpan; } return(new TextPointer(line.Position, iSpan, 0)); }