internal TextEditRow LayoutRow(int startIndex, int?width) { var r = new TextEditRow(); if (string.IsNullOrEmpty(_text)) { return(r); } _stringBuilder.Clear(); int? lastBreakPosition = null; Vector2?lastBreakMeasure = null; for (var i = startIndex; i < _text.Length; ++i) { var c = Text[i]; _stringBuilder.Append(c); Vector2 sz = Vector2.Zero; if (c != '\n') { sz = Font.MeasureString(_stringBuilder); } else { sz = new Vector2(r.x1 + NewLineWidth, Math.Max(r.ymax, CrossEngineStuff.LineSpacing(_font))); } if (width != null && c == '\n') { // Break right here ++r.num_chars; r.x1 = sz.X; r.ymax = sz.Y; r.baseline_y_delta = sz.Y; break; } if (width != null && sz.X > width.Value) { if (lastBreakPosition != null) { r.num_chars = lastBreakPosition.Value - startIndex; } if (lastBreakMeasure != null) { r.x1 = lastBreakMeasure.Value.X; r.ymax = lastBreakMeasure.Value.Y; r.baseline_y_delta = lastBreakMeasure.Value.Y; } break; } if (char.IsWhiteSpace(c)) { lastBreakPosition = i + 1; lastBreakMeasure = sz; } ++r.num_chars; r.x1 = sz.X; r.ymax = sz.Y; r.baseline_y_delta = sz.Y; } return(r); }
internal TextEditRow LayoutRow(int startIndex, int?width) { var r = new TextEditRow(); if (string.IsNullOrEmpty(_text)) { return(r); } _stringBuilder.Clear(); int? lastBreakPosition = null; Point?lastBreakMeasure = null; for (var i = startIndex; i < _text.Length; ++i) { var c = _displayText[i]; _stringBuilder.Append(c); var sz = Point.Zero; if (c != '\n') { var v = Font.MeasureString(_stringBuilder); sz = new Point((int)v.X, (int)v.Y); } else { sz = new Point(r.X + NewLineWidth, Math.Max(r.Y, CrossEngineStuff.LineSpacing(_font))); // Break right here ++r.CharsCount; r.X = sz.X; r.Y = sz.Y; break; } if (width != null && sz.X > width.Value) { if (lastBreakPosition != null) { r.CharsCount = lastBreakPosition.Value - startIndex; } if (lastBreakMeasure != null) { r.X = lastBreakMeasure.Value.X; r.Y = lastBreakMeasure.Value.Y; } break; } if (char.IsWhiteSpace(c)) { lastBreakPosition = i + 1; lastBreakMeasure = sz; } ++r.CharsCount; r.X = sz.X; r.Y = sz.Y; } return(r); }