Skip to content

Instantly share code, notes, and snippets.

@huachaohuang
Last active June 15, 2025 06:43
Show Gist options
  • Save huachaohuang/8a935f5095238bb2b9430517d6a3726d to your computer and use it in GitHub Desktop.
Save huachaohuang/8a935f5095238bb2b9430517d6a3726d to your computer and use it in GitHub Desktop.
Use fontforge to center the asterisk in a font
import fontforge
def center(c):
return (c.boundingBox()[1] + c.boundingBox()[3]) / 2
def transform(input, output):
font = fontforge.open(input)
plus = font["plus"]
asterisk = font["asterisk"]
asterisk_shift = center(plus) - center(asterisk)
asterisk.transform((1, 0, 0, 1, 0, asterisk_shift))
font.generate(output)
font.close()
if __name__ == "__main__":
import os
import sys
input_dir = sys.argv[1]
output_dir = sys.argv[2]
if not os.path.exists(output_dir):
os.mkdir(output_dir)
for name in os.listdir(input_dir):
input = os.path.join(input_dir, name)
output = os.path.join(output_dir, name)
transform(input, output)
print(f"Generated {output}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment