(
designspace: fontTools.designspaceLib.DesignSpaceDocument,
vtt_compile: bool = True,
)
| 225 | |
| 226 | |
| 227 | def compile_variable_and_save( |
| 228 | designspace: fontTools.designspaceLib.DesignSpaceDocument, |
| 229 | vtt_compile: bool = True, |
| 230 | ) -> None: |
| 231 | |
| 232 | if "Italic" in designspace.default.font.info.familyName: #Some weird stuff happens with Italics |
| 233 | designspace.default.font.info.familyName = designspace.default.font.info.familyName.replace(" Italic", "") |
| 234 | |
| 235 | familyName = designspace.default.font.info.familyName |
| 236 | styleName = designspace.default.font.info.styleName |
| 237 | file_stem = familyName.replace(" ", "") |
| 238 | if "Italic" in styleName and "Italic" not in file_stem: |
| 239 | file_stem = file_stem+"Italic" |
| 240 | file_path: Path = (OUTPUT_TTF_DIR / file_stem).with_suffix(".ttf") |
| 241 | |
| 242 | print(f"[{familyName} {styleName}] Compiling") |
| 243 | varFont = ufo2ft.compileVariableTTF(designspace, inplace=True) |
| 244 | |
| 245 | print(f"[{familyName} {styleName}] Merging VTT") |
| 246 | |
| 247 | if "Italic" in styleName: |
| 248 | font_vtt = fontTools.ttLib.TTFont(ITALIC_VTT_DATA_FILE) |
| 249 | else: |
| 250 | font_vtt = fontTools.ttLib.TTFont(VTT_DATA_FILE) |
| 251 | |
| 252 | |
| 253 | for table in ["TSI0", "TSI1", "TSI2", "TSI3", "TSI5", "TSIC", "maxp"]: |
| 254 | varFont[table] = fontTools.ttLib.newTable(table) |
| 255 | varFont[table] = font_vtt[table] |
| 256 | |
| 257 | # this will correct the OFFSET[R] commands in TSI1 |
| 258 | if font_vtt.getGlyphOrder() != varFont.getGlyphOrder(): |
| 259 | tsi1.fixOFFSET(varFont, font_vtt) |
| 260 | pass |
| 261 | |
| 262 | if vtt_compile: |
| 263 | print(f"[{familyName} {styleName}] Compiling VTT") |
| 264 | vttLib.compile_instructions(varFont, ship=True) |
| 265 | else: |
| 266 | file_path = (OUTPUT_TTF_DIR / str(file_stem+"_VTT")).with_suffix(".ttf") |
| 267 | |
| 268 | # last minute manual corrections to set things correctly |
| 269 | # set two flags to enable proper rendering (one for overlaps in Mac, the other for windows hinting) |
| 270 | # Helping mac office generage the postscript name correctly for variable fonts when an italic is present |
| 271 | set_overlap_flag(varFont) |
| 272 | varFont["head"].flags = 0x000b |
| 273 | |
| 274 | if "Regular" in styleName: |
| 275 | varFont["name"].setName(familyName.replace(" ","")+"Roman", 25, 3, 1, 1033) |
| 276 | |
| 277 | print(f"[{familyName} {styleName}] Saving") |
| 278 | file_path.parent.mkdir(exist_ok=True, parents=True) |
| 279 | varFont.save(file_path) |
| 280 | |
| 281 | print(f"[{familyName}] Done: {file_path}") |
| 282 | |
| 283 | |
| 284 | def compile_static_and_save(instance: ufoLib2.Font, name:str) -> None: |
no test coverage detected