Skip to content

Commit 93d3cb5

Browse files
committed
[dehinter.font] conditionally clear head flags bit 4 only when LTSH and hdmx are not present
1 parent 0910d73 commit 93d3cb5

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

lib/dehinter/font.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,13 @@ def update_maxp_table(tt):
186186
# =========================================
187187
def update_head_table_flags(tt):
188188
if is_bit_k_set(tt["head"].flags, 4):
189-
new_flags = clear_bit_k(tt["head"].flags, 4)
190-
tt["head"].flags = new_flags
191-
return True
189+
# confirm that there is no LTSH or hdmx table
190+
# bit 4 should be set if either of these tables are present in font
191+
if has_hdmx_table(tt) or has_ltsh_table(tt):
192+
return False
193+
else:
194+
new_flags = clear_bit_k(tt["head"].flags, 4)
195+
tt["head"].flags = new_flags
196+
return True
192197
else:
193198
return False

tests/test_font.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,42 @@ def test_update_maxp_table():
249249
# =========================================
250250
# head table edits
251251
# =========================================
252-
def test_update_head_table_flags():
252+
def test_update_head_table_flags_without_ltsh_hdmx():
253253
tt = TTFont(FILEPATH_HINTED_TTF)
254254
assert (tt["head"].flags & (1 << 4)) != 0
255+
remove_hdmx_table(tt)
256+
remove_ltsh_table(tt)
255257
response = update_head_table_flags(tt)
256258
assert response is True
257259
assert (tt["head"].flags & (1 << 4)) == 0
258260

259261

262+
def test_update_head_table_flags_with_ltsh_hdmx():
263+
tt = TTFont(FILEPATH_HINTED_TTF)
264+
assert (tt["head"].flags & (1 << 4)) != 0
265+
response = update_head_table_flags(tt)
266+
assert response is False
267+
assert (tt["head"].flags & (1 << 4)) != 0
268+
269+
270+
def test_update_head_table_flags_with_ltsh():
271+
tt = TTFont(FILEPATH_HINTED_TTF)
272+
assert (tt["head"].flags & (1 << 4)) != 0
273+
remove_hdmx_table(tt)
274+
response = update_head_table_flags(tt)
275+
assert response is False
276+
assert (tt["head"].flags & (1 << 4)) != 0
277+
278+
279+
def test_update_head_table_flags_with_hdmx():
280+
tt = TTFont(FILEPATH_HINTED_TTF)
281+
assert (tt["head"].flags & (1 << 4)) != 0
282+
remove_ltsh_table(tt)
283+
response = update_head_table_flags(tt)
284+
assert response is False
285+
assert (tt["head"].flags & (1 << 4)) != 0
286+
287+
260288
def test_update_head_table_flags_previously_cleared():
261289
tt = TTFont(FILEPATH_HINTED_TTF_2)
262290
assert (tt["head"].flags & (1 << 4)) == 0

0 commit comments

Comments
 (0)