浏览代码

Fix some tab issues.

/main
Yuncong Zhang 6 年前
当前提交
ca9d1b43
共有 2 个文件被更改,包括 18 次插入11 次删除
  1. 25
      Runtime/ui/txt/layout.cs
  2. 4
      Runtime/ui/txt/paragraph.cs

25
Runtime/ui/txt/layout.cs


namespace Unity.UIWidgets.ui {
static class Layout {
// Measure the length of the span of the text. Currently, this is only used to compute the length
// of ellipsis, assuming that the ellipsis does not contain any tab, tab is not considered for simplicity
public static float measureText(string text, int start, int count, TextStyle style) {
char startingChar = text[start];
float totalWidth = 0;

return totalWidth;
}
public static int computeTruncateCount(string text, int start, int count, TextStyle style, float advanceLimit) {
public static int computeTruncateCount(float offset, string text, int start, int count, TextStyle style,
float advanceLimit, TabStops tabStops) {
float currentAdvance = 0;
float currentAdvance = offset;
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
float advance = style.fontSize + style.letterSpacing;
for (int i = 0; i < count; i++) {

Font font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
for (int i = 0; i < count; i++) {
char ch = text[start + i];
if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) {
if (ch == '\t') {
currentAdvance = tabStops.nextTab(currentAdvance);
}
else if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) {
currentAdvance += glyphInfo.advance + style.letterSpacing;
}
else {

if (LayoutUtils.isWordSpace(ch)) {
currentAdvance += style.wordSpacing;
}
if (currentAdvance > advanceLimit) {
return count - i;
}

return 0;
}
public static float doLayout(float offset, string text, int start, int count, float[] advances, float[] positions, TextStyle style, TabStops tabStops, out UnityEngine.Rect bounds) {
return _doLayout(offset, text, start, count, style, advances, positions, 0,
tabStops, out bounds);
}
public static void computeCharWidths(string text, int start, int count, TextStyle style, float[] advances, int advanceOffset) {
char startingChar = text[start];
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {

}
}
}
}
public static float doLayout(float offset, string text, int start, int count, float[] advances, float[] positions, TextStyle style, TabStops tabStops, out UnityEngine.Rect bounds) {
return _doLayout(offset, text, start, count, style, advances, positions, 0,
tabStops, out bounds);
}
static float _doLayout(float offset, string text, int start, int count, TextStyle style,

float advance = glyphInfo.advance;
if (ch == '\t') {
advance = tabStops.nextTab(initAdvance + offset) - initAdvance;
advance = tabStops.nextTab(initAdvance + offset) - initAdvance - offset;
}
x += advance;

4
Runtime/ui/txt/paragraph.cs


// Find the minimum number of characters to truncate, so that the truncated text appended with ellipsis
// is within the constraints of line width
int truncateCount =
Layout.computeTruncateCount(text, textStart, textCount, style, this._width - ellipsisWidth);
int truncateCount = Layout.computeTruncateCount(runXOffset, text, textStart, textCount, style,
this._width - ellipsisWidth, this._tabStops);
text = text.Substring(0, textStart + textCount - truncateCount) + ellipsis;
textCount = text.Length - textStart;

正在加载...
取消
保存