浏览代码

Remove some textbuff and replace with direct text.

/main
Yuncong Zhang 5 年前
当前提交
cf00417e
共有 3 个文件被更改,包括 18 次插入19 次删除
  1. 28
      Runtime/ui/txt/layout.cs
  2. 2
      Runtime/ui/txt/linebreaker.cs
  3. 7
      Runtime/ui/txt/paragraph.cs

28
Runtime/ui/txt/layout.cs


static float _x, _y, _maxX, _maxY; // Used to pass bounds from static to non-static doLayout
public static float measureText(float offset, TextBuff buff, int start, int count, TextStyle style,
public static float measureText(float offset, string text, int start, int count, TextStyle style,
return _doLayout(offset, buff, start, count, style, advances, null, advanceOffset, tabStops);
return _doLayout(offset, text, start, count, style, advances, null, advanceOffset, tabStops);
public void doLayout(float offset, TextBuff buff, int start, int count, TextStyle style, TabStops tabStops) {
public void doLayout(float offset, string text, int start, int count, TextStyle style, TabStops tabStops) {
this._advance = _doLayout(offset, buff, start, count, style, this._advances, this._positions, 0,
this._advance = _doLayout(offset, text, start, count, style, this._advances, this._positions, 0,
public static void computeCharWidths(TextBuff buff, int start, int count, TextStyle style, List<float> advances, int advanceOffset) {
char startingChar = buff.charAt(start);
public static void computeCharWidths(string text, int start, int count, TextStyle style, List<float> advances, int advanceOffset) {
char startingChar = text[start];
char ch = buff.charAt(start + i);
char ch = text[start + i];
if (char.IsHighSurrogate(ch) || EmojiUtils.isSingleCharNonEmptyEmoji(ch)) {
advances[i + advanceOffset] = advance;
}

}
else {
Font font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
font.RequestCharactersInTextureSafe(buff.subString(start, count), style.UnityFontSize, style.UnityFontStyle);
font.RequestCharactersInTextureSafe(text.Substring(start, count), style.UnityFontSize, style.UnityFontStyle);
char ch = buff.charAt(start + i);
char ch = text[start + i];
if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) {
advances[i + advanceOffset] = glyphInfo.advance + style.letterSpacing;
}

}
}
static float _doLayout(float offset, TextBuff buff, int start, int count, TextStyle style,
static float _doLayout(float offset, string text, int start, int count, TextStyle style,
char startingChar = buff.charAt(start);
char startingChar = text[start];
advance = _layoutEmoji(buff.text, buff.offset + start, style, font, count,
advance = _layoutEmoji(text, start, style, font, count,
advances, positions, advanceOffset, advance);
}
else {

// : LayoutUtils.getPrevWordBreakForCache(buff, start + 1);
int wordend;
for (int iter = start; iter < start + count; iter = wordend) {
wordend = LayoutUtils.getNextWordBreak(buff.text, buff.offset + iter, start + count);
advance = _layoutWord(offset, iter - start, buff.text, iter + buff.offset,
wordend = LayoutUtils.getNextWordBreak(text, iter, start + count);
advance = _layoutWord(offset, iter - start, text, iter,
wordend - iter, style, font, advances, positions, advanceOffset, advance,
tabStops);
}

2
Runtime/ui/txt/linebreaker.cs


// Layout.measureText(this._width - this._preBreak, this._textBuf,
// start, end - start, style,
// this._charWidths, start, this._tabStops);
Layout.computeCharWidths(this._textBuf, start, end - start, style, this._charWidths, start);
Layout.computeCharWidths(this._textBuf.text, this._textBuf.offset + start, end - start, style, this._charWidths, start);
}
int current = this._wordBreaker.current();

7
Runtime/ui/txt/paragraph.cs


}
}
layout.doLayout(runXOffset, new TextBuff(text), textStart, textCount, run.style, this._tabStops);
layout.doLayout(runXOffset, text, textStart, textCount, run.style, this._tabStops);
builder.allocRunPos(run.style, text, textStart, textCount);
// bounds relative to first character

// performance, and the ellipsis is handled here
Layout.requireEllipsisInTexture(this._paragraphStyle.ellipsis, style);
TextBuff ellipsisTextBuff = new TextBuff(this._paragraphStyle.ellipsis);
float ellipsisWidth = Layout.measureText(runXOffset, ellipsisTextBuff, 0,
float ellipsisWidth = Layout.measureText(runXOffset, this._paragraphStyle.ellipsis, 0,
float textWidth = Layout.measureText(runXOffset, new TextBuff(text), textStart, textCount, style,
float textWidth = Layout.measureText(runXOffset, text, textStart, textCount, style,
textAdvances, 0, this._tabStops);
// Find the minimum number of characters to truncate, so that the truncated text appended with ellipsis

正在加载...
取消
保存