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

Commit 47d9175

Browse files
author
Yuncong Zhang
committed
Fix tab causing text overflow bug.
1 parent 8f69501 commit 47d9175

File tree

2 files changed

+15
-40
lines changed

2 files changed

+15
-40
lines changed

Runtime/ui/txt/layout.cs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,15 @@ static float _layoutWord(float offset, int layoutOffset,
162162
float letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft;
163163

164164
for (int i = 0; i < wordCount; i++) {
165+
initAdvance = x;
165166
var ch = text[start + i];
166167
if (i == 0) {
167168
x += letterSpaceHalfLeft + wordSpacing;
168-
if (advances != null) {
169-
advances[i + layoutOffset] = letterSpaceHalfLeft + wordSpacing;
170-
}
169+
advances[i + layoutOffset] = letterSpaceHalfLeft + wordSpacing;
171170
}
172171
else {
173-
if (advances != null) {
174-
advances[i - 1 + layoutOffset] += letterSpaceHalfRight;
175-
advances[i + layoutOffset] = letterSpaceHalfLeft;
176-
}
172+
advances[i - 1 + layoutOffset] += letterSpaceHalfRight;
173+
advances[i + layoutOffset] = letterSpaceHalfLeft;
177174

178175
x += letterSpace;
179176
}
@@ -182,9 +179,7 @@ static float _layoutWord(float offset, int layoutOffset,
182179
_updateBounds(glyphInfo, x, ref bounds);
183180
}
184181

185-
if (positions != null) {
186-
positions[i + layoutOffset] = x;
187-
}
182+
positions[i + layoutOffset] = x;
188183

189184
float advance;
190185
if (ch == '\t') {
@@ -195,15 +190,10 @@ static float _layoutWord(float offset, int layoutOffset,
195190
}
196191

197192
x += advance;
198-
if (advances != null) {
199-
advances[i + layoutOffset] += advance;
200-
}
193+
advances[i + layoutOffset] += advance;
201194

202195
if (i + 1 == wordCount) {
203-
if (advances != null) {
204-
advances[i + layoutOffset] += letterSpaceHalfRight;
205-
}
206-
196+
advances[i + layoutOffset] += letterSpaceHalfRight;
207197
x += letterSpaceHalfRight;
208198
}
209199
}
@@ -223,9 +213,7 @@ static float _layoutEmoji(string text, int start, int count, TextStyle style, Fo
223213
float letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft;
224214

225215
x += letterSpaceHalfLeft;
226-
if (advances != null) {
227-
advances[i] = letterSpaceHalfLeft;
228-
}
216+
advances[i] = letterSpaceHalfLeft;
229217

230218

231219
var minX = x;
@@ -234,28 +222,19 @@ static float _layoutEmoji(string text, int start, int count, TextStyle style, Fo
234222
var maxY = metrics.descent;
235223
_updateBounds(minX, maxX, minY, maxY, ref bounds);
236224

237-
if (positions != null) {
238-
positions[i] = x;
239-
}
225+
positions[i] = x;
240226

241227
float advance = style.fontSize;
242228
x += advance;
243229

244-
if (advances != null) {
245-
advances[i] += advance;
246-
advances[i] += letterSpaceHalfRight;
247-
}
230+
advances[i] += advance;
231+
advances[i] += letterSpaceHalfRight;
248232

249233
x += letterSpaceHalfRight;
250234
}
251235
else {
252-
if (advances != null) {
253-
advances[i] = 0;
254-
}
255-
256-
if (positions != null) {
257-
positions[i] = x;
258-
}
236+
advances[i] = 0;
237+
positions[i] = x;
259238
}
260239
}
261240

Runtime/ui/txt/paragraph.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,11 @@ public int getLine(TextPosition position) {
801801

802802
var offset = position.offset;
803803
if (position.affinity == TextAffinity.upstream && offset > 0) {
804-
offset = _isUtf16Surrogate(this._text[offset - 1]) ? offset - 2 : offset - 1;
804+
offset = char.IsSurrogate(this._text[offset - 1]) ? offset - 2 : offset - 1;
805805
}
806806

807807
var lineCount = this.getLineCount();
808-
for (int lineIndex = 0; lineIndex < this.getLineCount(); ++lineIndex) {
808+
for (int lineIndex = 0; lineIndex < lineCount; ++lineIndex) {
809809
var line = this._lineRanges[lineIndex];
810810
if ((offset >= line.start && offset < line.endIncludingNewLine)) {
811811
return lineIndex;
@@ -1090,10 +1090,6 @@ float getLineXOffset(float lineTotalAdvance) {
10901090

10911091
return 0;
10921092
}
1093-
1094-
static bool _isUtf16Surrogate(int value) {
1095-
return (value & 0xF800) == 0xD800;
1096-
}
10971093
}
10981094

10991095
class SplayTree<TKey, TValue> : IDictionary<TKey, TValue> where TKey : IComparable<TKey> {

0 commit comments

Comments
 (0)