浏览代码

Reuse all lists in linebreaker, remove lineBaseLines.

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

71
Runtime/ui/txt/linebreaker.cs


TextBuff _textBuf;
float[] _charWidths;
List<int> _breaks = new List<int>();
int _breaksCount = 0;
int _widthsCount = 0;
WordBreaker _wordBreaker = new WordBreaker();
float _width = 0.0f;
float _preBreak;

TabStops _tabStops;
int mFirstTabIndex;
List<Candidate> _candidates = new List<Candidate>();
int _candidatesCount = 0;
int nCand = this._candidates.Count;
int nCand = this._candidatesCount;
var cand = this._candidates.last();
var cand = this._candidates[this._candidatesCount - 1];
return this._breaks.Count;
return this._breaksCount;
public List<int> getBreaks() {
return this._breaks;
public int getBreaksCount() {
return this._breaksCount;
}
public int getBreak(int i) {
return this._breaks[i];
}
public float getWidth(int i) {
return this._widths[i];
}
public void resize(int size) {

this._textBuf = new TextBuff(text, textOffset, textLength);
this._wordBreaker.setText(this._textBuf);
this._wordBreaker.next();
this._candidates.Clear();
this._candidatesCount = 0;
this._candidates.Add(can);
this._addCandidateToList(can);
this._lastBreak = 0;
this._bestBreak = 0;
this._bestScore = ScoreInfty;

public void finish() {
this._wordBreaker.finish();
this._width = 0;
this._candidates.Clear();
this._widths.Clear();
this._breaks.Clear();
this._candidatesCount = 0;
this._breaksCount = 0;
this._widthsCount = 0;
public List<float> getWidths() {
return this._widths;
public int getWidthsCount() {
return this._widthsCount;
}
public void setTabStops(TabStops tabStops) {

void _addWordBreak(int offset, float preBreak, float postBreak, int preSpaceCount, int postSpaceCount,
float penalty) {
float width = this._candidates.last().preBreak;
float width = this._candidates[this._candidatesCount - 1].preBreak;
if (postBreak - width > this._lineWidth) {
this._addCandidatesInsideWord(width, offset, postSpaceCount);
}

}
void _addCandidatesInsideWord(float width, int offset, int postSpaceCount) {
int i = this._candidates.last().offset;
int i = this._candidates[this._candidatesCount - 1].offset;
width += this._charWidths[i++];
for (; i < offset; i++) {
float w = this._charWidths[i];

}
}
void _addCandidateToList(Candidate cand) {
if (this._candidates.Count == this._candidatesCount) {
this._candidates.Add(cand);
this._candidatesCount++;
}
else {
this._candidates[this._candidatesCount++] = cand;
}
}
int candIndex = this._candidates.Count;
this._candidates.Add(cand);
int candIndex = this._candidatesCount;
this._addCandidateToList(cand);
if (cand.postBreak - this._preBreak > this._lineWidth) {
if (this._bestBreak == this._lastBreak) {
this._bestBreak = candIndex;

}
void _pushBreak(int offset, float width) {
if (this.lineLimit == 0 || this._breaks.Count < this.lineLimit) {
this._breaks.Add(offset);
this._widths.Add(width);
if (this.lineLimit == 0 || this._breaksCount < this.lineLimit) {
if (this._breaks.Count == this._breaksCount) {
this._breaks.Add(offset);
this._breaksCount++;
}
else {
this._breaks[this._breaksCount++] = offset;
}
if (this._widths.Count == this._widthsCount) {
this._widths.Add(width);
this._widthsCount++;
}
else {
this._widths[this._widthsCount++] = width;
}
}
}
}

20
Runtime/ui/txt/paragraph.cs


ParagraphStyle _paragraphStyle;
List<LineRange> _lineRanges = new List<LineRange>();
List<float> _lineWidths = new List<float>();
float[] _lineBaseLines;
// float[] _lineBaseLines;
GlyphLine[] _glyphLines;
float _maxIntrinsicWidth;
float _minIntrinsicWidth;

this._glyphLines = new GlyphLine[this._lineRanges.Count];
}
if (this._lineBaseLines == null || this._lineBaseLines.Length < this._lineRanges.Count) {
this._lineBaseLines = new float[this._lineRanges.Count];
}
// if (this._lineBaseLines == null || this._lineBaseLines.Length < this._lineRanges.Count) {
// this._lineBaseLines = new float[this._lineRanges.Count];
// }
if (this._lineHeights == null || this._lineHeights.Length < this._lineRanges.Count) {
this._lineHeights = new float[this._lineRanges.Count];

this._lineHeights[lineNumber] = ((lineNumber == 0 ? 0 : this._lineHeights[lineNumber - 1])
+ Mathf.Round(maxLineSpacing + maxDescent));
this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
// this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
yOffset += Mathf.Round(maxLineSpacing + preMaxDescent);
preMaxDescent = maxDescent;
float lineXOffset = this.getLineXOffset(runXOffset);

break;
}
if (lineBreaker.lineLimit != 0 && lineBreaker.getBreaks().Count >= lineBreaker.lineLimit) {
if (lineBreaker.lineLimit != 0 && lineBreaker.getBreaksCount() >= lineBreaker.lineLimit) {
break;
}

}
void _updateBreaks(LineBreaker lineBreaker, int breaksCount, int blockStart, int blockEnd) {
List<int> breaks = lineBreaker.getBreaks();
List<float> widths = lineBreaker.getWidths();
var breakStart = i > 0 ? breaks[i - 1] : 0;
var breakStart = i > 0 ? lineBreaker.getBreak(i - 1) : 0;
var lineEnd = breaks[i] + blockStart;
var lineEnd = lineBreaker.getBreak(i) + blockStart;
bool hardBreak = lineEnd == blockEnd;
var lineEndIncludingNewline =
hardBreak && lineEnd < this._text.Length ? lineEnd + 1 : lineEnd;

this._lineRanges.Add(new LineRange(lineStart, lineEnd,
lineEndExcludingWhitespace, lineEndIncludingNewline, hardBreak));
this._lineWidths.Add(widths[i]);
this._lineWidths.Add(lineBreaker.getWidth(i));
}
}

正在加载...
取消
保存