Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Runtime/ui/txt/emoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,14 @@ public static Image image {

public const int rowCount = 36;
public const int colCount = 37;
public static float advanceFactor = 1.3f;
public static float sizeFactor = 1.2f;

public static Rect getMinMaxRect(float fontSize, float ascent, float descent) {
return Rect.fromLTWH(fontSize * 0.05f, descent - fontSize, fontSize * 0.9f, fontSize * 0.9f);
return Rect.fromLTWH((advanceFactor - sizeFactor) / 2 * fontSize,
descent - fontSize * sizeFactor,
fontSize * sizeFactor,
fontSize * sizeFactor);
}

public static Rect getUVRect(int code) {
Expand Down
13 changes: 6 additions & 7 deletions Runtime/ui/txt/layout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static float measureText(string text, TextStyle style) {
char startingChar = text[0];
float totalWidth = 0;
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
float advance = style.fontSize + style.letterSpacing;
float advance = style.fontSize * EmojiUtils.advanceFactor + style.letterSpacing;
for (int i = 0; i < text.Length; i++) {
char ch = text[i];
if (char.IsHighSurrogate(ch) || EmojiUtils.isSingleCharNonEmptyEmoji(ch)) {
Expand Down Expand Up @@ -42,7 +42,7 @@ public static int computeTruncateCount(float offset, string text, int start, int
char startingChar = text[start];
float currentAdvance = offset;
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
float advance = style.fontSize + style.letterSpacing;
float advance = style.fontSize * EmojiUtils.advanceFactor + style.letterSpacing;
for (int i = 0; i < count; i++) {
char ch = text[start + i];
if (char.IsHighSurrogate(ch) || EmojiUtils.isSingleCharNonEmptyEmoji(ch)) {
Expand Down Expand Up @@ -85,7 +85,7 @@ public static float computeCharWidths(float offset, string text, int start, int
char startingChar = text[start];
float totalWidths = 0;
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
float advance = style.fontSize + style.letterSpacing;
float advance = style.fontSize * EmojiUtils.advanceFactor + style.letterSpacing;
for (int i = 0; i < count; i++) {
char ch = text[start + i];
if (char.IsHighSurrogate(ch) || EmojiUtils.isSingleCharNonEmptyEmoji(ch)) {
Expand Down Expand Up @@ -224,16 +224,15 @@ static float _layoutEmoji(string text, int start, int count, TextStyle style, Fo
x += letterSpaceHalfLeft;
advances[i] = letterSpaceHalfLeft;


float advance = style.fontSize * EmojiUtils.advanceFactor;
var minX = x;
var maxX = metrics.descent - metrics.ascent + x;
var minY = metrics.ascent;
var maxX = advance + x;
var minY = -style.fontSize * EmojiUtils.sizeFactor;
var maxY = metrics.descent;
_updateBounds(minX, maxX, minY, maxY, ref bounds);

positions[i] = x;

float advance = style.fontSize;
x += advance;

advances[i] += advance;
Expand Down