def test_componentize(): ttf_path = _get_test_ttf_path() save_path = get_temp_file_path() opts = Object() setattr(opts, 'font_path', ttf_path) setattr(opts, 'output_path', save_path) ufo, ps_names = ttfcomp.get_glyph_names_mapping(_get_test_ufo_path()) ttcomp_obj = ttfcomp.TTComponentizer(ufo, ps_names, opts) ttcomp_obj.componentize() # 'get_composites_data' method comps_data = ttcomp_obj.composites_data comps_name_list = sorted(comps_data.keys()) comps_comp_list = [comps_data[gname] for gname in comps_name_list] assert comps_name_list == [ 'aa', 'aacute', 'adieresis', 'atilde', 'uni01CE' ] assert comps_comp_list[1].names == ('a', 'uni0301') assert comps_comp_list[4].names == ('a', 'uni030C') assert comps_comp_list[1].positions == ((0, 0), (263.35, 0)) assert comps_comp_list[4].positions == ((0, 0), (263, 0)) # 'assemble_components' method comps_data = ttfcomp.ComponentsData() comps_data.names = ('a', 'uni01CE') comps_data.positions = ((0, 0), (263, 0)) comps_data.same_advwidth = True comp_one, comp_two = ttcomp_obj.assemble_components(comps_data) assert comp_one.glyphName == 'a' assert comp_two.glyphName == 'uni01CE' assert (comp_one.x, comp_one.y) == (0, 0) assert (comp_two.x, comp_two.y) == (263, 0) assert comp_one.flags == 0x204 assert comp_two.flags == 0x4
def test_componentize(): ttf_path = _get_test_ttf_path() save_path = get_temp_file_path() opts = Object() setattr(opts, 'font_path', ttf_path) setattr(opts, 'output_path', save_path) ufo, ps_names = ttfcomp.get_glyph_names_mapping(_get_test_ufo_path()) ttcomp_obj = ttfcomp.TTComponentizer(ufo, ps_names, opts) ttcomp_obj.componentize() # 'get_composites_data' method comps_data = ttcomp_obj.composites_data comps_name_list = sorted(comps_data.keys()) comps_comp_list = [comps_data[gname] for gname in comps_name_list] assert comps_name_list == ['aa', 'aacute', 'adieresis', 'atilde', 'uni01CE'] assert comps_comp_list[1].names == ('a', 'uni0301') assert comps_comp_list[4].names == ('a', 'uni030C') assert comps_comp_list[1].positions == ((0, 0), (263.35, 0)) assert comps_comp_list[4].positions == ((0, 0), (263, 0)) # 'assemble_components' method comps_data = ttfcomp.ComponentsData() comps_data.names = ('a', 'uni01CE') comps_data.positions = ((0, 0), (263, 0)) comps_data.same_advwidth = True comp_one, comp_two = ttcomp_obj.assemble_components(comps_data) assert comp_one.glyphName == 'a' assert comp_two.glyphName == 'uni01CE' assert (comp_one.x, comp_one.y) == (0, 0) assert (comp_two.x, comp_two.y) == (263, 0) assert comp_one.flags == 0x204 assert comp_two.flags == 0x4
def test_get_composites_data(): ufo, ps_names = ttfcomp.get_glyph_names_mapping(_get_test_ufo_path()) comps_data = ttfcomp.get_composites_data(ufo, ps_names) comps_name_list = sorted(list(comps_data.keys())) comps_comp_list = [comps_data[gname] for gname in comps_name_list] assert comps_name_list == ['aacute', 'adieresis', 'atilde', 'uni01CE'] assert comps_comp_list[0].names == ('a', 'uni0301') assert comps_comp_list[3].names == ('a', 'uni030C') assert comps_comp_list[0].positions == ((0, 0), (263.35, 0)) assert comps_comp_list[3].positions == ((0, 0), (263, 0))
def test_get_glyph_names_mapping_names_from_goadb(): # the test UFO has a 'public.postscriptNames' in its lib; # empty the lib temporarily to force the reading of the GOADB ufo_path = _get_test_ufo_path() lib_path = os.path.join(ufo_path, 'lib.plist') lib_data = _read_file(lib_path) _write_file(lib_path, EMPTY_LIB) result = ttfcomp.get_glyph_names_mapping(ufo_path) _write_file(lib_path, lib_data) assert sorted(result[1].keys()) == DESIGN_NAMES_LIST assert sorted(result[1].values()) == PRODCT_NAMES_LIST
def test_warn_empty_psnames_key(capsys): # the test UFO has a 'public.postscriptNames' in its lib; # set the key to empty to ensure we get a warning ufo_path = _get_test_ufo_path() lib_path = os.path.join(ufo_path, 'lib.plist') lib_data = _read_file(lib_path) _write_file(lib_path, EMPTY_PSKEY) result = ttfcomp.get_glyph_names_mapping(ufo_path) _write_file(lib_path, lib_data) assert len(result[1]) == 0 captured = capsys.readouterr() # check (partial) warning message in stdout: assert "WARNING: The contents of public.postscriptNames is empty." in captured.out # noqa: E501
def test_get_glyph_names_mapping_names_from_lib(): result = ttfcomp.get_glyph_names_mapping(_get_test_ufo_path()) assert sorted(result[1].keys()) == DESIGN_NAMES_LIST assert sorted(result[1].values()) == PRODCT_NAMES_LIST
def test_get_glyph_names_mapping_invalid_ufo(): path = _get_test_ttf_path() assert ttfcomp.get_glyph_names_mapping(path) == (None, None)