Skip to content

Commit cfd6927

Browse files
committed
font-patcher: Ignore PPEM for non ttf/otf fonts
[why] When the source font does not have a HEAD table (i.e. is not a ttf/otf font but for example a sfd) we can not copy the PPEM and flag values. The patcher crashes. [how] Just put the code into a try block. We could check the signature instead, but this would add more and complex code. Reported-by: Jakub Jirutka <[email protected]> Signed-off-by: Fini Jastrow <[email protected]>
1 parent 49eb3ef commit cfd6927

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

font-patcher

+22-14
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class TableHEADWriter:
9393
self.tab_offset = self.getlong()
9494
self.tab_length = self.getlong()
9595
if tab_name == b'head':
96-
break
96+
return
97+
raise Exception('No HEAD table found')
9798

9899
def goto(self, where):
99100
""" Go to a named location in the file or to the specified index """
@@ -239,19 +240,26 @@ class font_patcher:
239240
message = "\nGenerated: {} in '{}'".format(self.sourceFont.fullname, outfile)
240241

241242
# Adjust flags that can not be changed via fontforge
242-
source_font = TableHEADWriter(self.args.font)
243-
source_font.close()
244-
dest_font = TableHEADWriter(outfile)
245-
if source_font.flags & 0x08 == 0 and dest_font.flags & 0x08 != 0:
246-
print("Changing flags from 0x{:X} to 0x{:X}".format(dest_font.flags, dest_font.flags & ~0x08))
247-
dest_font.putshort(dest_font.flags & ~0x08, 'flags') # clear 'ppem_to_int'
248-
if source_font.lowppem != dest_font.lowppem:
249-
print("Changing lowestRecPPEM from {} to {}".format(dest_font.lowppem, source_font.lowppem))
250-
dest_font.putshort(source_font.lowppem, 'lowestRecPPEM')
251-
if dest_font.modified:
252-
dest_font.reset_table_checksum()
253-
dest_font.reset_full_checksum()
254-
dest_font.close()
243+
try:
244+
source_font = TableHEADWriter(self.args.font)
245+
dest_font = TableHEADWriter(outfile)
246+
if source_font.flags & 0x08 == 0 and dest_font.flags & 0x08 != 0:
247+
print("Changing flags from 0x{:X} to 0x{:X}".format(dest_font.flags, dest_font.flags & ~0x08))
248+
dest_font.putshort(dest_font.flags & ~0x08, 'flags') # clear 'ppem_to_int'
249+
if source_font.lowppem != dest_font.lowppem:
250+
print("Changing lowestRecPPEM from {} to {}".format(dest_font.lowppem, source_font.lowppem))
251+
dest_font.putshort(source_font.lowppem, 'lowestRecPPEM')
252+
if dest_font.modified:
253+
dest_font.reset_table_checksum()
254+
dest_font.reset_full_checksum()
255+
except Exception as error:
256+
print("Can not handle font flags ({})".format(repr(error)))
257+
finally:
258+
try:
259+
source_font.close()
260+
dest_font.close()
261+
except:
262+
pass
255263
print(message)
256264

257265
if self.args.postprocess:

0 commit comments

Comments
 (0)