Last active
June 15, 2025 06:43
-
-
Save huachaohuang/8a935f5095238bb2b9430517d6a3726d to your computer and use it in GitHub Desktop.
Use fontforge to center the asterisk in a font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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