Skip to content

Commit

Permalink
font-patcher: Ignore PPEM for non ttf/otf fonts
Browse files Browse the repository at this point in the history
[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]>
  • Loading branch information
Finii committed Aug 20, 2022
1 parent 189bc86 commit c5878d4
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions font-patcher
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class TableHEADWriter:
self.tab_offset = self.getlong()
self.tab_length = self.getlong()
if tab_name == b'head':
break
return
raise Exception('No HEAD table found')

def goto(self, where):
""" Go to a named location in the file or to the specified index """
Expand Down Expand Up @@ -251,19 +252,26 @@ class font_patcher:
message = "\nGenerated: {} in '{}'".format(self.sourceFont.fullname, outfile)

# Adjust flags that can not be changed via fontforge
source_font = TableHEADWriter(self.args.font)
source_font.close()
dest_font = TableHEADWriter(outfile)
if source_font.flags & 0x08 == 0 and dest_font.flags & 0x08 != 0:
print("Changing flags from 0x{:X} to 0x{:X}".format(dest_font.flags, dest_font.flags & ~0x08))
dest_font.putshort(dest_font.flags & ~0x08, 'flags') # clear 'ppem_to_int'
if source_font.lowppem != dest_font.lowppem:
print("Changing lowestRecPPEM from {} to {}".format(dest_font.lowppem, source_font.lowppem))
dest_font.putshort(source_font.lowppem, 'lowestRecPPEM')
if dest_font.modified:
dest_font.reset_table_checksum()
dest_font.reset_full_checksum()
dest_font.close()
try:
source_font = TableHEADWriter(self.args.font)
dest_font = TableHEADWriter(outfile)
if source_font.flags & 0x08 == 0 and dest_font.flags & 0x08 != 0:
print("Changing flags from 0x{:X} to 0x{:X}".format(dest_font.flags, dest_font.flags & ~0x08))
dest_font.putshort(dest_font.flags & ~0x08, 'flags') # clear 'ppem_to_int'
if source_font.lowppem != dest_font.lowppem:
print("Changing lowestRecPPEM from {} to {}".format(dest_font.lowppem, source_font.lowppem))
dest_font.putshort(source_font.lowppem, 'lowestRecPPEM')
if dest_font.modified:
dest_font.reset_table_checksum()
dest_font.reset_full_checksum()
except Exception as error:
print("Can not handle font flags ({})".format(repr(error)))
finally:
try:
source_font.close()
dest_font.close()
except:
pass
print(message)

if self.args.postprocess:
Expand Down

0 comments on commit c5878d4

Please sign in to comment.