Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit a4ff74a

Browse files
authored
Merge pull request #349 from UnityTech/fix_emoji
Adjust emoji advance and size.
2 parents 482acf3 + fa42e6f commit a4ff74a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Diff for: Runtime/ui/txt/emoji.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,14 @@ public static Image image {
233233

234234
public const int rowCount = 36;
235235
public const int colCount = 37;
236+
public static float advanceFactor = 1.3f;
237+
public static float sizeFactor = 1.2f;
236238

237239
public static Rect getMinMaxRect(float fontSize, float ascent, float descent) {
238-
return Rect.fromLTWH(fontSize * 0.05f, descent - fontSize, fontSize * 0.9f, fontSize * 0.9f);
240+
return Rect.fromLTWH((advanceFactor - sizeFactor) / 2 * fontSize,
241+
descent - fontSize * sizeFactor,
242+
fontSize * sizeFactor,
243+
fontSize * sizeFactor);
239244
}
240245

241246
public static Rect getUVRect(int code) {

Diff for: Runtime/ui/txt/layout.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static float measureText(string text, TextStyle style) {
88
char startingChar = text[0];
99
float totalWidth = 0;
1010
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
11-
float advance = style.fontSize + style.letterSpacing;
11+
float advance = style.fontSize * EmojiUtils.advanceFactor + style.letterSpacing;
1212
for (int i = 0; i < text.Length; i++) {
1313
char ch = text[i];
1414
if (char.IsHighSurrogate(ch) || EmojiUtils.isSingleCharNonEmptyEmoji(ch)) {
@@ -42,7 +42,7 @@ public static int computeTruncateCount(float offset, string text, int start, int
4242
char startingChar = text[start];
4343
float currentAdvance = offset;
4444
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
45-
float advance = style.fontSize + style.letterSpacing;
45+
float advance = style.fontSize * EmojiUtils.advanceFactor + style.letterSpacing;
4646
for (int i = 0; i < count; i++) {
4747
char ch = text[start + i];
4848
if (char.IsHighSurrogate(ch) || EmojiUtils.isSingleCharNonEmptyEmoji(ch)) {
@@ -85,7 +85,7 @@ public static float computeCharWidths(float offset, string text, int start, int
8585
char startingChar = text[start];
8686
float totalWidths = 0;
8787
if (char.IsHighSurrogate(startingChar) || EmojiUtils.isSingleCharEmoji(startingChar)) {
88-
float advance = style.fontSize + style.letterSpacing;
88+
float advance = style.fontSize * EmojiUtils.advanceFactor + style.letterSpacing;
8989
for (int i = 0; i < count; i++) {
9090
char ch = text[start + i];
9191
if (char.IsHighSurrogate(ch) || EmojiUtils.isSingleCharNonEmptyEmoji(ch)) {
@@ -224,16 +224,15 @@ static float _layoutEmoji(string text, int start, int count, TextStyle style, Fo
224224
x += letterSpaceHalfLeft;
225225
advances[i] = letterSpaceHalfLeft;
226226

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

234234
positions[i] = x;
235235

236-
float advance = style.fontSize;
237236
x += advance;
238237

239238
advances[i] += advance;

0 commit comments

Comments
 (0)