浏览代码

Optimize PaintRecord offset.

/main
Yuncong Zhang 5 年前
当前提交
f597aadc
共有 3 个文件被更改,包括 35 次插入14 次删除
  1. 9
      Runtime/ui/txt/layout.cs
  2. 30
      Runtime/ui/txt/paint_record.cs
  3. 10
      Runtime/ui/txt/paragraph.cs

9
Runtime/ui/txt/layout.cs


public void doLayout(float offset, TextBuff buff, int start, int count, TextStyle style) {
this._start = start;
this._count = count;
this._advances = new float[count];
this._positions = new float[count];
if (this._advances == null || this._advances.Length < count) {
this._advances = new float[count];
}
if (this._positions == null || this._positions.Length < count) {
this._positions = new float[count];
}
_x = _y = _maxX = _maxY = 0;
this._advance = _doLayout(offset, buff, start, count, style, this._advances, this._positions, 0,

30
Runtime/ui/txt/paint_record.cs


namespace Unity.UIWidgets.ui {
struct PaintRecord {
public PaintRecord(TextStyle style, Offset offset, TextBlob text, FontMetrics metrics, float runWidth) {
public PaintRecord(TextStyle style, float dx, float dy, TextBlob text, FontMetrics metrics, float runWidth) {
this._offset = offset;
this._dx = dx;
this._dy = dy;
this._offset = null;
}
public TextBlob text {

get { return this._runWidth; }
}
public Offset offset {
get { return this._offset; }
set { this._offset = value; }
public FontMetrics metrics {
get { return this._metrics; }
public FontMetrics metrics {
get { return this._metrics; }
public float dx {
get { return this._dx; }
}
public float dy {
get { return this._dy; }
}
public void shift(float x, float y) {
this._dx += x;
this._dy += y;
}
public Offset shiftedOffset(Offset other) {
return new Offset(this._dx + other.dx, this._dy + other.dy);
}
TextStyle _style;

float _dx;
float _dy;
FontMetrics _metrics;
}
}

10
Runtime/ui/txt/paragraph.cs


filterMode = FilterMode.Bilinear,
color = paintRecord.style.color
};
canvas.drawTextBlob(paintRecord.text, paintRecord.offset + offset, paint);
canvas.drawTextBlob(paintRecord.text, paintRecord.shiftedOffset(offset), paint);
this.paintDecorations(canvas, paintRecord, offset);
}
}

var font = FontManager.instance.getOrCreate(style.fontFamily,
style.fontWeight, style.fontStyle).font;
var metrics = FontMetrics.fromFont(font, style.UnityFontSize);
return new PaintRecord(style, new Offset(runXOffset, 0), textBlob, metrics, advance);
return new PaintRecord(style, runXOffset, 0, textBlob, metrics, advance);
}
CodeUnitRun _generateCodeUnitRun(LineStyleRun run, int lineNumber, GlyphPosition[] glyphPositions) {

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);
paintRecord.shift(lineXOffset, yOffset);
this._paintRecords.Add(paintRecord);
}
}

float underLineThickness = metrics.underlineThickness ?? (record.style.fontSize / 14.0f);
paint.style = PaintingStyle.stroke;
paint.strokeWidth = underLineThickness;
var recordOffset = baseOffset + record.offset;
var recordOffset = record.shiftedOffset(baseOffset);
var x = recordOffset.dx;
var y = recordOffset.dy;

var metrics = record.metrics;
Rect rect = Rect.fromLTRB(0, metrics.ascent, record.runWidth, metrics.descent);
rect = rect.shift(baseOffset + record.offset);
rect = rect.shift(record.shiftedOffset(baseOffset));
canvas.drawRect(rect, record.style.background);
}

正在加载...
取消
保存