mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-19 09:51:48 +02:00
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 <jakub@jirutka.cz> Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
This commit is contained in:
parent
189bc8673f
commit
c5878d44db
1 changed files with 22 additions and 14 deletions
36
font-patcher
36
font-patcher
|
@ -93,7 +93,8 @@ class TableHEADWriter:
|
||||||
self.tab_offset = self.getlong()
|
self.tab_offset = self.getlong()
|
||||||
self.tab_length = self.getlong()
|
self.tab_length = self.getlong()
|
||||||
if tab_name == b'head':
|
if tab_name == b'head':
|
||||||
break
|
return
|
||||||
|
raise Exception('No HEAD table found')
|
||||||
|
|
||||||
def goto(self, where):
|
def goto(self, where):
|
||||||
""" Go to a named location in the file or to the specified index """
|
""" Go to a named location in the file or to the specified index """
|
||||||
|
@ -251,19 +252,26 @@ class font_patcher:
|
||||||
message = "\nGenerated: {} in '{}'".format(self.sourceFont.fullname, outfile)
|
message = "\nGenerated: {} in '{}'".format(self.sourceFont.fullname, outfile)
|
||||||
|
|
||||||
# Adjust flags that can not be changed via fontforge
|
# Adjust flags that can not be changed via fontforge
|
||||||
source_font = TableHEADWriter(self.args.font)
|
try:
|
||||||
source_font.close()
|
source_font = TableHEADWriter(self.args.font)
|
||||||
dest_font = TableHEADWriter(outfile)
|
dest_font = TableHEADWriter(outfile)
|
||||||
if source_font.flags & 0x08 == 0 and dest_font.flags & 0x08 != 0:
|
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))
|
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'
|
dest_font.putshort(dest_font.flags & ~0x08, 'flags') # clear 'ppem_to_int'
|
||||||
if source_font.lowppem != dest_font.lowppem:
|
if source_font.lowppem != dest_font.lowppem:
|
||||||
print("Changing lowestRecPPEM from {} to {}".format(dest_font.lowppem, source_font.lowppem))
|
print("Changing lowestRecPPEM from {} to {}".format(dest_font.lowppem, source_font.lowppem))
|
||||||
dest_font.putshort(source_font.lowppem, 'lowestRecPPEM')
|
dest_font.putshort(source_font.lowppem, 'lowestRecPPEM')
|
||||||
if dest_font.modified:
|
if dest_font.modified:
|
||||||
dest_font.reset_table_checksum()
|
dest_font.reset_table_checksum()
|
||||||
dest_font.reset_full_checksum()
|
dest_font.reset_full_checksum()
|
||||||
dest_font.close()
|
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)
|
print(message)
|
||||||
|
|
||||||
if self.args.postprocess:
|
if self.args.postprocess:
|
||||||
|
|
Loading…
Reference in a new issue