Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit f83117c

Browse files
author
Yuncong Zhang
committed
Make text_blob in mesh_info nullable.
1 parent 4920b6e commit f83117c

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

Runtime/painting/text_painter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public Offset getOffsetForCaret(TextPosition position, Rect caretPrototype) {
218218
{
219219
var rectNextLineTop = this._paragraph.getNextLineStartRectTop();
220220
if (rectNextLineTop != null) {
221-
return new Offset(0, (float) rectNextLineTop);
221+
return new Offset(0, rectNextLineTop.Value);
222222
}
223223
}
224224
}

Runtime/ui/painting/txt/mesh_generator.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class TextBlobMesh : PoolObject {
102102
static readonly Dictionary<MeshKey, MeshInfo> _meshes = new Dictionary<MeshKey, MeshInfo>();
103103
static long _frameCount = 0;
104104

105-
public TextBlob textBlob;
105+
public TextBlob? textBlob;
106106
public float scale;
107107
public uiMatrix3 matrix;
108108

@@ -116,6 +116,7 @@ public override void clear() {
116116
ObjectPool<uiMeshMesh>.release(this._mesh);
117117
this._mesh = null;
118118
this._resolved = false;
119+
this.textBlob = null;
119120
}
120121

121122
public static TextBlobMesh create(TextBlob textBlob, float scale, uiMatrix3 matrix) {
@@ -160,10 +161,10 @@ public uiMeshMesh resolveMesh() {
160161

161162
this._resolved = true;
162163

163-
var style = this.textBlob.style;
164+
var style = this.textBlob.Value.style;
164165

165-
var text = this.textBlob.text;
166-
var key = MeshKey.create(this.textBlob.instanceId, this.scale);
166+
var text = this.textBlob.Value.text;
167+
var key = MeshKey.create(this.textBlob.Value.instanceId, this.scale);
167168
var fontInfo = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle);
168169
var font = fontInfo.font;
169170

@@ -176,7 +177,7 @@ public uiMeshMesh resolveMesh() {
176177
}
177178

178179
// Handling Emoji
179-
char startingChar = text[this.textBlob.textOffset];
180+
char startingChar = text[this.textBlob.Value.textOffset];
180181
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
181182
var vert = ObjectPool<uiList<Vector3>>.alloc();
182183
var tri = ObjectPool<uiList<int>>.alloc();
@@ -189,13 +190,13 @@ public uiMeshMesh resolveMesh() {
189190
var minY = minMaxRect.top;
190191
var maxY = minMaxRect.bottom;
191192

192-
for (int i = 0; i < this.textBlob.textSize; i++) {
193-
char a = text[this.textBlob.textOffset + i];
193+
for (int i = 0; i < this.textBlob.Value.textSize; i++) {
194+
char a = text[this.textBlob.Value.textOffset + i];
194195
int code = a;
195196
if (char.IsHighSurrogate(a)) {
196-
D.assert(i + 1 < this.textBlob.textSize);
197-
D.assert(this.textBlob.textOffset + i + 1 < this.textBlob.text.Length);
198-
char b = text[this.textBlob.textOffset + i + 1];
197+
D.assert(i + 1 < this.textBlob.Value.textSize);
198+
D.assert(this.textBlob.Value.textOffset + i + 1 < this.textBlob.Value.text.Length);
199+
char b = text[this.textBlob.Value.textOffset + i + 1];
199200
D.assert(char.IsLowSurrogate(b));
200201
code = char.ConvertToUtf32(a, b);
201202
}
@@ -205,7 +206,7 @@ public uiMeshMesh resolveMesh() {
205206

206207
var uvRect = EmojiUtils.getUVRect(code);
207208

208-
var positionX = this.textBlob.getPositionX(i);
209+
var positionX = this.textBlob.Value.getPositionX(i);
209210

210211
int baseIndex = vert.Count;
211212
vert.Add(new Vector3(positionX + minX, minY, 0));
@@ -241,7 +242,7 @@ public uiMeshMesh resolveMesh() {
241242
return this._mesh;
242243
}
243244

244-
var length = this.textBlob.textSize;
245+
var length = this.textBlob.Value.textSize;
245246
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * this.scale);
246247

247248
var vertices = ObjectPool<uiList<Vector3>>.alloc();
@@ -254,9 +255,9 @@ public uiMeshMesh resolveMesh() {
254255
uv.SetCapacity(length * 4);
255256

256257
for (int charIndex = 0; charIndex < length; ++charIndex) {
257-
var ch = text[charIndex + this.textBlob.textOffset];
258+
var ch = text[charIndex + this.textBlob.Value.textOffset];
258259
// first char as origin for mesh position
259-
var positionX = this.textBlob.getPositionX(charIndex);
260+
var positionX = this.textBlob.Value.getPositionX(charIndex);
260261
if (LayoutUtils.isWordSpace(ch) || LayoutUtils.isLineEndSpace(ch) || ch == '\t') {
261262
continue;
262263
}

0 commit comments

Comments
 (0)