Skip to content

Commit e747668

Browse files
authored
⌨️ Fix an error that prevents any text layers from being imported (#105)
* 🌁 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]>
1 parent 5db48bf commit e747668

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/converter/text.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ def override_characters_style(fig_text):
198198
# Compute the override for this character. Aside from style override,
199199
# we have to set the emoji font if this is an emoji
200200
style_override = copy.deepcopy(override_table[style_id])
201-
override_fills = override_table[current_glyph["styleID"]].get("fillPaints", [{}])
202201

203-
is_emoji = override_fills and override_fills[0].get("type") == "EMOJI"
202+
is_emoji = "emojiCodePoints" in current_glyph
204203

205204
if is_emoji:
206205
style_override["fontName"] = {

tests/converter/test_text.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def build_emoji_text(chars: str, glyphs: List):
2222
"textData": {
2323
"characters": chars,
2424
"glyphs": glyphs,
25-
"styleOverrideTable": [{"styleID": 2, "fillPaints": [{"type": "EMOJI"}]}],
2625
},
2726
}
2827

@@ -86,8 +85,8 @@ def test_multi_color_text(self):
8685

8786
def test_emoji_text(self):
8887
chars = "Sketch ❤️ you"
89-
glyphs = [{"firstCharacter": i, "styleID": 0} for i in range(len(chars))]
90-
glyphs[7]["styleID"] = 2
88+
glyphs = [{"firstCharacter": i} for i in range(len(chars))]
89+
glyphs[7]["emojiCodePoints"] = [10084, 65039]
9190

9291
text = override_characters_style(build_emoji_text(chars, glyphs))
9392

@@ -113,9 +112,9 @@ def test_emoji_text(self):
113112

114113
def test_multi_code_point_text(self):
115114
chars = "nice 🏳️‍🌈 flag"
116-
glyphs = [{"firstCharacter": i, "styleID": 0} for i in range(len(chars))]
115+
glyphs = [{"firstCharacter": i} for i in range(len(chars))]
117116
# Multi-codepoint flag is a single glyph
118-
glyphs[5]["styleID"] = 2
117+
glyphs[5]["emojiCodePoints"] = [127987, 65039, 8205, 127752]
119118
glyphs.pop(6)
120119
glyphs.pop(6)
121120
glyphs.pop(6)

tests/data/structure.fig

4.17 KB
Binary file not shown.

0 commit comments

Comments
 (0)