Build variable font versions from source files.
(font_config: FontConfig, build_option: BuildOption)
| 1483 | |
| 1484 | |
| 1485 | def build_variable_fonts(font_config: FontConfig, build_option: BuildOption): |
| 1486 | """Build variable font versions from source files.""" |
| 1487 | input_files = [ |
| 1488 | joinPaths(build_option.src_dir, "MapleMono-Italic[wght]-VF.ttf"), |
| 1489 | joinPaths(build_option.src_dir, "MapleMono[wght]-VF.ttf"), |
| 1490 | ] |
| 1491 | for input_file in input_files: |
| 1492 | font = TTFont(input_file) |
| 1493 | basename = path.basename(input_file) |
| 1494 | print(f"👉 Variable version for {basename}") |
| 1495 | |
| 1496 | # fix auto rename by FontLab |
| 1497 | rename_glyph_name( |
| 1498 | font=font, |
| 1499 | map=match_unicode_names( |
| 1500 | input_file.replace(".ttf", ".glyphs").replace("-VF", "") |
| 1501 | ), |
| 1502 | ) |
| 1503 | |
| 1504 | is_italic = "Italic" in input_file |
| 1505 | |
| 1506 | font_config.patch_font_feature( |
| 1507 | font=font, |
| 1508 | issue_fea_dir=build_option.output_dir, |
| 1509 | is_italic=is_italic, |
| 1510 | is_cn=False, |
| 1511 | is_variable=True, |
| 1512 | is_hinted=False, |
| 1513 | fea_path=build_option.get_feature_file_path(is_italic), |
| 1514 | ) |
| 1515 | |
| 1516 | style_name = "Italic" if is_italic else "Regular" |
| 1517 | postscript_name = f"{font_config.family_name_compact}-{style_name}" |
| 1518 | update_font_names( |
| 1519 | font=font, |
| 1520 | family_name=font_config.family_name, |
| 1521 | style_name=style_name, |
| 1522 | full_name=f"{font_config.family_name} {style_name}", |
| 1523 | version_str=font_config.version_str, |
| 1524 | postscript_name=postscript_name, |
| 1525 | unique_identifier=get_unique_identifier( |
| 1526 | font_config=font_config, |
| 1527 | postscript_name=postscript_name, |
| 1528 | variable=True, |
| 1529 | ), |
| 1530 | is_skip_subfamily=True, |
| 1531 | ) |
| 1532 | |
| 1533 | if is_italic: |
| 1534 | add_ital_axis_to_stat(font) |
| 1535 | |
| 1536 | patch_instance(font, font_config.weight_mapping) |
| 1537 | |
| 1538 | if font_config.line_height != 1: |
| 1539 | calculated_metric = (font["hhea"].ascender, font["hhea"].descender) # type: ignore |
| 1540 | if calculated_metric != font_config.vertical_metric: |
| 1541 | font_config.vertical_metric = calculated_metric |
| 1542 |
no test coverage detected