| 282 | |
| 283 | |
| 284 | def compile_static_and_save(instance: ufoLib2.Font, name:str) -> None: |
| 285 | family_name = name |
| 286 | style_name = instance.info.styleName |
| 287 | print(f"[{family_name}] Building static instance: {style_name}") |
| 288 | |
| 289 | # Use pathops backend for overlap removal because it is, at the time of this |
| 290 | # writing, massively faster than booleanOperations and thanks to autohinting, |
| 291 | # there is no need to keep outlines compatible to previous releases. |
| 292 | static_ttf = ufo2ft.compileTTF( |
| 293 | instance, removeOverlaps=True, overlapsBackend="pathops" |
| 294 | ) |
| 295 | static_otf = ufo2ft.compileOTF( |
| 296 | instance, |
| 297 | removeOverlaps=True, |
| 298 | overlapsBackend="pathops", |
| 299 | # Can do inplace now because TTF is already done. |
| 300 | inplace=True, |
| 301 | # Don't optimize here, will be optimized after autohinting. |
| 302 | optimizeCFF=ufo2ft.CFFOptimization.NONE, |
| 303 | ) |
| 304 | |
| 305 | file_name = f"{family_name}-{style_name}".replace(" ", "") |
| 306 | file_path_static = (OUTPUT_STATIC_TTF_DIR / file_name).with_suffix(".ttf") |
| 307 | file_path_static_otf = (OUTPUT_STATIC_OTF_DIR / file_name).with_suffix(".otf") |
| 308 | |
| 309 | file_path_static.parent.mkdir(exist_ok=True, parents=True) |
| 310 | static_ttf.save(file_path_static) |
| 311 | file_path_static_otf.parent.mkdir(exist_ok=True, parents=True) |
| 312 | static_otf.save(file_path_static_otf) |
| 313 | print(f"[{family_name}] Done: {file_path_static}, {file_path_static_otf}") |
| 314 | |
| 315 | |
| 316 | # Font hinting |