Emoji sequences: EnableLigatures writes liga into every serialized TMP text and TMP Settings; EmojiCheck renders every fully-qualified sequence as one visible character

Adds tools/emoji/emoji-sequences.txt (2760 fully-qualified multi-code-point sequences from the pinned emoji-test.txt), written by fetch_emoji_font.py and recorded in the lock. Not compiled yet (first Unity pass follows); the asset changes land in a later commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-12 04:22:40 +02:00
commit bd78401967
5 changed files with 2928 additions and 3 deletions

View file

@ -7,6 +7,7 @@ emoji_test_sha256=1d8a944f88d7952f7ef7c5167fef3c67995bcae24543949710231b03a201ac
svg_count=4009
single_codepoint_count=1400
unsupported_count=0
sequence_count=2760
tool_nanoemoji=0.16.0
tool_fonttools=4.66.1
tool_picosvg=0.23.0
@ -20,3 +21,4 @@ font_file=Twemoji.ttf
font_sha256=de66290bfa98226e40d8999a3ab024c2242e8d2938f939d9a85c1494844f6aa0
singles_sha256=7ad887a16ef5386df040e1e8988e9bdc55ae5cab461ffc9df4613d0cb5770b4e
unsupported_sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
sequences_sha256=18529154b14f75f54db5dedd72910de35af9ca05aef284b7d121be249b3c3bb2

View file

