浏览代码

Save glyphPosition.

/main
Yuncong Zhang 5 年前
当前提交
86237131
共有 1 个文件被更改,包括 33 次插入30 次删除
  1. 63
      Runtime/ui/txt/paragraph.cs

63
Runtime/ui/txt/paragraph.cs


public readonly TextDirection direction;
public readonly Range<int> codeUnits;
public Range<float> xPos;
public readonly GlyphPosition[] positions;
public readonly int start;
public readonly int count;
readonly GlyphPosition[] _positions;
TextDirection direction) {
TextDirection direction, int start, int count) {
this.positions = positions;
this._positions = positions;
this.start = start;
this.count = count;
D.assert(this.start >= 0 && this.start + this.count <= this._positions.Length);
for (int i = 0; i < this.positions.Length; ++i) {
this.positions[i].shiftSelf(shift);
for (int i = this.start; i < this.start + this.count; ++i) {
this._positions[i].shiftSelf(shift);
}
public GlyphPosition get(int i) {
D.assert(i < this.count);
return this._positions[this.start + i];
}
}

int textCount = textEnd - textStart;
// It is assured in the _computeLineStyleRuns that run is not empty
// if (textCount == 0) {
// return;
// }
D.assert(textCount != 0);
bool hardBreak = this._lineRanges[lineNumber].hardBreak;
if (this._shouldConsiderEllipsis(hardBreak, isLastLineStyleRun, lineNumber, lineLimit)) {

// bounds relative to first character
builder.setBounds(layout.translatedBounds());
GlyphPosition[] glyphPositions = this._populateGlyphPositions(
this._populateGlyphPositions(
lineGlyphPositions,
ref pLineGlyphPositions,
ref wordIndex,
ref justifyXOffset,
ref maxWordWidth);

PaintRecord paintRecord = this._generatePaintRecord(run.style, textBlob, runXOffset, advance);
runXOffset += advance;
this._codeUnitRuns.Add(this._generateCodeUnitRun(run, lineNumber, glyphPositions));
for (int i = 0; i < glyphPositions.Length; i++) {
lineGlyphPositions[pLineGlyphPositions++] = glyphPositions[i];
}
this._codeUnitRuns.Add(this._generateCodeUnitRun(run, lineNumber, lineGlyphPositions,
pLineGlyphPositions - textCount, textCount));
return paintRecord;
}

textCount = text.Length;
}
GlyphPosition[] _populateGlyphPositions(int textStart, int textCount,
void _populateGlyphPositions(int textStart, int textCount,
GlyphPosition[] lineGlyphPositions,
ref int pLineGlyphPositions,
if (textCount == 0) {
return null;
}
D.assert(textCount != 0);
GlyphPosition[] glyphPositions = new GlyphPosition[textCount];
glyphPositions[glyphIndex] = new GlyphPosition(runXOffset + glyphXOffset, glyphAdvance,
lineGlyphPositions[pLineGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset, glyphAdvance,
new Range<int>(textStart + glyphIndex, textStart + glyphIndex + 1));
if (wordIndex < words.Count) {
Range<int> word = words[wordIndex];

wordIndex++;
if (!float.IsNaN(wordStartPosition)) {
float wordWidth = glyphPositions.last().xPos.end - wordStartPosition;
float wordWidth = lineGlyphPositions[pLineGlyphPositions-1].xPos.end - wordStartPosition;
maxWordWidth = Mathf.Max(wordWidth, maxWordWidth);
wordStartPosition = float.NaN;
}

return glyphPositions;
}
PaintRecord _generatePaintRecord(TextStyle style, TextBlob textBlob, float runXOffset, float advance) {

return new PaintRecord(style, runXOffset, 0, textBlob, metrics, advance);
}
CodeUnitRun _generateCodeUnitRun(LineStyleRun run, int lineNumber, GlyphPosition[] glyphPositions) {
CodeUnitRun _generateCodeUnitRun(LineStyleRun run, int lineNumber, GlyphPosition[] glyphPositions, int start, int count) {
lineNumber, TextDirection.ltr);
lineNumber, TextDirection.ltr, start, count);
for (int i = 0; i < lineStyleRunCount; i++) {
this._codeUnitRuns[this._codeUnitRuns.Count - 1 - i].shift(lineXOffset);
}
for (int i = 0; i < lineGlyphPositions.Length; ++i) {
lineGlyphPositions[i].shiftSelf(lineXOffset);
}

else {
left = float.MaxValue;
right = float.MinValue;
foreach (var gp in run.positions) {
for (int i = 0; i < run.count; i++) {
var gp = run.get(i);
if (gp.codeUnits.start >= start && gp.codeUnits.end <= end) {
left = Mathf.Min(left, gp.xPos.start);
right = Mathf.Max(right, gp.xPos.end);

正在加载...
取消
保存