Generate instances of variable fonts
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
98a9d78273
commit
2b7645a572
@ -4,7 +4,7 @@
|
||||
font-display: swap;
|
||||
font-weight: $weight;
|
||||
src: local('Inconsolata'),
|
||||
url('../fonts/Inconsolata-VariableFont_wdth,wght.ttf');
|
||||
url('../fonts/gen/Inconsolata-#{$weight}.woff2');
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,8 +13,8 @@
|
||||
font-family: 'Lora';
|
||||
font-display: swap;
|
||||
src: local('Lora'),
|
||||
url('../fonts/Lora-VariableFont_wght.ttf'),
|
||||
url('../fonts/Lora-Italic-VariableFont_wght.ttf');
|
||||
url('../fonts/gen/Lora-Regular.woff2'),
|
||||
url('../fonts/gen/Lora-Italic.woff2');
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,8 +24,8 @@
|
||||
font-display: swap;
|
||||
font-weight: $weight;
|
||||
src: local('Raleway'),
|
||||
url('../fonts/Raleway-VariableFont_wght.ttf'),
|
||||
url('../fonts/Raleway-Italic-VariableFont_wght.ttf');
|
||||
url('../fonts/gen/Raleway-#{$weight}.woff2'),
|
||||
url('../fonts/gen/Raleway-#{$weight}-Italic.woff2');
|
||||
}
|
||||
}
|
||||
|
||||
|
74
chatgpt-instance-fonts.py
Normal file
74
chatgpt-instance-fonts.py
Normal file
@ -0,0 +1,74 @@
|
||||
#!/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"
|
||||
)
|
||||
instantiate_variable_font(
|
||||
"Inconsolata-VariableFont_wdth,wght.ttf",
|
||||
{"wght": 700},
|
||||
"Inconsolata-700.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()
|
BIN
static/fonts/gen/Inconsolata-400.woff2
Normal file
BIN
static/fonts/gen/Inconsolata-400.woff2
Normal file
Binary file not shown.
BIN
static/fonts/gen/Inconsolata-700.woff2
Normal file
BIN
static/fonts/gen/Inconsolata-700.woff2
Normal file
Binary file not shown.
BIN
static/fonts/gen/Lora-Italic.woff2
Normal file
BIN
static/fonts/gen/Lora-Italic.woff2
Normal file
Binary file not shown.
BIN
static/fonts/gen/Lora-Regular.woff2
Normal file
BIN
static/fonts/gen/Lora-Regular.woff2
Normal file
Binary file not shown.
BIN
static/fonts/gen/Raleway-400-Italic.woff2
Normal file
BIN
static/fonts/gen/Raleway-400-Italic.woff2
Normal file
Binary file not shown.
BIN
static/fonts/gen/Raleway-400.woff2
Normal file
BIN
static/fonts/gen/Raleway-400.woff2
Normal file
Binary file not shown.
BIN
static/fonts/gen/Raleway-700-Italic.woff2
Normal file
BIN
static/fonts/gen/Raleway-700-Italic.woff2
Normal file
Binary file not shown.
BIN
static/fonts/gen/Raleway-700.woff2
Normal file
BIN
static/fonts/gen/Raleway-700.woff2
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user