浏览代码

Revert all optimization on paragraph layout.

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

6
Runtime/painting/text_painter.cs


using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;

var builder = new ParagraphBuilder(this._createParagraphStyle());
this._text.build(builder, this.textScaleFactor);
this._paragraph = builder.build();
}
else {
Debug.Log($"Use Old Paragraph [{DateTime.Now.Millisecond}]");
}
this._lastMinWidth = minWidth;

4
Runtime/ui/txt/layout.cs


}
else {
Font font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
// font.RequestCharactersInTextureSafe(text, style.UnityFontSize, style.UnityFontStyle);
font.RequestCharactersInTextureSafe(text, style.UnityFontSize, style.UnityFontStyle);
for (int i = 0; i < text.Length; i++) {
char ch = text[i];
if (font.getGlyphInfo(ch, out var glyphInfo, style.UnityFontSize, style.UnityFontStyle)) {

else {
Font font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
// TODO: it is kind of a waste to require the entire string for this style, but SubString causes alloc
// font.RequestCharactersInTextureSafe(text, style.UnityFontSize, style.UnityFontStyle);
font.RequestCharactersInTextureSafe(text, style.UnityFontSize, style.UnityFontStyle);
for (int i = 0; i < count; i++) {
char ch = text[start + i];
if (ch == '\t') {

25
Runtime/ui/txt/paragraph.cs


int textCount = textEnd - textStart;
// Keep track of the pointer to _glyphPositions in the start of this run
int glyphPositionStyleRunStart = pGlyphPositions;
Font font = FontManager.instance.getOrCreate(
style.fontFamily,
style.fontWeight,
style.fontStyle).font;
// Ellipsize the text if ellipsis string is set, and this is the last lineStyleRun of
// the current line, and this is the last line or max line is not set

font.RequestCharactersInTextureSafe(ellipsis, style.UnityFontSize, style.UnityFontStyle);
float ellipsisWidth = Layout.measureText(ellipsis, style);
// Find the minimum number of characters to truncate, so that the truncated text

}
// Create paint record
var font = FontManager.instance.getOrCreate(style.fontFamily,
style.fontWeight, style.fontStyle).font;
var metrics = FontMetrics.fromFont(font, style.UnityFontSize);
PaintRecord paintRecord = new PaintRecord(style, runXOffset, 0, builder.make(),
metrics, advance);

return nextLineStart - lineStart;
}
internal void setText(string text, StyledRuns runs, bool skipRequestCharacters = false) {
if (text == null || text.isEmpty()) {
this.clear();
this._text = text;
this._runs = runs;
this._needsLayout = false;
return;
}
internal void setText(string text, StyledRuns runs) {
if (!skipRequestCharacters) {
for (int i = 0; i < runs.size; i++) {
var run = runs.getRun(i);
var style = run.style;
var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
font.RequestCharactersInTextureSafe(text.Substring(run.start, run.end - run.start),
style.UnityFontSize, style.UnityFontStyle);
}
}
}
public void setParagraphStyle(ParagraphStyle style) {

正在加载...
取消
保存