浏览代码

add assertion on get charactor info

/main
fzhangtj 6 年前
当前提交
2b4449e6
共有 4 个文件被更改,包括 23 次插入15 次删除
  1. 25
      Runtime/ui/painting/txt/font_manager.cs
  2. 4
      Runtime/ui/painting/txt/mesh_generator.cs
  3. 3
      Runtime/ui/txt/layout.cs
  4. 6
      Runtime/ui/txt/linebreaker.cs

25
Runtime/ui/painting/txt/font_manager.cs


public void addFont(Font font) {
D.assert(font != null);
D.assert(font.dynamic, $"adding font which is not dynamic is not allowed {font.name}");
FontInfo current;
this._fonts.TryGetValue(font.name, out current);
D.assert(current == null || current.font == font, $"font with name {font.name} already exists");
foreach (var fontName in font.fontNames) {
this._fonts[fontName] = fontInfo;
}
this._fonts[font.name] = fontInfo;
}
internal FontInfo getOrCreate(string name) {

osFont.material.mainTexture.hideFlags = HideFlags.DontSave;
var newFont = new FontInfo(osFont);
foreach (var fontName in osFont.fontNames) {
this._fonts[fontName] = newFont;
}
this._fonts[osFont.name] = newFont;
return newFont;
}

entry.onTextureRebuilt();
}
}
}
public static class FontExtension
{
public static CharacterInfo MustGetCharacterInfo(this Font font, char ch, int fontSize, UnityEngine.FontStyle fontStyle)
{
CharacterInfo info;
bool success = font.GetCharacterInfo(ch, out info, fontSize, fontStyle);
D.assert(success, $"fail to get character info for character '{ch}' (code{(int)ch}) from font: ${font.name}");
return info;
}
}
}

4
Runtime/ui/painting/txt/mesh_generator.cs


continue;
}
CharacterInfo charInfo;
font.GetCharacterInfo(ch, out charInfo, fontSizeToLoad, style.UnityFontStyle);
CharacterInfo charInfo = font.MustGetCharacterInfo(ch, fontSizeToLoad, style.UnityFontStyle);
var minX = charInfo.minX / this._scale;
var maxX = charInfo.maxX / this._scale;
var minY = charInfo.minY / this._scale;

3
Runtime/ui/txt/layout.cs


for (int i = 0; i < count; i++) {
int charIndex = start + i;
var ch = text[charIndex];
CharacterInfo characterInfo;
font.GetCharacterInfo(ch, out characterInfo, style.UnityFontSize, style.UnityFontStyle);
CharacterInfo characterInfo = font.MustGetCharacterInfo(ch, style.UnityFontSize, style.UnityFontStyle);
var rect = Rect.fromLTRB(characterInfo.minX, -characterInfo.maxY, characterInfo.maxX,
-characterInfo.minY);

6
Runtime/ui/txt/linebreaker.cs


using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

if (this._tabWidth == int.MaxValue) {
this._font.RequestCharactersInTexture(" ", this._fontSize);
CharacterInfo characterInfo;
this._font.GetCharacterInfo(' ', out characterInfo, this._fontSize);
CharacterInfo characterInfo = this._font.MustGetCharacterInfo(' ', this._fontSize, UnityEngine.FontStyle.Normal);
this._tabWidth = characterInfo.advance * kTabSpaceCount;
}

正在加载...
取消
保存