Skip to content

Commit

Permalink
⌨️ Fix an error that prevents any text layers from being imported (#105)
Browse files Browse the repository at this point in the history
* 🌁 Update tests/data/structure.fig to the latest file format version

Signed-off-by: Dmitry Rodionov <[email protected]>

* 👨‍👨‍👧‍👧 Fix emoji detection when building text layer attributes

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]>

---------

Signed-off-by: Dmitry Rodionov <[email protected]>
  • Loading branch information
rodionovd authored Mar 1, 2024
1 parent 5db48bf commit e747668
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/converter/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ 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"
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
Binary file modified tests/data/structure.fig
Binary file not shown.

0 comments on commit e747668

Please sign in to comment.