|
|
|
|
|
|
float maxWordWidth = 0; |
|
|
|
|
|
|
|
List<Range<int>> words = new List<Range<int>>(); |
|
|
|
List<LineStyleRun> lineStyleRuns = new List<LineStyleRun>(); |
|
|
|
|
|
|
|
Layout layout = new Layout(); |
|
|
|
layout.setTabStops(this._tabStops); |
|
|
|
|
|
|
words.Clear(); |
|
|
|
lineStyleRuns.Clear(); |
|
|
|
words, lineStyleRuns, builder, layout |
|
|
|
words, builder, layout |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void _computePaintRecordsFromLine(int lineNumber, ref int lineLimit, ref int styleRunIndex, |
|
|
|
ref float maxWordWidth, ref float yOffset, ref float preMaxDescent, List<Range<int>> words, |
|
|
|
List<LineStyleRun> lineStyleRuns, TextBlobBuilder builder, Layout layout) { |
|
|
|
TextBlobBuilder builder, Layout layout) { |
|
|
|
var lineRange = this._lineRanges[lineNumber]; |
|
|
|
int wordIndex = 0; |
|
|
|
float runXOffset = 0; |
|
|
|
|
|
|
? 0 |
|
|
|
: (this._width - this._lineWidths[lineNumber]) / (words.Count - 1); |
|
|
|
|
|
|
|
this._computeLineStyleRuns(lineStyleRuns, lineRange, ref styleRunIndex, out int totalTextCount, out int maxTextCount); |
|
|
|
LineStyleRun[] lineStyleRuns = this._computeLineStyleRuns(lineRange, ref styleRunIndex, out int totalTextCount, out int maxTextCount); |
|
|
|
if (lineStyleRuns == null) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
layout.allocAdvancesAndPositions(maxTextCount); |
|
|
|
|
|
|
|
// Add ellipsis length to make sure this array is big enough
|
|
|
|
|
|
|
? new GlyphPosition[totalTextCount + ellipsisLength] |
|
|
|
: new GlyphPosition[totalTextCount]; |
|
|
|
PaintRecord[] paintRecords = new PaintRecord[lineStyleRuns.Count]; |
|
|
|
PaintRecord[] paintRecords = new PaintRecord[lineStyleRuns.Length]; |
|
|
|
for (int i = 0; i < lineStyleRuns.Count; ++i) { |
|
|
|
for (int i = 0; i < lineStyleRuns.Length; ++i) { |
|
|
|
var isLastLineStyleRun = i == lineStyleRuns.Count - 1; |
|
|
|
var isLastLineStyleRun = i == lineStyleRuns.Length - 1; |
|
|
|
paintRecords[i] = this._generatePaintRecordFromLineStyleRun( |
|
|
|
run, |
|
|
|
layout, |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
float lineXOffset = this.getLineXOffset(runXOffset); |
|
|
|
this._shiftByLineXOffset(runXOffset, lineStyleRuns.Count, lineGlyphPositions); |
|
|
|
this._shiftByLineXOffset(runXOffset, lineStyleRuns.Length, lineGlyphPositions); |
|
|
|
void _computeLineStyleRuns(List<LineStyleRun> lineStyleRuns, LineRange lineRange, ref int styleRunIndex, out int totalTextCount, out int maxTextCount) { |
|
|
|
LineStyleRun[] _computeLineStyleRuns(LineRange lineRange, ref int styleRunIndex, out int totalTextCount, out int maxTextCount) { |
|
|
|
// Exclude trailing whitespace from right-justified lines so the last
|
|
|
|
// visible character in the line will be flush with the right margin.
|
|
|
|
int lineEndIndex = this._paragraphStyle.textAlign == TextAlign.right || |
|
|
|
|
|
|
|
|
|
|
totalTextCount = maxTextCount = 0; |
|
|
|
int lineStyleRunCount = 0; |
|
|
|
for (int i = styleRunIndex; i < this._runs.size; i++) { |
|
|
|
var styleRun = this._runs.getRun(i); |
|
|
|
if (styleRun.start < lineEndIndex && styleRun.end > lineRange.start) { |
|
|
|
int start = Mathf.Max(styleRun.start, lineRange.start); |
|
|
|
int end = Mathf.Min(styleRun.end, lineEndIndex); |
|
|
|
// Make sure that each line is not empty
|
|
|
|
if (start < end) { |
|
|
|
lineStyleRunCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (styleRun.end >= lineEndIndex) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (lineStyleRunCount == 0) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
LineStyleRun[] lineStyleRuns = new LineStyleRun[lineStyleRunCount]; |
|
|
|
|
|
|
|
int pLineStyleRun = 0; |
|
|
|
while (styleRunIndex < this._runs.size) { |
|
|
|
var styleRun = this._runs.getRun(styleRunIndex); |
|
|
|
if (styleRun.start < lineEndIndex && styleRun.end > lineRange.start) { |
|
|
|
|
|
|
if (start < end) { |
|
|
|
lineStyleRuns.Add(new LineStyleRun(start, end, styleRun.style)); |
|
|
|
lineStyleRuns[pLineStyleRun++] = new LineStyleRun(start, end, styleRun.style); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
styleRunIndex++; |
|
|
|
} |
|
|
|
|
|
|
|
return lineStyleRuns; |
|
|
|
} |
|
|
|
|
|
|
|
PaintRecord _generatePaintRecordFromLineStyleRun( |
|
|
|