{"id":20610895,"url":"https://github.com/darkroomengineering/variable-font-converter","last_synced_at":"2025-03-06T17:46:26.252Z","repository":{"id":244245248,"uuid":"814684652","full_name":"darkroomengineering/variable-font-converter","owner":"darkroomengineering","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-13T14:33:47.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-01T20:49:41.292Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darkroomengineering.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["darkroomengineering"],"polar":"darkroomengineering"}},"created_at":"2024-06-13T13:46:01.000Z","updated_at":"2024-06-19T12:45:14.000Z","dependencies_parsed_at":"2024-06-13T16:45:58.556Z","dependency_job_id":null,"html_url":"https://github.com/darkroomengineering/variable-font-converter","commit_stats":null,"previous_names":["darkroomengineering/variable-font-converter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkroomengineering%2Fvariable-font-converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkroomengineering%2Fvariable-font-converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkroomengineering%2Fvariable-font-converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkroomengineering%2Fvariable-font-converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darkroomengineering","download_url":"https://codeload.github.com/darkroomengineering/variable-font-converter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242258252,"owners_count":20098293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T10:18:17.763Z","updated_at":"2025-03-06T17:46:26.206Z","avatar_url":"https://github.com/darkroomengineering.png","language":"Python","funding_links":["https://github.com/sponsors/darkroomengineering","https://polar.sh/darkroomengineering"],"categories":[],"sub_categories":[],"readme":"# Generate Static Fonts from Variable Font\n\nThis script allows you to generate static font instances from a variable font using the FontTools library. This can be useful for creating multiple static versions of a font with different properties (e.g., weight, slant, optical size).\n\n## Requirements\n\n- Python 3.x\n- FontTools library\n\nYou can install FontTools using pip:\n\n```sh\npip install fonttools\n```\n\n## Usage\n\n1. **Define the instances you want to generate**: \n   Modify the `instances` list to define the different static instances you want to create. Each instance is a dictionary with keys corresponding to the font variation axes (e.g., `wght`, `slnt`, `opts`) and values specifying the desired values for those axes.\n\n2. **Set the variable font path**: \n   Specify the path to your variable font file in the `variable_font_path` variable.\n\n3. **Set the output folder**: \n   Specify the path to the folder where you want the generated static fonts to be saved in the `output_folder` variable.\n\n4. **Run the script**: \n   Execute the script to generate the static fonts.\n\n### Example\n\n```python\nfrom fontTools.varLib import mutator\nfrom fontTools.ttLib import TTFont\nimport os\n\ndef generate_static_fonts(variable_font_path, output_folder, instances):\n    # Ensure the output directory exists\n    os.makedirs(output_folder, exist_ok=True)\n    \n    # Load the variable font\n    varfont = TTFont(variable_font_path)\n    \n    for instance in instances:\n        # Generate a static instance\n        static_font = mutator.instantiateVariableFont(varfont, instance)\n        \n        # Create the output file name based on the instance\n        instance_name = '-'.join(f'{k}{v}' for k, v in instance.items())\n        output_path = os.path.join(output_folder, f'{os.path.basename(variable_font_path).split(\".\")[0]}-{instance_name}.ttf')\n        \n        # Save the static font\n        static_font.save(output_path)\n        print(f'Saved: {output_path}')\n\n# Define the instances you want to generate (e.g., different weights)\ninstances = [\n    {\"wght\": 10, 'slnt': 4, 'opts': -10},\n    {\"wght\": 12, 'slnt': 4, 'opts': -10},\n    {\"wght\": 14, 'slnt': 4, 'opts': -10},\n    {\"wght\": 16, 'slnt': 4, 'opts': -10},\n    {\"wght\": 18, 'slnt': 4, 'opts': -10},\n]\n\n# Path to your variable font\nvariable_font_path = \"path/to/your-variable/font.ttf\"\n\n# Output folder\noutput_folder = \"path/to/output/folder\"\n\n# Generate static fonts\ngenerate_static_fonts(variable_font_path, output_folder, instances)\n```\n\n### Parameters\n\n- `variable_font_path`: The path to the variable font file.\n- `output_folder`: The folder where the generated static fonts will be saved.\n- `instances`: A list of dictionaries specifying the desired values for the font variation axes.\n\n### Output\n\nThe script will generate and save static font files in the specified output folder. The file names will include the base name of the variable font and the values of the specified axes.\n\n## License\n\nThis script is provided \"as is\" without warranty of any kind. Use it at your own risk.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkroomengineering%2Fvariable-font-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkroomengineering%2Fvariable-font-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkroomengineering%2Fvariable-font-converter/lists"}