|
|
|
|
|
|
int ellipsizedLength = this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0); |
|
|
|
builder.allocPos(ellipsizedLength); |
|
|
|
GlyphPosition[] glyphPositions = new GlyphPosition[ellipsizedLength]; |
|
|
|
int maxWordCount = this._computeMaxWordCount(); |
|
|
|
if (maxWordCount == 0) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Range<int>[] words = new Range<int>[maxWordCount]; |
|
|
|
builder, layout, glyphPositions, ref pGlyphPositions |
|
|
|
builder, layout, words, glyphPositions, ref pGlyphPositions |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void _computePaintRecordsFromLine(int lineNumber, ref int lineLimit, ref int styleRunIndex, |
|
|
|
ref float maxWordWidth, ref float yOffset, ref float preMaxDescent, |
|
|
|
TextBlobBuilder builder, Layout layout, GlyphPosition[] glyphPositions, ref int pGlyphPositions) { |
|
|
|
ref float maxWordWidth, ref float yOffset, ref float preMaxDescent, TextBlobBuilder builder, Layout layout, |
|
|
|
Range<int>[] words, GlyphPosition[] glyphPositions, ref int pGlyphPositions) { |
|
|
|
var lineRange = this._lineRanges[lineNumber]; |
|
|
|
int wordIndex = 0; |
|
|
|
float runXOffset = 0; |
|
|
|
|
|
|
bool justifyLine = this._paragraphStyle.textAlign == TextAlign.justify && |
|
|
|
lineNumber != lineLimit - 1 && !lineRange.hardBreak; |
|
|
|
|
|
|
|
Range<int>[] words = this._findWords(lineRange.start, lineRange.end); |
|
|
|
float wordGapWidth = !(justifyLine && words != null && words.Length > 1) |
|
|
|
int wordCount = this._findWords(lineRange.start, lineRange.end, words); |
|
|
|
float wordGapWidth = !(justifyLine && wordCount > 1) |
|
|
|
: (this._width - this._lineWidths[lineNumber]) / (words.Length - 1); |
|
|
|
: (this._width - this._lineWidths[lineNumber]) / (wordCount - 1); |
|
|
|
|
|
|
|
int lineStyleRunCount = this._countLineStyleRuns(lineRange, styleRunIndex, out int maxTextCount); |
|
|
|
|
|
|
|
|
|
|
lineNumber, |
|
|
|
justifyLine, |
|
|
|
wordGapWidth, |
|
|
|
wordCount, |
|
|
|
ref tLineLimit, |
|
|
|
ref wordIndex, |
|
|
|
ref runXOffset, |
|
|
|
|
|
|
int lineNumber, |
|
|
|
bool justifyLine, |
|
|
|
float wordGapWidth, |
|
|
|
int wordCount, |
|
|
|
ref int lineLimit, |
|
|
|
ref int wordIndex, |
|
|
|
ref float runXOffset, |
|
|
|
|
|
|
runXOffset, |
|
|
|
wordGapWidth, |
|
|
|
justifyLine, |
|
|
|
wordCount, |
|
|
|
ref pLineGlyphPositions, |
|
|
|
ref wordIndex, |
|
|
|
ref justifyXOffset, |
|
|
|
|
|
|
float runXOffset, |
|
|
|
float wordGapWidth, |
|
|
|
bool justifyLine, |
|
|
|
int wordCount, |
|
|
|
ref int pLineGlyphPositions, |
|
|
|
ref int wordIndex, |
|
|
|
ref float justifyXOffset, |
|
|
|
|
|
|
builder.setPosition(glyphIndex, glyphXOffset); |
|
|
|
glyphPositions[pLineGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset, |
|
|
|
glyphAdvance, new Range<int>(textStart + glyphIndex, textStart + glyphIndex + 1)); |
|
|
|
if (words != null && wordIndex < words.Length) { |
|
|
|
if (words != null && wordIndex < wordCount) { |
|
|
|
Range<int> word = words[wordIndex]; |
|
|
|
if (word.start == runStart + glyphIndex) { |
|
|
|
wordStartPosition = runXOffset + glyphXOffset; |
|
|
|
|
|
|
newLinePositions.Add(this._text.Length); |
|
|
|
} |
|
|
|
|
|
|
|
Range<int>[] _findWords(int start, int end) { |
|
|
|
var inWord = false; |
|
|
|
int wordCount = 0; |
|
|
|
for (int i = start; i < end; ++i) { |
|
|
|
bool isSpace = LayoutUtils.isWordSpace(this._text[i]); |
|
|
|
if (!inWord && !isSpace) { |
|
|
|
inWord = true; |
|
|
|
int _computeMaxWordCount() { |
|
|
|
int max = 0; |
|
|
|
for (int lineNumber = 0; lineNumber < this._lineRanges.Count; lineNumber++) { |
|
|
|
var inWord = false; |
|
|
|
int wordCount = 0, start = this._lineRanges[lineNumber].start, end = this._lineRanges[lineNumber].end; |
|
|
|
for (int i = start; i < end; ++i) { |
|
|
|
bool isSpace = LayoutUtils.isWordSpace(this._text[i]); |
|
|
|
if (!inWord && !isSpace) { |
|
|
|
inWord = true; |
|
|
|
} |
|
|
|
else if (inWord && isSpace) { |
|
|
|
inWord = false; |
|
|
|
wordCount++; |
|
|
|
} |
|
|
|
else if (inWord && isSpace) { |
|
|
|
inWord = false; |
|
|
|
|
|
|
|
if (inWord) { |
|
|
|
} |
|
|
|
if (inWord) { |
|
|
|
wordCount++; |
|
|
|
if (wordCount > max) { |
|
|
|
max = wordCount; |
|
|
|
} |
|
|
|
if (wordCount == 0) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return max; |
|
|
|
} |
|
|
|
Range<int>[] words = new Range<int>[wordCount]; |
|
|
|
inWord = false; |
|
|
|
wordCount = 0; |
|
|
|
int _findWords(int start, int end, Range<int>[] words) { |
|
|
|
var inWord = false; |
|
|
|
int wordCount = 0; |
|
|
|
int wordStart = 0; |
|
|
|
|
|
|
|
for (int i = start; i < end; ++i) { |
|
|
|
|
|
|
words[wordCount] = new Range<int>(wordStart, end); |
|
|
|
} |
|
|
|
|
|
|
|
return words; |
|
|
|
return wordCount; |
|
|
|
} |
|
|
|
|
|
|
|
void paintDecorations(Canvas canvas, PaintRecord record, Offset baseOffset) { |
|
|
|