浏览代码

Make newLinePositions array.

/main
Yuncong Zhang 5 年前
当前提交
e599751f
共有 2 个文件被更改,包括 25 次插入20 次删除
  1. 29
      Runtime/ui/txt/linebreaker.cs
  2. 16
      Runtime/ui/txt/paragraph.cs

29
Runtime/ui/txt/linebreaker.cs


static LineBreaker _instance;
public static List<int> newLinePositions {
get {
if (_newLinePositions == null)
_newLinePositions = new List<int>();
return _newLinePositions;
public static int[] newLinePositions(string text, out int count) {
count = 0;
for (var i = 0; i < text.Length; i++) {
if (text[i] == '\n') {
count++;
}
}
count++;
if (_newLinePositions == null || _newLinePositions.Length < count) {
_newLinePositions = new int[count];
}
count = 0;
for (var i = 0; i < text.Length; i++) {
if (text[i] == '\n') {
_newLinePositions[count++] = i;
}
_newLinePositions[count++] = text.Length;
return _newLinePositions;
static List<int> _newLinePositions;
static int[] _newLinePositions;
TextBuff _textBuf;
float[] _charWidths;

16
Runtime/ui/txt/paragraph.cs


? this._paragraphStyle.maxLines ?? 1
: this._paragraphStyle.maxLines ?? 0;
var newLinePositions = LineBreaker.newLinePositions;
this._computeNewLinePositions(newLinePositions);
var newLinePositions = LineBreaker.newLinePositions(this._text, out int newLineCount);
for (var newlineIndex = 0; newlineIndex < newLinePositions.Count; ++newlineIndex) {
for (var newlineIndex = 0; newlineIndex < newLineCount; ++newlineIndex) {
if (lineLimit != 0 && this._lineRanges.Count >= lineLimit) {
break;
}

lineEndExcludingWhitespace, lineEndIncludingNewline, hardBreak));
this._lineWidths.Add(widths[i]);
}
}
void _computeNewLinePositions(List<int> newLinePositions) {
newLinePositions.Clear();
for (var i = 0; i < this._text.Length; i++) {
if (this._text[i] == '\n') {
newLinePositions.Add(i);
}
}
newLinePositions.Add(this._text.Length);
}
int _computeMaxWordCount() {

正在加载...
取消
保存