浏览代码

Cleanup.

/main
Yuncong Zhang 5 年前
当前提交
3bfcc1c3
共有 3 个文件被更改,包括 64 次插入49 次删除
  1. 58
      Runtime/ui/painting/txt/mesh_generator.cs
  2. 15
      Runtime/ui/painting/txt/text_blob.cs
  3. 40
      Runtime/ui/txt/paragraph.cs

58
Runtime/ui/painting/txt/mesh_generator.cs


public float scale;
public MeshKey() {
}
public static MeshKey create(long textBlobId, float scale) {

long _timeToLive;
public MeshInfo() {
}
public static MeshInfo create(MeshKey key, uiMeshMesh mesh, long textureVersion, int timeToLive = 5) {

}
}
uiMeshMesh _mesh;
bool _resolved;

newMesh.matrix = matrix;
return newMesh;
}
public static long frameCount {
get { return _frameCount; }
}

}
static List<MeshKey> _keysToRemove = new List<MeshKey>();
public static void tickNextFrame() {
_frameCount++;
D.assert(_keysToRemove.Count == 0);

}
}
foreach (var key in _keysToRemove)
{
foreach (var key in _keysToRemove) {
_keysToRemove.Clear();
}

}
this._resolved = true;
_meshes.TryGetValue(key, out var meshInfo);
if (meshInfo != null && meshInfo.textureVersion == fontInfo.textureVersion) {
ObjectPool<MeshKey>.release(key);

}
// Handling Emoji
char startingChar = text[this.textBlob.textOffset];
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {

var metrics = FontMetrics.fromFont(font, style.UnityFontSize);
var minMaxRect = EmojiUtils.getMinMaxRect(style.fontSize, metrics.ascent, metrics.descent);
var minX = minMaxRect.left;

char a = text[this.textBlob.textOffset + i];
int code = a;
if (char.IsHighSurrogate(a)) {
D.assert(i+1 < this.textBlob.textSize);
D.assert(this.textBlob.textOffset+i+1 < this.textBlob.text.Length);
char b = text[this.textBlob.textOffset+i+1];
D.assert(i + 1 < this.textBlob.textSize);
D.assert(this.textBlob.textOffset + i + 1 < this.textBlob.text.Length);
char b = text[this.textBlob.textOffset + i + 1];
} else if (char.IsLowSurrogate(a) || EmojiUtils.isEmptyEmoji(a)) {
}
else if (char.IsLowSurrogate(a) || EmojiUtils.isEmptyEmoji(a)) {
var uvRect = EmojiUtils.getUVRect(code);
var pos = this.textBlob.getPosition(i);

uvCoord.Add(uvRect.topRight.toVector());
uvCoord.Add(uvRect.topLeft.toVector());
if(char.IsHighSurrogate(a)) i++;
if (char.IsHighSurrogate(a)) {
i++;
}
for (int charIndex = 0; charIndex < length; ++charIndex) {
var ch = text[charIndex + this.textBlob.textOffset];
// first char as origin for mesh position

if (fontSizeToLoad == 0) {
continue;
}
var minX = glyphInfo.minX / this.scale;
var maxX = glyphInfo.maxX / this.scale;
var minY = -glyphInfo.maxY / this.scale;

}
uiMeshMesh mesh = vertices.Count > 0 ? uiMeshMesh.create(null, vertices, triangles, uv) : null;
_meshes[key] = MeshInfo.create(key, mesh, fontInfo.textureVersion);
this._mesh = mesh.transform(this.matrix);

15
Runtime/ui/painting/txt/text_blob.cs


this.textSize = textSize;
this.style = style;
this._bounds = bounds;
this._boundsInText = null;
var pos = this.getPosition(0);
return Rect.fromLTWH(this._bounds.xMin + pos, this._bounds.yMin,
this._bounds.width, this._bounds.height);
if (this._boundsInText == null) {
var pos = this.getPosition(0);
this._boundsInText = Rect.fromLTWH(this._bounds.xMin + pos, this._bounds.yMin,
this._bounds.width, this._bounds.height);
}
return this._boundsInText;
}
}

internal readonly TextStyle style;
readonly UnityEngine.Rect _bounds; // bounds with positions[start] as origin
readonly float[] _positions;
Rect _boundsInText;
}
public struct TextBlobBuilder {

return result;
}
}
}
}

40
Runtime/ui/txt/paragraph.cs


get { return this._didExceedMaxLines; }
}
static List<Paragraph> _paragraphs = new List<Paragraph>();
static List<Paragraph> _paragraphPool = new List<Paragraph>();
if (_paragraphs.isEmpty()) {
if (_paragraphPool.isEmpty()) {
Paragraph ret = _paragraphs.last();
_paragraphs.RemoveAt(_paragraphs.Count - 1);
Paragraph ret = _paragraphPool.last();
_paragraphPool.RemoveAt(_paragraphPool.Count - 1);
_paragraphs.Add(paragraph);
_paragraphPool.Add(paragraph);
readonly Paint _textPaint = new Paint {
filterMode = FilterMode.Bilinear
};
public void paint(Canvas canvas, Offset offset) {
for (int i = 0; i < this._paintRecordsCount; i++) {
var paintRecord = this._paintRecords[i];

for (int i = 0; i < this._paintRecordsCount; i++) {
var paintRecord = this._paintRecords[i];
var paint = new Paint {
filterMode = FilterMode.Bilinear,
color = paintRecord.style.color
};
canvas.drawTextBlob(paintRecord.text, paintRecord.shiftedOffset(offset), paint);
this._textPaint.color = paintRecord.style.color;
canvas.drawTextBlob(paintRecord.text, paintRecord.shiftedOffset(offset), this._textPaint);
this.paintDecorations(canvas, paintRecord, offset);
}
}

runIndex++;
}
this._maxIntrinsicWidth = Mathf.Max(lineBlockWidth, this._maxIntrinsicWidth);
return countRuns;

return;
}
var paint = new Paint();
paint.color = record.style.color;
this._textPaint.color = record.style.color;
paint.color = record.style.decorationColor;
this._textPaint.color = record.style.decorationColor;
}

paint.style = PaintingStyle.stroke;
paint.strokeWidth = underLineThickness;
this._textPaint.style = PaintingStyle.stroke;
this._textPaint.strokeWidth = underLineThickness;
var recordOffset = record.shiftedOffset(baseOffset);
var x = recordOffset.dx;
var y = recordOffset.dy;

if (decoration != null && decoration.contains(TextDecoration.underline)) {
// underline
yOffset += metrics.underlinePosition ?? underLineThickness;
canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), paint);
canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), this._textPaint);
canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), paint);
canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), this._textPaint);
yOffset = yOffsetOriginal;
}

canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), paint);
canvas.drawLine(new Offset(x, y + yOffset), new Offset(x + width, y + yOffset), this._textPaint);
this._textPaint.style = PaintingStyle.fill;
this._textPaint.strokeWidth = 0;
}
void paintBackground(Canvas canvas, PaintRecord record, Offset baseOffset) {

正在加载...
取消
保存