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

Commit 77d9edb

Browse files
author
Yuncong Zhang
committed
Fix issues.
1 parent 73ada8e commit 77d9edb

File tree

11 files changed

+54
-47
lines changed

11 files changed

+54
-47
lines changed

Runtime/painting/text_painter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public TextPainter(TextSpan text = null,
3434
this._ellipsis = ellipsis;
3535
}
3636

37+
~TextPainter() {
38+
Paragraph.release(ref this._paragraph);
39+
}
40+
3741
public float textScaleFactor {
3842
get { return this._textScaleFactor; }
3943
set {

Runtime/rendering/editable.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -884,11 +884,11 @@ public TextPosition getParagraphForward(TextPosition position, TextAffinity? aff
884884
Paragraph.LineRange? line = null;
885885
for (int i = 0; i < lineCount; ++i) {
886886
line = this._textPainter.getLineRange(i);
887-
if (!((Paragraph.LineRange) line).hardBreak) {
887+
if (!line.Value.hardBreak) {
888888
continue;
889889
}
890890

891-
if (((Paragraph.LineRange) line).end > position.offset) {
891+
if (line.Value.end > position.offset) {
892892
break;
893893
}
894894
}
@@ -897,7 +897,7 @@ public TextPosition getParagraphForward(TextPosition position, TextAffinity? aff
897897
return new TextPosition(position.offset, affinity ?? position.affinity);
898898
}
899899

900-
return new TextPosition(((Paragraph.LineRange) line).end, affinity ?? position.affinity);
900+
return new TextPosition(line.Value.end, affinity ?? position.affinity);
901901
}
902902

903903

@@ -911,7 +911,7 @@ public TextPosition getParagraphBackward(TextPosition position, TextAffinity? af
911911
continue;
912912
}
913913

914-
if (((Paragraph.LineRange) line).start < position.offset) {
914+
if (line.Value.start < position.offset) {
915915
break;
916916
}
917917
}
@@ -920,7 +920,7 @@ public TextPosition getParagraphBackward(TextPosition position, TextAffinity? af
920920
return new TextPosition(position.offset, affinity ?? position.affinity);
921921
}
922922

923-
return new TextPosition(((Paragraph.LineRange) line).start, affinity ?? position.affinity);
923+
return new TextPosition(line.Value.start, affinity ?? position.affinity);
924924
}
925925

926926
protected override float computeMinIntrinsicWidth(float height) {

Runtime/ui/painting/draw_cmd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class DrawPicture : DrawCmd {
8787
}
8888

8989
public class DrawTextBlob : DrawCmd {
90-
public TextBlob textBlob;
90+
public TextBlob? textBlob;
9191
public Offset offset;
9292
public Paint paint;
9393
}

Runtime/ui/painting/picture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void addDrawCmd(DrawCmd drawCmd) {
268268
case DrawTextBlob cmd: {
269269
var state = this._getState();
270270
var scale = XformUtils.getScale(state.xform);
271-
var rect = cmd.textBlob.shiftedBoundsInText(cmd.offset);
271+
var rect = cmd.textBlob.Value.shiftedBoundsInText(cmd.offset.dx, cmd.offset.dy);
272272
rect = state.xform.mapRect(rect);
273273

274274
var paint = cmd.paint;

Runtime/ui/painting/txt/mesh_generator.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ public uiMeshMesh resolveMesh() {
205205

206206
var uvRect = EmojiUtils.getUVRect(code);
207207

208-
var pos = this.textBlob.getPosition(i);
208+
var positionX = this.textBlob.getPositionX(i);
209209

210210
int baseIndex = vert.Count;
211-
vert.Add(new Vector3(pos + minX, minY, 0));
212-
vert.Add(new Vector3(pos + maxX, minY, 0));
213-
vert.Add(new Vector3(pos + maxX, maxY, 0));
214-
vert.Add(new Vector3(pos + minX, maxY, 0));
211+
vert.Add(new Vector3(positionX + minX, minY, 0));
212+
vert.Add(new Vector3(positionX + maxX, minY, 0));
213+
vert.Add(new Vector3(positionX + maxX, maxY, 0));
214+
vert.Add(new Vector3(positionX + minX, maxY, 0));
215215
tri.Add(baseIndex);
216216
tri.Add(baseIndex + 1);
217217
tri.Add(baseIndex + 2);
@@ -256,7 +256,7 @@ public uiMeshMesh resolveMesh() {
256256
for (int charIndex = 0; charIndex < length; ++charIndex) {
257257
var ch = text[charIndex + this.textBlob.textOffset];
258258
// first char as origin for mesh position
259-
var position = this.textBlob.getPosition(charIndex);
259+
var positionX = this.textBlob.getPositionX(charIndex);
260260
if (LayoutUtils.isWordSpace(ch) || LayoutUtils.isLineEndSpace(ch) || ch == '\t') {
261261
continue;
262262
}
@@ -274,10 +274,10 @@ public uiMeshMesh resolveMesh() {
274274

275275
var baseIndex = vertices.Count;
276276

277-
vertices.Add(new Vector3(position + minX, minY, 0));
278-
vertices.Add(new Vector3(position + maxX, minY, 0));
279-
vertices.Add(new Vector3(position + maxX, maxY, 0));
280-
vertices.Add(new Vector3(position + minX, maxY, 0));
277+
vertices.Add(new Vector3(positionX + minX, minY, 0));
278+
vertices.Add(new Vector3(positionX + maxX, minY, 0));
279+
vertices.Add(new Vector3(positionX + maxX, maxY, 0));
280+
vertices.Add(new Vector3(positionX + minX, maxY, 0));
281281

282282
triangles.Add(baseIndex);
283283
triangles.Add(baseIndex + 1);

Runtime/ui/painting/txt/text_blob.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
namespace Unity.UIWidgets.ui {
22
public struct TextBlob {
3-
internal TextBlob(string text, int textOffset, int textSize, float[] positions,
3+
internal TextBlob(string text, int textOffset, int textSize, float[] positionXs,
44
UnityEngine.Rect bounds, TextStyle style) {
55
this.instanceId = ++_nextInstanceId;
6-
this._positions = positions;
6+
this._positionXs = positionXs;
77
this.text = text;
88
this.textOffset = textOffset;
99
this.textSize = textSize;
@@ -15,7 +15,7 @@ internal TextBlob(string text, int textOffset, int textSize, float[] positions,
1515
public Rect boundsInText {
1616
get {
1717
if (this._boundsInText == null) {
18-
var pos = this.getPosition(0);
18+
var pos = this.getPositionX(0);
1919
this._boundsInText = Rect.fromLTWH(this._bounds.xMin + pos, this._bounds.yMin,
2020
this._bounds.width, this._bounds.height);
2121
}
@@ -24,14 +24,14 @@ public Rect boundsInText {
2424
}
2525
}
2626

27-
public Rect shiftedBoundsInText(Offset offset) {
28-
var pos = this.getPosition(0);
29-
return Rect.fromLTWH(this._bounds.xMin + pos + offset.dx, this._bounds.yMin + offset.dy,
27+
public Rect shiftedBoundsInText(float dx, float dy) {
28+
var pos = this.getPositionX(0);
29+
return Rect.fromLTWH(this._bounds.xMin + pos + dx, this._bounds.yMin + dy,
3030
this._bounds.width, this._bounds.height);
3131
}
3232

33-
public float getPosition(int i) {
34-
return this._positions[this.textOffset + i];
33+
public float getPositionX(int i) {
34+
return this._positionXs[this.textOffset + i];
3535
}
3636

3737
static long _nextInstanceId;
@@ -41,14 +41,14 @@ public float getPosition(int i) {
4141
internal readonly int textSize;
4242
internal readonly TextStyle style;
4343
readonly UnityEngine.Rect _bounds; // bounds with positions[start] as origin
44-
readonly float[] _positions;
44+
readonly float[] _positionXs;
4545

4646
Rect _boundsInText;
4747
}
4848

4949
public struct TextBlobBuilder {
5050
TextStyle _style;
51-
float[] _positions;
51+
float[] _positionXs;
5252
string _text;
5353
int _textOffset;
5454
int _size;
@@ -71,17 +71,17 @@ internal void allocRunPos(TextStyle style, string text, int offset, int size) {
7171
}
7272

7373
internal void allocPos(int size) {
74-
if (this._positions == null || this._positions.Length < size) {
75-
this._positions = new float[size];
74+
if (this._positionXs == null || this._positionXs.Length < size) {
75+
this._positionXs = new float[size];
7676
}
7777
}
7878

79-
public void setPosition(int i, float position) {
80-
this._positions[this._textOffset + i] = position;
79+
public void setPositionX(int i, float positionX) {
80+
this._positionXs[this._textOffset + i] = positionX;
8181
}
8282

83-
public void setPositions(float[] positions) {
84-
this._positions = positions;
83+
public void setPositionXs(float[] positionXs) {
84+
this._positionXs = positionXs;
8585
}
8686

8787
public void setBounds(UnityEngine.Rect bounds) {
@@ -90,7 +90,7 @@ public void setBounds(UnityEngine.Rect bounds) {
9090

9191
public TextBlob make() {
9292
var result = new TextBlob(this._text, this._textOffset,
93-
this._size, this._positions, this._bounds, this._style);
93+
this._size, this._positionXs, this._bounds, this._style);
9494
return result;
9595
}
9696
}

Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_impl.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -928,22 +928,23 @@ void _drawUIPicture(uiPicture picture, bool needsSave = true) {
928928
}
929929
}
930930

931-
void _drawTextBlob(TextBlob textBlob, uiOffset offset, uiPaint paint) {
931+
void _drawTextBlob(TextBlob? textBlob, uiOffset offset, uiPaint paint) {
932+
D.assert(textBlob != null);
932933

933934
var state = this._currentLayer.currentState;
934935
var scale = state.scale * this._devicePixelRatio;
935936

936937
var matrix = new uiMatrix3(state.matrix.Value);
937938
matrix.preTranslate(offset.dx, offset.dy);
938939

939-
var mesh = TextBlobMesh.create(textBlob, scale, matrix);
940-
var textBlobBounds = matrix.mapRect(uiRectHelper.fromRect(textBlob.boundsInText));
940+
var mesh = TextBlobMesh.create(textBlob.Value, scale, matrix);
941+
var textBlobBounds = matrix.mapRect(uiRectHelper.fromRect(textBlob.Value.boundsInText));
941942

942943
// request font texture so text mesh could be generated correctly
943-
var style = textBlob.style;
944+
var style = textBlob.Value.style;
944945
var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
945946
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * scale);
946-
var subText = textBlob.text.Substring(textBlob.textOffset, textBlob.textSize);
947+
var subText = textBlob.Value.text.Substring(textBlob.Value.textOffset, textBlob.Value.textSize);
947948
Texture tex = null;
948949
bool notEmoji = !char.IsHighSurrogate(subText[0]) && !EmojiUtils.isSingleCharEmoji(subText[0]);
949950
if (notEmoji) {

Runtime/ui/renderer/common/draw_cmd.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,11 @@ public override void release() {
405405
}
406406

407407
public override void clear() {
408+
this.textBlob = null;
408409
this.offset = null;
409410
}
410411

411-
public TextBlob textBlob;
412+
public TextBlob? textBlob;
412413
public uiOffset? offset;
413414
public uiPaint paint;
414415
}

Runtime/ui/renderer/common/picture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ public void addDrawCmd(uiDrawCmd drawCmd) {
261261
case uiDrawTextBlob cmd: {
262262
var state = this._getState();
263263
var scale = uiXformUtils.getScale(state.xform);
264-
var rect = uiRectHelper.fromRect(cmd.textBlob.boundsInText).shift(cmd.offset.Value);
264+
var rect = uiRectHelper.fromRect(
265+
cmd.textBlob.Value.shiftedBoundsInText(cmd.offset.Value.dx, cmd.offset.Value.dy));
265266
rect = state.xform.mapRect(rect);
266267

267268
var paint = cmd.paint;

Runtime/ui/txt/paragraph.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
188188
PaintRecord[] _paintRecords;
189189
CodeUnitRun[] _codeUnitRuns;
190190
float[] _lineHeights;
191-
float[] _textBlobPositions;
191+
float[] _textBlobPositionXs;
192192
float _maxIntrinsicWidth;
193193
float _minIntrinsicWidth;
194194
float _alphabeticBaseline;
@@ -333,11 +333,11 @@ public void layout(ParagraphConstraints constraints) {
333333
int ellipsizedLength = this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0);
334334

335335
// All text blobs share a single position buffer, which is big enough taking ellipsis into consideration
336-
if (this._textBlobPositions == null || this._textBlobPositions.Length < ellipsizedLength) {
337-
this._textBlobPositions = new float[LayoutUtils.minPowerOfTwo(ellipsizedLength)];
336+
if (this._textBlobPositionXs == null || this._textBlobPositionXs.Length < ellipsizedLength) {
337+
this._textBlobPositionXs = new float[LayoutUtils.minPowerOfTwo(ellipsizedLength)];
338338
}
339339

340-
builder.setPositions(this._textBlobPositions);
340+
builder.setPositionXs(this._textBlobPositionXs);
341341
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
342342
if (this._glyphPositions == null || this._glyphPositions.Length < ellipsizedLength) {
343343
this._glyphPositions = new GlyphPosition[LayoutUtils.minPowerOfTwo(ellipsizedLength)];
@@ -467,7 +467,7 @@ public void layout(ParagraphConstraints constraints) {
467467
for (int glyphIndex = 0; glyphIndex < textCount; ++glyphIndex) {
468468
float glyphXOffset = _positionsBuffer[glyphIndex] + justifyXOffset;
469469
float glyphAdvance = _advancesBuffer[glyphIndex];
470-
builder.setPosition(glyphIndex, glyphXOffset);
470+
builder.setPositionX(glyphIndex, glyphXOffset);
471471
this._glyphPositions[pGlyphPositions++] = new GlyphPosition(runXOffset + glyphXOffset,
472472
glyphAdvance, textStart + glyphIndex);
473473
if (wordIndex < wordCount) {

0 commit comments

Comments
 (0)