浏览代码

Optimize layout: request character only at begining.

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

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') {

11
Runtime/ui/txt/paragraph.cs


return nextLineStart - lineStart;
}
internal void setText(string text, StyledRuns runs) {
internal void setText(string text, StyledRuns runs, bool skipRequestCharacters = false) {
if (!skipRequestCharacters) {
for (int i = 0; i < runs.size; i++) {
var style = runs.getStyle(i);
var run = runs.getRun(i);
var font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
font.RequestCharactersInTextureSafe(text.Substring(run.start, run.end - run.start),
Mathf.CeilToInt(style.fontSize), style.UnityFontStyle);
}
}
}
public void setParagraphStyle(ParagraphStyle style) {

正在加载...
取消
保存