Skip to content

Commit

Permalink
πŸ‘¨β€πŸ‘¨β€πŸ‘§β€πŸ‘§ Fix emoji detection when building text layer attributes
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rodionovd committed Feb 29, 2024
1 parent b5d682a commit 9b1d3c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/converter/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = {
Expand Down
9 changes: 4 additions & 5 deletions tests/converter/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def build_emoji_text(chars: str, glyphs: List):
"textData": {
"characters": chars,
"glyphs": glyphs,
"styleOverrideTable": [{"styleID": 2, "fillPaints": [{"type": "EMOJI"}]}],
},
}

Expand Down Expand Up @@ -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))

Expand All @@ -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)
Expand Down

0 comments on commit 9b1d3c8

Please sign in to comment.