Skip to content

Commit

Permalink
only touch lichess.sfd when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
schlawg committed Nov 16, 2024
1 parent 0e0cb37 commit 14214b3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions bin/gen/licon.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def main():

gen_fonts()

codes = parse_codes()
codes = read_write_codes()

gen_sources(codes)

Expand All @@ -110,32 +110,33 @@ def dash_camel(s):
return ''.join([w.title() for w in s.split('-')])


def parse_codes():
def read_write_codes():
unnamed_re = re.compile(r'$|uni[a-f0-9]{4}', re.IGNORECASE)
codes = {}
warnings = []
corrected = []
lines = []
with open('lichess.sfd', 'r') as f:
lines = f.readlines()
name = None
n = 0
line_ok = True
for line in lines:
if line.startswith('StartChar:'):
name = dash_camel(line.split(': ')[1].strip())
elif line.startswith('Encoding:') and name is not None:
code_point = int(line.split(' ')[1])
if code_point >= 0xe000 and code_point <= 0xefff:
code_point = 57344 + n
n += 1
code_point = 57343 + n
line = f'Encoding: {code_point} {code_point} {n}\n'
if unnamed_re.match(name):
warnings.append(f' Unnamed glyph "{name}" at code point {code_point}\n')
else:
codes[name] = code_point
corrected.append(line)
with open('lichess.sfd', 'w') as f:
f.write(''.join(corrected))
if corrected != lines:
with open('lichess.sfd', 'w') as f:
f.write(''.join(corrected))
print('' if not warnings else f'\nWarnings:\n{"".join(warnings)}')
return dict(sorted(codes.items(), key=lambda x: x[1]))

Expand Down

0 comments on commit 14214b3

Please sign in to comment.