@ -14,6 +14,10 @@ using UnityEngine;
// Run as -executeMethod EmojiCheck.Run (exit 1 on failure in batchmode, as EngineAssetCheck). Corpus:
// tools/emoji/emoji-singles.txt (from emoji-test.txt); the emoji Twemoji lacks are listed in
// tools/emoji/emoji-unsupported.txt and reported, not rendered; -emojiLimit N spreads N entries evenly for a spike.
// Every fully-qualified multi-code-point sequence (tools/emoji/emoji-sequences.txt: ZWJ, skin tone, flag, keycap,
// tag) must also render as exactly one visible character, which needs `liga` on the rendering component: every
// TMP text in every prefab and scene must have it, and so must one added at runtime (as ActionGameManager's
// FACE AIM mark is), or a family or flag would show as its pieces.
public static class EmojiCheck
{
const string BodyFontPath = "Assets/Fonts/Ubuntu/Ubuntu-L Small SDF.asset";
@ -49,6 +53,7 @@ public static class EmojiCheck
var unsupported = new HashSet<int>(LoadCodePoints("emoji-unsupported.txt"));
var corpus = LoadSingles().Where(cp => !unsupported.Contains(cp)).ToList();
var sequences = LoadSequences();
var missing = new HashSet<int>();
TMP_Text.MissingCharacterEventCallback onMissing = (unicode, index, source, asset, component) => missing.Add(unicode);
TMP_Text.OnMissingCharacter += onMissing;
@ -60,7 +65,7 @@ public static class EmojiCheck
text.textWrappingMode = TextWrappingModes.NoWrap;
text.rectTransform.sizeDelta = new Vector2(100000, 100000);
int viaEmoji = 0, viaBody = 0, blank = 0, pirateNames = 0;
int viaEmoji = 0, viaBody = 0, blank = 0, pirateNames = 0, notOne = 0, runtimeLiga = 0;
var strays = new HashSet<string>();
try
{
@ -90,6 +95,35 @@ public static class EmojiCheck
Render(string.Join(" ", slice.Select(char.ConvertFromUtf32)), $"chunk {i}");
}
// A text created at runtime inherits liga from TMP Settings, with no wiring of its own.
var runtime = new GameObject("Runtime", typeof(RectTransform));
runtime.transform.SetParent(canvas.transform, false);
runtimeLiga = runtime.AddComponent<TextMeshProUGUI>().fontFeatures
.Contains(UnityEngine.TextCore.LowLevel.OTL_FeatureTag.liga) ? 1 : 0;
if (runtimeLiga == 0) failures.Add("a TextMeshProUGUI added at runtime does not have liga: TMP Settings' features are not inherited");
// Sequences: space-separated groups, each of which must end as one visible character.
for (var i = 0; i < sequences.Count; i += Chunk)
{
var slice = sequences.Skip(i).Take(Chunk).ToList();
text.text = string.Join(" ", slice.Select(ToText));
text.ForceMeshUpdate();
var visible = new List<int> { 0 };
for (var c = 0; c < text.textInfo.characterCount; c++)
{
var info = text.textInfo.characterInfo[c];
if (info.character == ' ') visible.Add(0);
else if (info.isVisible) visible[visible.Count - 1]++;
}
if (visible.Count != slice.Count) failures.Add($"sequence chunk {i}: {visible.Count} groups rendered for {slice.Count} sequences");
for (var g = 0; g < Math.Min(visible.Count, slice.Count); g++)
if (visible[g] != 1)
{
notOne++;
failures.Add($"sequence {slice[g]} rendered {visible[g]} visible characters, not one");
}
}
// The Pirates names as the shipped catalog stores them, through the game's own catalog reader.
var catalogPath = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "GameData", "Aetheria.cc");
using (var catalog = AetheriaStores.Open(catalogPath))
@ -116,6 +150,19 @@ public static class EmojiCheck
foreach (var cp in missing.OrderBy(c => c)) failures.Add($"missing code point U+{cp:X4}");
// Every serialized TMP text has liga (an instance inherits it from its prefab, so this reads the effective value).
int texts = 0, withoutLiga = 0;
EmojiFont.VisitSerializedTexts(component =>
{
texts++;
if (!component.fontFeatures.Contains(UnityEngine.TextCore.LowLevel.OTL_FeatureTag.liga))
{
withoutLiga++;
failures.Add($"TMP text {component.name} has no liga: {GetPath(component)}");
}
return false;
});
// TMP over-allocates atlasTextures by doubling its capacity when a page is added, so entries past
// atlasTextureCount are null by design (3 pages in a 4-slot array). Only the used pages count.
long ink = 0, colour = 0;
@ -136,11 +183,21 @@ public static class EmojiCheck
if (unsupported.Count > 0)
Debug.LogWarning($"EmojiCheck: Twemoji lacks {unsupported.Count} single-code-point emoji of the Emoji version: " +
string.Join(" ", unsupported.OrderBy(c => c).Select(c => $"U+{c:X4}")));
return $"checked {corpus.Count} single code points ({unsupported.Count} not drawn by Twemoji, listed in the warning) + {pirateNames} Pirates product names, " +
return $"{sequences.Count} sequences ({notOne} not one visible character), {texts} serialized TMP texts ({withoutLiga} without liga), runtime text liga {runtimeLiga}; " +
$"checked {corpus.Count} single code points ({unsupported.Count} not drawn by Twemoji, listed in the warning) + {pirateNames} Pirates product names, " +
$"{missing.Count} missing, {viaEmoji} glyphs via the emoji asset, {viaBody} via the body font, {strays.Count} via other fonts, {blank} blank, " +
$"{ink} atlas ink pixels of which {colour} coloured, {pages} atlas pages";
}
static string GetPath(Component component) =>
component.gameObject.scene.IsValid() ? component.gameObject.scene.path : AssetDatabase.GetAssetPath(component);
static string ToText(string sequence) => string.Concat(sequence.Split(' ').Select(cp => char.ConvertFromUtf32(Convert.ToInt32(cp, 16))));
static List<string> LoadSequences() =>
File.ReadAllLines(Path.Combine(Directory.GetParent(Application.dataPath).FullName, "tools", "emoji", "emoji-sequences.txt"))
.Where(l => l.Length > 0).ToList();
static List<int> LoadSingles()
{
var all = LoadCodePoints("emoji-singles.txt");

View file

@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.TextCore.LowLevel;
@ -10,6 +13,9 @@ using UnityEngine.TextCore.LowLevel;
// route, TMP Settings' global fallback list; the emoji fallback list stays empty, and no component names
// an emoji font. (Measured: the global list alone resolves every single code point; the emoji list alone
// leaves 200 text-presentation emoji unresolved. A second route could only disagree with the first.)
// Sequences (ZWJ, skin tone, flag, keycap) resolve only through the emoji font's GSUB ligatures, and TMP applies
// them per component, gated by that component's font features: EnableLigatures writes `liga` into every
// serialized TMP text and into TMP Settings (so a text created later inherits it); there is no global switch.
public static class EmojiFont
{
public const string FontPath = "Assets/Fonts/Emoji/Twemoji.ttf";
@ -74,4 +80,85 @@ public static class EmojiFont
message = "EmojiFont: built " + AssetPath + " and made it TMP Settings' only emoji route (the global fallback).";
return true;
}
// Menu entry for interactive use; -executeMethod EmojiFont.EnableLigatures for batchmode, exit 1 on failure.
// Idempotent: a second run changes nothing and saves nothing.
[MenuItem("Aetheria/Text/Enable Ligatures")]
public static void EnableLigatures()
{
try
{
var settings = TMP_Settings.fontFeatures;
var settingsChanged = Enable(settings);
if (settingsChanged) EditorUtility.SetDirty(TMP_Settings.instance);
var (files, components) = VisitSerializedTexts(text =>
{
var features = text.fontFeatures.ToList();
if (!Enable(features, text.enableKerning)) return false;
text.fontFeatures = features;
EditorUtility.SetDirty(text);
return true;
});
AssetDatabase.SaveAssets();
Debug.Log($"EmojiFont: liga added to {components} TMP component(s) in {files} file(s)" +
(settingsChanged ? " and to TMP Settings." : "; TMP Settings already had it."));
if (Application.isBatchMode) EditorApplication.Exit(0);
}
catch (Exception e)
{
Debug.LogError("EmojiFont.EnableLigatures failed: " + e);
if (Application.isBatchMode) EditorApplication.Exit(1);
}
}
// A legacy list ([0], no feature serialized) is first converted to [kern] when kerning is on, as TMP does on load.
static bool Enable(List<OTL_FeatureTag> features, bool kerning = true)
{
if (features.Contains(OTL_FeatureTag.liga)) return false;
features.RemoveAll(tag => tag == 0);
if (kerning && !features.Contains(OTL_FeatureTag.kern)) features.Add(OTL_FeatureTag.kern);
features.Add(OTL_FeatureTag.liga);
return true;
}
// The one walk over every TMP text a serialized asset owns: each prefab and each scene under Assets/, skipping a
// component that belongs to a prefab instance unless that instance overrides its font features (otherwise it
// inherits from its source prefab, which is walked itself). `visit` returns whether it changed the component;
// an asset that changed is saved. Returns the files and components changed.
public static (int files, int components) VisitSerializedTexts(Func<TMP_Text, bool> visit)
{
int files = 0, components = 0;
bool Owns(TMP_Text text) =>
!PrefabUtility.IsPartOfPrefabInstance(text) ||
new SerializedObject(text).FindProperty("m_ActiveFontFeatures")?.prefabOverride == true;
int Visit(IEnumerable<TMP_Text> texts) => texts.Where(Owns).Count(visit);
foreach (var path in AssetDatabase.FindAssets("t:Prefab", new[] { "Assets" }).Select(AssetDatabase.GUIDToAssetPath))
{
var root = PrefabUtility.LoadPrefabContents(path);
try
{
var changed = Visit(root.GetComponentsInChildren<TMP_Text>(true));
if (changed == 0) continue;
PrefabUtility.SaveAsPrefabAsset(root, path);
files++;
components += changed;
}
finally { PrefabUtility.UnloadPrefabContents(root); }
}
foreach (var path in AssetDatabase.FindAssets("t:Scene", new[] { "Assets" }).Select(AssetDatabase.GUIDToAssetPath))
{
var scene = EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
try
{
var changed = Visit(scene.GetRootGameObjects().SelectMany(root => root.GetComponentsInChildren<TMP_Text>(true)));
if (changed == 0) continue;
EditorSceneManager.SaveScene(scene);
files++;
components += changed;
}
finally { EditorSceneManager.CloseScene(scene, true); }
}
return (files, components);
}
}

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@ Run it on Yggdrasil (or any docker host) from the repository root:
Downloads the jdecked/twemoji release source archive and Unicode's emoji-test.txt (both sha256 pinned
below), runs nanoemoji (glyf_colr_0) over the SVGs, and writes the font, the licence text, the smoke's
corpus (emoji-singles.txt, from emoji-test.txt), the list of emoji Twemoji lacks (emoji-unsupported.txt)
corpus (emoji-singles.txt and emoji-sequences.txt, from emoji-test.txt), the list of emoji Twemoji lacks (emoji-unsupported.txt)
and emoji-font.lock. The font is the only artifact Unity consumes; nothing here is hand-made art.
A run whose font-determining pins match the lock must reproduce the font's sha256, or the script exits 1
and leaves the committed font and lock untouched; the lock never follows the machine.
@ -36,6 +36,7 @@ PINNED_IMAGE = "python:3.13-slim"
ROOT = Path(__file__).resolve().parents[2]
FONT_DIR = ROOT / "Assets" / "Fonts" / "Emoji"
SINGLES = ROOT / "tools" / "emoji" / "emoji-singles.txt"
SEQUENCES = ROOT / "tools" / "emoji" / "emoji-sequences.txt"
UNSUPPORTED = ROOT / "tools" / "emoji" / "emoji-unsupported.txt"
@ -72,6 +73,20 @@ def single_code_points(emoji_test):
return sorted(found)
def fully_qualified_sequences(emoji_test):
"""Every fully-qualified emoji of more than one code point (ZWJ, skin tone, flag, keycap, tag, and a
base with its FE0F), each as its space-separated hex code points in file order. The smoke renders each
as one visible character."""
found = []
for line in emoji_test.read_text(encoding="utf-8").splitlines():
if not line or line.startswith("#"):
continue
points, status = (part.strip() for part in line.split("#", 1)[0].split(";", 1))
if status == "fully-qualified" and len(points.split()) > 1:
found.append(points)
return found
def refuse_unless_pinned_environment():
here = (sys.platform, f"{sys.version_info.major}.{sys.version_info.minor}", os.environ.get("EMOJI_FONT_IMAGE"))
if here != (PINNED_PLATFORM, PINNED_PYTHON, PINNED_IMAGE):
@ -148,12 +163,14 @@ def main():
drawn = {int(p.stem, 16) for p in svgs if re.fullmatch(r"[0-9a-f]+", p.stem)}
singles = single_code_points(emoji_test)
unsupported = [cp for cp in singles if cp not in drawn]
sequences = fully_qualified_sequences(emoji_test)
FONT_DIR.mkdir(parents=True, exist_ok=True)
out = FONT_DIR / f"{FAMILY}.ttf"
shutil.copyfile(built, out)
(FONT_DIR / "LICENSE.txt").write_text(licence_text(src), encoding="utf-8", newline="\n")
SINGLES.write_text("".join(f"{cp:X}\n" for cp in singles), encoding="utf-8", newline="\n")
SEQUENCES.write_text("".join(f"{points}\n" for points in sequences), encoding="utf-8", newline="\n")
UNSUPPORTED.write_text("".join(f"{cp:X}\n" for cp in unsupported), encoding="utf-8", newline="\n")
print(f"Twemoji lacks {len(unsupported)} of {len(singles)} single-code-point emoji: "
+ " ".join(f"U+{cp:04X}" for cp in unsupported))
@ -162,11 +179,13 @@ def main():
f"source_url={TWEMOJI_URL}", f"source_version={TWEMOJI_VERSION}", f"source_sha256={TWEMOJI_SHA256}",
f"emoji_test_version={EMOJI_TEST_VERSION}", f"emoji_test_url={EMOJI_TEST_URL}", f"emoji_test_sha256={EMOJI_TEST_SHA256}",
f"svg_count={len(svgs)}", f"single_codepoint_count={len(singles)}", f"unsupported_count={len(unsupported)}",
f"sequence_count={len(sequences)}",
*(f"tool_{n}={v}" for n, v in tools.items()),
f"source_date_epoch={SOURCE_DATE_EPOCH}", "color_format=glyf_colr_0",
f"python_version={font_pins['python_version']}", f"platform={PINNED_PLATFORM}", f"container_image={PINNED_IMAGE}",
f"font_file={out.name}", f"font_sha256={font_sha}",
f"singles_sha256={sha256(SINGLES)}", f"unsupported_sha256={sha256(UNSUPPORTED)}",
f"sequences_sha256={sha256(SEQUENCES)}",
]
lock_path.write_text("\n".join(lock) + "\n", encoding="utf-8", newline="\n")
print("\n".join(lock))