Skip to content

Commit

Permalink
clean flattend_kernel_table generation using itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
mjishnu committed Sep 24, 2024
1 parent db83168 commit c407f4c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions handwrite/svgtottf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
import json
import os
import sys
Expand Down Expand Up @@ -127,9 +128,9 @@ def set_kerning(self, table):
Config dictionary with kerning values/autokern bool.
"""
rows = table["rows"]
rows = [list(i) if i != None else None for i in rows]
rows = [list(i) if i is not None else None for i in rows]
cols = table["cols"]
cols = [list(i) if i != None else None for i in cols]
cols = [list(i) if i is not None else None for i in cols]

self.font.addLookup("kern", "gpos_pair", 0, [["kern", [["latn", ["dflt"]]]]])

Expand All @@ -141,12 +142,8 @@ def set_kerning(self, table):
kerning_table = table.get("table", False)
if not kerning_table:
raise ValueError("Kerning offsets not found in the config file.")
flatten_list = (
lambda y: [x for a in y for x in flatten_list(a)]
if type(y) is list
else [y]
)
offsets = [0 if x is None else x for x in flatten_list(kerning_table)]
flattened_kerning_table = list(itertools.chain.from_iterable(kerning_table))
offsets = [0 if x is None else x for x in flattened_kerning_table]
self.font.addKerningClass("kern", "kern-1", rows, cols, offsets)

def generate_font_file(self, filename, outdir, config_file):
Expand Down

0 comments on commit c407f4c

Please sign in to comment.