/// <summary> /// Draws text to given Graphics /// </summary> /// <param name="gr"></param> /// <param name="textbox"></param> /// <param name="start">Start place of drawing text</param> /// <param name="size">Size of drawing</param> public static void DrawText(Graphics gr, FastColoredTextBox textbox, Place start, Size size) { if (textbox.needRecalc) textbox.Recalc(); if (textbox.needRecalcFoldingLines) textbox.RecalcFoldingLines(); var startPoint = textbox.PlaceToPoint(start); var startY = startPoint.Y + textbox.VerticalScroll.Value; var startX = startPoint.X + textbox.HorizontalScroll.Value - textbox.LeftIndent - textbox.Paddings.Left; // determine range of characters that we can draw int firstChar = start.iChar; int lastChar = (startX + size.Width) / textbox.CharWidth; var startLine = start.iLine; //draw text for (int iLine = startLine; iLine < textbox.lines.Count; iLine++) { Line line = textbox.lines[iLine]; LineInfo lineInfo = textbox.LineInfos[iLine]; // if (lineInfo.startY > startY + size.Height) break; if (lineInfo.startY + lineInfo.WordWrapStringsCount * textbox.CharHeight < startY) continue; if (lineInfo.VisibleState == VisibleState.Hidden) continue; int y = lineInfo.startY - startY; // gr.SmoothingMode = SmoothingMode.None; //draw line background if (lineInfo.VisibleState == VisibleState.Visible) if (line.BackgroundBrush != null) gr.FillRectangle(line.BackgroundBrush, new Rectangle(0, y, size.Width, textbox.CharHeight * lineInfo.WordWrapStringsCount)); // gr.SmoothingMode = SmoothingMode.AntiAlias; //draw wordwrap strings of line for (int iWordWrapLine = 0; iWordWrapLine < lineInfo.WordWrapStringsCount; iWordWrapLine++) { y = lineInfo.startY + iWordWrapLine * textbox.CharHeight - startY; //indent var indent = iWordWrapLine == 0 ? 0 : lineInfo.wordWrapIndent * textbox.CharWidth; //draw chars Rendering.DrawLineChars(gr, textbox, firstChar, lastChar, iLine, iWordWrapLine, -startX + indent, y); } } }