From 9b1d3c826c8acce04390051d5fd773934a33ce10 Mon Sep 17 00:00:00 2001 From: Dmitry Rodionov Date: Thu, 29 Feb 2024 18:25:53 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=A8=E2=80=8D=F0=9F=91=A8=E2=80=8D?= =?UTF-8?q?=F0=9F=91=A7=E2=80=8D=F0=9F=91=A7=20Fix=20emoji=20detection=20w?= =?UTF-8?q?hen=20building=20text=20layer=20attributes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of a special fill style override for emojis there's now a glyph-level "emojiCodePoints" field we can use to detect them Signed-off-by: Dmitry Rodionov --- src/converter/text.py | 8 +++++--- tests/converter/test_text.py | 9 ++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/converter/text.py b/src/converter/text.py index 00a3ed7..6a38498 100644 --- a/src/converter/text.py +++ b/src/converter/text.py @@ -198,9 +198,11 @@ def override_characters_style(fig_text): # Compute the override for this character. Aside from style override, # we have to set the emoji font if this is an emoji style_override = copy.deepcopy(override_table[style_id]) - override_fills = override_table[current_glyph["styleID"]].get("fillPaints", [{}]) - - is_emoji = override_fills and override_fills[0].get("type") == "EMOJI" + if "styleID" in current_glyph: + override_fills = override_table[current_glyph["styleID"]].get("fillPaints", [{}]) + is_emoji = override_fills and override_fills[0].get("type") == "EMOJI" + else: + is_emoji = "emojiCodePoints" in current_glyph if is_emoji: style_override["fontName"] = { diff --git a/tests/converter/test_text.py b/tests/converter/test_text.py index 6578ed7..91c7b78 100644 --- a/tests/converter/test_text.py +++ b/tests/converter/test_text.py @@ -22,7 +22,6 @@ def build_emoji_text(chars: str, glyphs: List): "textData": { "characters": chars, "glyphs": glyphs, - "styleOverrideTable": [{"styleID": 2, "fillPaints": [{"type": "EMOJI"}]}], }, } @@ -86,8 +85,8 @@ def test_multi_color_text(self): def test_emoji_text(self): chars = "Sketch ❤️ you" - glyphs = [{"firstCharacter": i, "styleID": 0} for i in range(len(chars))] - glyphs[7]["styleID"] = 2 + glyphs = [{"firstCharacter": i} for i in range(len(chars))] + glyphs[7]["emojiCodePoints"] = [10084, 65039] text = override_characters_style(build_emoji_text(chars, glyphs)) @@ -113,9 +112,9 @@ def test_emoji_text(self): def test_multi_code_point_text(self): chars = "nice 🏳️‍🌈 flag" - glyphs = [{"firstCharacter": i, "styleID": 0} for i in range(len(chars))] + glyphs = [{"firstCharacter": i} for i in range(len(chars))] # Multi-codepoint flag is a single glyph - glyphs[5]["styleID"] = 2 + glyphs[5]["emojiCodePoints"] = [127987, 65039, 8205, 127752] glyphs.pop(6) glyphs.pop(6) glyphs.pop(6)