浏览代码

Change PaintRecords to array.

/main
Yuncong Zhang 5 年前
当前提交
3a7ac100
共有 2 个文件被更改,包括 27 次插入32 次删除
  1. 2
      Runtime/ui/txt/layout.cs
  2. 57
      Runtime/ui/txt/paragraph.cs

2
Runtime/ui/txt/layout.cs


this._advance = _doLayout(offset, buff, start, count, style, this._advances, this._positions, 0,
this._tabStops);
this._bounds.Set(_x, _y, _maxX - _x, _maxY - _y);
this._count = count;
}
public static void computeCharWidths(TextBuff buff, int start, int count, TextStyle style, List<float> advances, int advanceOffset) {

57
Runtime/ui/txt/paragraph.cs


List<LineStyleRun> lineStyleRuns = new List<LineStyleRun>();
List<CodeUnitRun> lineCodeUnitRuns = new List<CodeUnitRun>();
List<GlyphPosition> lineGlyphPositions = new List<GlyphPosition>();
List<PaintRecord> paintRecords = new List<PaintRecord>();
Layout layout = new Layout();
layout.setTabStops(this._tabStops);

lineCodeUnitRuns.Clear();
lineGlyphPositions.Clear();
paintRecords.Clear();
words, lineStyleRuns, lineCodeUnitRuns, lineGlyphPositions, paintRecords,
words, lineStyleRuns, lineCodeUnitRuns, lineGlyphPositions,
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, List<CodeUnitRun> lineCodeUnitRuns,
List<GlyphPosition> lineGlyphPositions, List<PaintRecord> paintRecords,
List<GlyphPosition> lineGlyphPositions,
TextBlobBuilder builder, Layout layout) {
var lineRange = this._lineRanges[lineNumber];

: (this._width - this._lineWidths[lineNumber]) / (words.Count - 1);
this._computeLineStyleRuns(lineStyleRuns, lineRange, ref styleRunIndex);
for (int lineStyleRunIndex = 0; lineStyleRunIndex < lineStyleRuns.Count; ++lineStyleRunIndex) {
var run = lineStyleRuns[lineStyleRunIndex];
var isLastLineStyleRun = lineStyleRunIndex == lineStyleRuns.Count - 1;
this._generatePaintRecordFromLineStyleRun(
PaintRecord[] paintRecords = new PaintRecord[lineStyleRuns.Count];
for (int i = 0; i < lineStyleRuns.Count; ++i) {
var run = lineStyleRuns[i];
var isLastLineStyleRun = i == lineStyleRuns.Count - 1;
paintRecords[i] = this._generatePaintRecordFromLineStyleRun(
run,
layout,
builder,

ref justifyXOffset,
ref maxWordWidth,
words,
paintRecords,
lineGlyphPositions,
lineCodeUnitRuns);
}

while (styleRunIndex < this._runs.size) {
var styleRun = this._runs.getRun(styleRunIndex);
if (styleRun.start < lineEndIndex && styleRun.end > lineRange.start) {
lineStyleRuns.Add(new LineStyleRun(
Mathf.Max(styleRun.start, lineRange.start),
Mathf.Min(styleRun.end, lineEndIndex),
styleRun.style));
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) {
lineStyleRuns.Add(new LineStyleRun(start, end, styleRun.style));
}
}
if (styleRun.end >= lineEndIndex) {

}
}
void _generatePaintRecordFromLineStyleRun(
PaintRecord _generatePaintRecordFromLineStyleRun(
LineStyleRun run,
Layout layout, TextBlobBuilder builder,
bool isLastLineStyleRun,

ref float justifyXOffset,
ref float maxWordWidth,
List<Range<int>> words,
List<PaintRecord> paintRecords,
List<GlyphPosition> lineGlyphPositions,
List<CodeUnitRun> lineCodeUnitRuns) {
string text = this._text;

// It is assured in the _computeLineStyleRuns that run is not empty
// if (textCount == 0) {
// return;
// }
bool hardBreak = this._lineRanges[lineNumber].hardBreak;
if (this._shouldConsiderEllipsis(hardBreak, isLastLineStyleRun, lineNumber, lineLimit)) {
this._handleOverflowEllipsis(ref text, ref textStart, ref textCount, run.style, runXOffset);

}
layout.doLayout(runXOffset, new TextBuff(text), textStart, textCount, run.style);
if (layout.nGlyphs() == 0) {
return;
}
builder.allocRunPos(run.style, text, textStart, textCount);
// bounds relative to first character

ref justifyXOffset,
ref maxWordWidth);
if (glyphPositions == null) {
return;
}
this._generatePaintRecord(paintRecords, run.style, textBlob, runXOffset, advance);
PaintRecord paintRecord = this._generatePaintRecord(run.style, textBlob, runXOffset, advance);
return paintRecord;
}
bool _shouldConsiderEllipsis(bool hardBreak, bool isLastLineStyleRun, int lineNumber, int lineLimit) {

return glyphPositions;
}
void _generatePaintRecord(List<PaintRecord> paintRecords, TextStyle style, TextBlob textBlob,
float runXOffset, float advance) {
PaintRecord _generatePaintRecord(TextStyle style, TextBlob textBlob, float runXOffset, float advance) {
paintRecords.Add(new PaintRecord(style, new Offset(runXOffset, 0), textBlob, metrics, advance));
return new PaintRecord(style, new Offset(runXOffset, 0), textBlob, metrics, advance);
}
void _generateCodeUnitRun(List<CodeUnitRun> lineCodeUnitRuns, LineStyleRun run, int lineNumber,

void _computeLineOffset(int lineNumber,
List<GlyphPosition> lineGlyphPositions,
List<CodeUnitRun> lineCodeUnitRuns,
List<PaintRecord> paintRecords,
PaintRecord[] paintRecords,
ref float yOffset, ref float preMaxDescent) {
int lineStart = this._lineRanges[lineNumber].start;
int nextLineStart = lineNumber < this._lineRanges.Count - 1

updateLineMetrics(paintRecord.metrics, paintRecord.style);
}
if (paintRecords.Count == 0) {
if (paintRecords.Length == 0) {
var defaultStyle = this._paragraphStyle.getTextStyle();
var defaultFont = FontManager.instance.getOrCreate(defaultStyle.fontFamily,
defaultStyle.fontWeight, defaultStyle.fontStyle).font;

preMaxDescent = maxDescent;
}
void _addPaintRecordsWithOffset(List<PaintRecord> paintRecords, float lineXOffset, float yOffset) {
for (int i = 0; i < paintRecords.Count; i++) {
void _addPaintRecordsWithOffset(PaintRecord[] paintRecords, float lineXOffset, float yOffset) {
for (int i = 0; i < paintRecords.Length; i++) {
PaintRecord paintRecord = paintRecords[i];
paintRecord.offset = new Offset(paintRecord.offset.dx + lineXOffset, yOffset);
this._paintRecords.Add(paintRecord);

正在加载...
取消
保存