def test_variable_output_filename(self, mock_designspace_locations, mock_TTFont_save, mock_varLib_build): project = FontProject() mock_designspace_locations.return_value = {'master1': 'location1'}, None mock_varLib_build.return_value = TTFont(), None, None project.build_variable_font('path/to/designspace.designspace') self.assertTrue(mock_TTFont_save.called) self.assertTrue(mock_TTFont_save.call_count == 1) self.assertEqual(mock_TTFont_save.call_args, mock.call('variable_ttf/designspace-VF.ttf'))
def test_variable_output_filename(self, mock_designspace_locations, mock_TTFont_save, mock_varLib_build): project = FontProject() mock_designspace_locations.return_value = { 'master1': 'location1' }, None mock_varLib_build.return_value = TTFont(), None, None project.build_variable_font('path/to/designspace.designspace') self.assertTrue(mock_TTFont_save.called) self.assertTrue(mock_TTFont_save.call_count == 1) self.assertEqual(mock_TTFont_save.call_args, mock.call('variable_ttf/designspace-VF.ttf'))
def test_variable_output_filename(self, mock_DesignSpaceDocument_fromfile, mock_TTFont_save, mock_varLib_build): project = FontProject() path = "path/to/designspace.designspace" doc = DesignSpaceDocument() doc.path = path mock_DesignSpaceDocument_fromfile.return_value = doc mock_varLib_build.return_value = TTFont(), None, None project.build_variable_font(path) self.assertTrue(mock_TTFont_save.called) self.assertTrue(mock_TTFont_save.call_count == 1) self.assertEqual(mock_TTFont_save.call_args, mock.call("variable_ttf/designspace-VF.ttf"))
def build_variable( designspacePath, stylespacePath=None, out=None, verbose="ERROR", ): """ Builds a variable font from a designspace using fontmake. Post applies the STAT table using a stylespace if given. *designspacePath* a `string` of the path to the designspace *stylespacePath* a `string` of the path to the stylespace *out* a `string` of the path where the varible font should be saved *verbose* sets the verbosity level for fontmake. Defaults to "ERROR" """ if out is None: out = os.path.splitext( os.path.basename(designspacePath))[0] + "-VF.ttf" else: if not os.path.exists(os.path.split(out)[0]): os.mkdir(os.path.split(out)[0]) print("🏗 Constructing variable font") fp = FontProject(verbose=verbose) fp.build_variable_font(designspacePath, output_path=out, useProductionNames=True) if stylespacePath is not None: print("🏗 Adding STAT table") ds = DesignSpaceDocument.fromfile(designspacePath) additional_locations = ds.lib.get("org.statmake.additionalLocations", {}) font = fontTools.ttLib.TTFont(out) stylespace = Stylespace.from_file(stylespacePath) apply_stylespace_to_variable_font(stylespace, font, additional_locations) font.save(out) print("✅ Built variable font")
def build_variable( designspacePath, stylespacePath=None, out=None, verbose="ERROR", ): """ Builds a variable font from a designspace using fontmake. Post applies the STAT table using a stylespace if given. *designspacePath* a `string` of the path to the designspace *stylespacePath* a `string` of the path to the stylespace *out* a `string` of the path where the varible font should be saved *verbose* sets the verbosity level for fontmake. Defaults to "ERROR" """ if out is None: out = os.path.splitext( os.path.basename(designspacePath))[0] + "-VF.ttf" else: if not os.path.exists(os.path.split(out)[0]): os.mkdir(os.path.split(out)[0]) print("🏗 Constructing variable font") fp = FontProject(verbose=verbose) fp.build_variable_font(designspacePath, output_path=out, useProductionNames=True) if stylespacePath is not None: print("🏗 Adding STAT table") ds = DesignSpaceDocument.fromfile(designspacePath) additional_locations = ds.lib.get("org.statmake.additionalLocations", {}) font = fontTools.ttLib.TTFont(out) stylespace = Stylespace.from_file(stylespacePath) apply_stylespace_to_variable_font(stylespace, font, additional_locations) font.save(out) font = fontTools.ttLib.TTFont(out) print("🏗 Add gasp table") gasp = fontTools.ttLib.newTable("gasp") gasp.gaspRange = {0xFFFF: 15} font["gasp"] = gasp print("🏗 Fix prep table") program = fontTools.ttLib.tables.ttProgram.Program() assembly = ['PUSHW[]', '511', 'SCANCTRL[]', 'PUSHB[]', '4', 'SCANTYPE[]'] program.fromAssembly(assembly) prep = fontTools.ttLib.newTable("prep") prep.program = program font["prep"] = prep print("🏗 Add dsig table") dsig = fontTools.ttLib.newTable("DSIG") dsig.ulVersion = 1 dsig.usFlag = 0 dsig.usNumSigs = 0 dsig.signatureRecords = [] font["DSIG"] = dsig print("🏗 Set fsType to 0") font["OS/2"].fsType = 0 font.save(out) print("✅ Built variable font")