A few bold keywords aren't worth the font Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Instantiate variable fonts at specific weights/styles, producing static TTF files.
|
|
No subsetting, no recursive searching—just direct calls with hardcoded axis values.
|
|
Requires fontTools >= 4.0.
|
|
|
|
Genererated by ChatGTP o3-mini-high. Not human-modified.
|
|
"""
|
|
|
|
from fontTools.ttLib import TTFont
|
|
from fontTools.varLib.instancer import instantiateVariableFont
|
|
|
|
def instantiate_variable_font(input_font_path, axis_values, output_font_path):
|
|
"""
|
|
1) Loads a variable font from `input_font_path`.
|
|
2) Instantiates (flattens) it at the specified axis values (e.g. {"wght": 400}).
|
|
3) Saves the result as a static TTF at `output_font_path`.
|
|
"""
|
|
print(f"Instantiating {input_font_path} with axes={axis_values} -> {output_font_path}")
|
|
vf = TTFont(input_font_path)
|
|
static_font = instantiateVariableFont(vf, axis_values)
|
|
static_font.flavor = "woff2"
|
|
static_font.save(output_font_path)
|
|
|
|
def main():
|
|
# Inconsolata (Variable)
|
|
instantiate_variable_font(
|
|
"Inconsolata-VariableFont_wdth,wght.ttf",
|
|
{"wght": 400},
|
|
"Inconsolata-400.woff2"
|
|
)
|
|
|
|
# Lora (Variable, normal and italic)
|
|
instantiate_variable_font(
|
|
"Lora-VariableFont_wght.ttf",
|
|
{"wght": 400},
|
|
"Lora-Regular.woff2"
|
|
)
|
|
instantiate_variable_font(
|
|
"Lora-Italic-VariableFont_wght.ttf",
|
|
{"wght": 400},
|
|
"Lora-Italic.woff2"
|
|
)
|
|
|
|
# Raleway (Variable, normal and italic)
|
|
instantiate_variable_font(
|
|
"Raleway-VariableFont_wght.ttf",
|
|
{"wght": 400},
|
|
"Raleway-400.woff2"
|
|
)
|
|
instantiate_variable_font(
|
|
"Raleway-VariableFont_wght.ttf",
|
|
{"wght": 700},
|
|
"Raleway-700.woff2"
|
|
)
|
|
instantiate_variable_font(
|
|
"Raleway-Italic-VariableFont_wght.ttf",
|
|
{"wght": 400},
|
|
"Raleway-400-Italic.woff2"
|
|
)
|
|
instantiate_variable_font(
|
|
"Raleway-Italic-VariableFont_wght.ttf",
|
|
{"wght": 700},
|
|
"Raleway-700-Italic.woff2"
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|