浏览代码

Optimize.

/main
Yuncong Zhang 5 年前
当前提交
16c4a06d
共有 4 个文件被更改,包括 51 次插入65 次删除
  1. 92
      Runtime/ui/txt/layout.cs
  2. 18
      Runtime/ui/txt/paragraph.cs
  3. 4
      Runtime/ui/txt/text_buff.cs
  4. 2
      Runtime/ui/txt/wordbreaker.cs

92
Runtime/ui/txt/layout.cs


}
else {
Font font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
font.RequestCharactersInTextureSafe(buff.text, style.UnityFontSize, style.UnityFontStyle);
font.RequestCharactersInTextureSafe(buff.subString(start, count), style.UnityFontSize, style.UnityFontStyle);
for (int i = 0; i < count; i++) {
char ch = buff.charAt(start + i);
if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) {

}
if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) {
var minX = glyphInfo.minX + x;
var maxX = glyphInfo.maxX + x;
var minY = -glyphInfo.maxY;
var maxY = -glyphInfo.minY;
if (_innerBounds.width <= 0 || _innerBounds.height <= 0) {
_innerBounds.x = minX;
_innerBounds.y = minY;
_innerBounds.xMax = maxX;
_innerBounds.yMax = maxY;
}
else {
if (minX < _innerBounds.x) {
_innerBounds.x = minX;
}
if (minY < _innerBounds.y) {
_innerBounds.y = minY;
}
if (maxX > _innerBounds.xMax) {
_innerBounds.xMax = maxX;
}
if (maxY > _innerBounds.yMax) {
_innerBounds.yMax = maxY;
}
}
_updateInnerBounds(glyphInfo, x);
}
if (positions != null) {

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

var maxX = metrics.descent - metrics.ascent + x;
var minY = metrics.ascent;
var maxY = metrics.descent;
if (_innerBounds.width <= 0 || _innerBounds.height <= 0) {
_innerBounds.x = minX;
_innerBounds.y = minY;
_innerBounds.xMax = maxX;
_innerBounds.yMax = maxY;
}
else {
if (minX < _innerBounds.x) {
_innerBounds.x = minX;
}
if (minY < _innerBounds.y) {
_innerBounds.y = minY;
}
if (maxX > _innerBounds.xMax) {
_innerBounds.xMax = maxX;
}
if (maxY > _innerBounds.yMax) {
_innerBounds.yMax = maxY;
}
}
_updateInnerBounds(minX, maxX, minY, maxY);
if (positions != null) {
positions[i] = x;

}
return x;
}
static void _updateInnerBounds(CharacterInfo glyphInfo, float x) {
var minX = glyphInfo.minX + x;
var maxX = glyphInfo.maxX + x;
var minY = -glyphInfo.maxY;
var maxY = -glyphInfo.minY;
_updateInnerBounds(minX, maxX, minY, maxY);
}
static void _updateInnerBounds(float minX, float maxX, float minY, float maxY) {
if (_innerBounds.width <= 0 || _innerBounds.height <= 0) {
_innerBounds.x = minX;
_innerBounds.y = minY;
_innerBounds.xMax = maxX;
_innerBounds.yMax = maxY;
}
else {
if (minX < _innerBounds.x) {
_innerBounds.x = minX;
}
if (minY < _innerBounds.y) {
_innerBounds.y = minY;
}
if (maxX > _innerBounds.xMax) {
_innerBounds.xMax = maxX;
}
if (maxY > _innerBounds.yMax) {
_innerBounds.yMax = maxY;
}
}
}
public static void requireEllipsisInTexture(string text, TextStyle style) {

18
Runtime/ui/txt/paragraph.cs


this.direction = direction;
}
public void Shift(float shift) {
public void shift(float shift) {
this.xPos = RangeUtils.shift(this.xPos, shift);
for (int i = 0; i < this.positions.Count; ++i) {
this.positions[i] = this.positions[i].shift(shift);

}
var textStyle = this._paragraphStyle.getTextStyle();
this._tabStops.setFont(FontManager.instance.getOrCreate(textStyle.fontFamily,
textStyle.fontWeight, textStyle.fontStyle).font,
this._tabStops.setFont(
FontManager.instance.getOrCreate(textStyle.fontFamily, textStyle.fontWeight, textStyle.fontStyle).font,
textStyle.UnityFontSize);
this._needsLayout = false;

lineCodeUnitRuns);
}
float lineXOffset = this._getAndShiftByLineXOffset(runXOffset, lineCodeUnitRuns, lineGlyphPositions);
float lineXOffset = this.getLineXOffset(runXOffset);
this._shiftByLineXOffset(runXOffset, lineCodeUnitRuns, lineGlyphPositions);
this._computeLineOffset(lineNumber, lineGlyphPositions, lineCodeUnitRuns, paintRecords,
ref yOffset, ref preMaxDescent);
this._addPaintRecordsWithOffset(paintRecords, lineXOffset, yOffset);

for (int glyphIndex = 0; glyphIndex < textCount; ++glyphIndex) {
float glyphXOffset = layout.getX(glyphIndex) + justifyXOffset;
float glyphAdvance = layout.getCharAdvance(glyphIndex);
builder.positions[glyphIndex] = new Vector2d(glyphXOffset, layout.getY(glyphIndex));
builder.positions[glyphIndex] = new Vector2d(glyphXOffset);
glyphPositions.Add(new GlyphPosition(runXOffset + glyphXOffset, glyphAdvance,
new Range<int>(textStart + glyphIndex, textStart + glyphIndex + 1)));
if (wordIndex < words.Count && words[wordIndex].start == runStart + glyphIndex) {

lineNumber, TextDirection.ltr));
}
float _getAndShiftByLineXOffset(float runXOffset, List<CodeUnitRun> lineCodeUnitRuns, List<GlyphPosition> lineGlyphPositions) {
float lineXOffset = this.getLineXOffset(runXOffset);
void _shiftByLineXOffset(float lineXOffset, List<CodeUnitRun> lineCodeUnitRuns, List<GlyphPosition> lineGlyphPositions) {
codeUnitRun.Shift(lineXOffset);
codeUnitRun.shift(lineXOffset);
}
for (int i = 0; i < lineGlyphPositions.Count; ++i) {

return lineXOffset;
}
void _computeLineOffset(int lineNumber,

4
Runtime/ui/txt/text_buff.cs


public override string ToString() {
return this.text.Substring(this.offset, this.size);
}
public string subString(int shift, int size) {
return this.text.Substring(this.offset + shift, size);
}
}
}

2
Runtime/ui/txt/wordbreaker.cs


}
public static bool isBoundaryChar(char code) {
return char.IsPunctuation(code) || (code >= 0x4E00 && code <= 0x9FFF) || (code >= 0x3040 && code <= 0x30FF);
return (code >= 0x4E00 && code <= 0x9FFF) || (code >= 0x3040 && code <= 0x30FF) || char.IsPunctuation(code);
}
void nextUntilCodePoint() {

正在加载...
取消
保存