浏览代码

Resize the emoji.

/main
Yuncong Zhang 5 年前
当前提交
804002c9
共有 4 个文件被更改,包括 37 次插入17 次删除
  1. 21
      Runtime/ui/painting/txt/mesh_generator.cs
  2. 6
      Runtime/ui/txt/emoji.cs
  3. 15
      Runtime/ui/txt/layout.cs
  4. 12
      Tests/Editor/Paragraph.cs

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


var text = this.textBlob.text;
var key = new MeshKey(this.textBlob.instanceId, this.scale);
var fontInfo = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle);
var font = fontInfo.font;
if (char.IsHighSurrogate(text[this.textBlob.textOffset])) {
D.assert(this.textBlob.textSize == 2);

var pos = this.textBlob.positions[0];
var metrics = FontMetrics.fromFont(font, style.UnityFontSize);
var minMaxRect = EmojiUtils.getMinMaxRect(style.fontSize, metrics.ascent, metrics.descent);
var minX = minMaxRect.left;
var maxX = minMaxRect.right;
var minY = minMaxRect.top;
var maxY = minMaxRect.bottom;
new Vector3(pos.x, pos.y - style.fontSize, 0),
new Vector3(pos.x + style.fontSize, pos.y - style.fontSize, 0),
new Vector3(pos.x + style.fontSize, pos.y, 0),
new Vector3(pos.x, pos.y, 0),
new Vector3(pos.x + minX, pos.y + minY, 0),
new Vector3(pos.x + maxX, pos.y + minY, 0),
new Vector3(pos.x + maxX, pos.y + maxY, 0),
new Vector3(pos.x + minX, pos.y + maxY, 0),
};
var tri = new List<int> {
0, 1, 2, 0, 2, 3,

return this._mesh;
}
var fontInfo = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle);
_meshes.TryGetValue(key, out var meshInfo);
if (meshInfo != null && meshInfo.textureVersion == fontInfo.textureVersion) {

}
var font = fontInfo.font;
var length = this.textBlob.textSize;
var fontSizeToLoad = Mathf.CeilToInt(style.UnityFontSize * this.scale);

6
Runtime/ui/txt/emoji.cs


Resources.Load<Texture2D>("Emoji")
);
}
catch (Exception e) {
catch (Exception) {
_image = null;
}
}

public const int rowCount = 4;
public const int colCount = 4;
public static Rect getMinMaxRect(float fontSize, float ascent, float descent) {
return Rect.fromLTWH(fontSize * 0.05f, descent - fontSize, fontSize * 0.9f, fontSize * 0.9f);
}
public static Rect getUVRect(int code) {
bool exist = emojiLookupTable.TryGetValue(code, out int index);

15
Runtime/ui/txt/layout.cs


this._advance = 0;
this._bounds = default;
Font font;
Font font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
this.layoutEmoji(style);
this.layoutEmoji(style, font);
font = FontManager.instance.getOrCreate(style.fontFamily, style.fontWeight, style.fontStyle).font;
font.RequestCharactersInTextureSafe(buff.text, style.UnityFontSize, style.UnityFontStyle);
int wordstart = start == buff.size

this._advance = x;
}
void layoutEmoji(TextStyle style) {
void layoutEmoji(TextStyle style, Font font) {
float x = this._advance;
float letterSpace = style.letterSpacing;
float letterSpaceHalfLeft = letterSpace * 0.5f;

this._advances[0] += letterSpaceHalfLeft;
var metrics = FontMetrics.fromFont(font, style.UnityFontSize);
var maxX = style.fontSize + x;
var minY = -style.fontSize;
var maxY = 0;
var maxX = metrics.descent - metrics.ascent + x;
var minY = metrics.ascent;
var maxY = metrics.descent;
if (this._bounds.width <= 0 || this._bounds.height <= 0) {
this._bounds = UnityEngine.Rect.MinMaxRect(

12
Tests/Editor/Paragraph.cs


new TextSpan(style: new TextStyle(fontSize: 24),
text: "Emoji \ud83d\ude0a\ud83d\ude0b\ud83d\ude0d\ud83d\ude0e\ud83d\ude00"),
new TextSpan(style: new TextStyle(fontSize: 14),
text: "Emoji \ud83d\ude0a\ud83d\ude0b\ud83d\ude0d\ud83d\ude0e\ud83d\ude00"),
text: "Emoji \ud83d\ude0a\ud83d\ude0b\ud83d\ude0d\ud83d\ude0e\ud83d\ude00 Emoji"),
text: "\ud83d\ude01\ud83d\ude02\ud83d\ude03\ud83d\ude04\ud83d\ude05"),
text: "Emoji \ud83d\ude01\ud83d\ude02\ud83d\ude03\ud83d\ude04\ud83d\ude05"),
new TextSpan(style: new TextStyle(fontSize: 18),
text: "Emoji \ud83d\ude01\ud83d\ude02\ud83d\ude03\ud83d\ude04\ud83d\ude05 Emoji Emoji"),
new TextSpan(style: new TextStyle(fontSize: 18),
text: "Emoji \ud83d\ude01\ud83d\ude02\ud83d\ude03\ud83d\ude04\ud83d\ude05 Emoji Emoji Emoji"),
new TextSpan(style: new TextStyle(fontSize: 18),
text: "Emoji \ud83d\ude01\ud83d\ude02\ud83d\ude03\ud83d\ude04\ud83d\ude05"),
text: "\ud83d\ude06\ud83d\ude1C\ud83d\ude18\ud83d\ude2D\ud83d\ude0C\ud83d\ude1E"),
text: "Emoji \ud83d\ude06\ud83d\ude1C\ud83d\ude18\ud83d\ude2D\ud83d\ude0C\ud83d\ude1EEmoji"),
new TextSpan(style: new TextStyle(fontSize: 14),
text: "FontSize 14"),
})));

正在加载...
取消
保存