def test_svg_to_colr_to_svg(svg_in, expected_svg_out, config_overrides): config, glyph_inputs = test_helper.color_font_config( config_overrides, (svg_in, ), ) _, ttfont = write_font._generate_color_font(config, glyph_inputs) svg_before = SVG.parse(str(test_helper.locate_test_file(svg_in))) svgs_from_font = tuple( colr_to_svg(svg_before.view_box(), ttfont, rounding_ndigits=3).values()) assert len(svgs_from_font) == 1 svg_expected = SVG.parse( str(test_helper.locate_test_file(expected_svg_out))) test_helper.svg_diff(svgs_from_font[0], svg_expected)
def _svg_root(view_box: Rect) -> etree.Element: svg_tree = etree.parse( str(test_helper.locate_test_file("colr_to_svg_template.svg"))) svg_root = svg_tree.getroot() vbox = (view_box.x, view_box.y, view_box.w, view_box.h) svg_root.attrib["viewBox"] = " ".join(ntos(v) for v in vbox) return svg_root
def _svg_root(view_box: Rect) -> etree.Element: svg_tree = etree.parse( test_helper.locate_test_file("colr_to_svg_template.svg")) svg_root = svg_tree.getroot() svg_root.attrib[ "viewBox"] = f"{view_box.x} {view_box.y} {view_box.w} {view_box.h}" return svg_root
def test_build_picosvg_font(): tmp_dir = _run((locate_test_file("minimal_static/config_picosvg.toml"), )) font = TTFont(tmp_dir / "Font.ttf") # fill=none ellipse dropped, rect became path, everything is under a group svg_content = font["SVG "].docList[0][0] assert _svg_element_names("/svg/g/*", svg_content) == ("path", "path"), svg_content
def test_read_write_config(config_file): tmp_dir = Path(tempfile.mkdtemp()) if config_file: config_file = locate_test_file(config_file) tmp_dir = tmp_dir / config_file.name else: tmp_dir = tmp_dir / "the_default.toml" original = config.load(config_file) config.write(tmp_dir, original) reloaded = config.load(tmp_dir) assert original == reloaded
def test_build_untouchedsvg_font(): tmp_dir = _run( (locate_test_file("minimal_static/config_untouchedsvg.toml"), )) font = TTFont(tmp_dir / "Font.ttf") assert "SVG " in font font = TTFont(tmp_dir / "Font.ttf") svg_content = font["SVG "].docList[0][0] # one group introduced assert _svg_element_names("/svg/*", svg_content) == ("g", ), svg_content # rect stayed rect, fill non ellipse still around assert _svg_element_names("/svg/g/*", svg_content) == ( "path", "rect", "ellipse", ), svg_content
def test_the_curious_case_of_the_parentless_reused_el(): # https://github.com/googlefonts/nanoemoji/issues/346 svgs = [ f"parentless_reused_el/emoji_u{codepoints}.svg" for codepoints in ("0023_20e3", "1f170", "1f171") ] tmp_dir = _run(( "--color_format=picosvg", "--pretty_print", "--keep_glyph_names", *(locate_test_file(svg) for svg in svgs), )) font = TTFont(tmp_dir / "Font.ttf") assert_expected_ttx(svgs, font, "parentless_reused_el.ttx", include_tables=["GlyphOrder", "SVG "])
def test_glyphmap_games(): # https://github.com/googlefonts/nanoemoji/issues/354 # We want to see both glyphs but only one cmap'd, and the use of our special naming scheme svgs = [ "emoji_u25fd.svg", "emoji_u42.svg", ] tmp_dir = _run(( "--color_format=glyf_colr_1", "--keep_glyph_names", "--glyphmap_generator=write_test_glyphmap", *(locate_test_file(svg) for svg in svgs), )) font = TTFont(tmp_dir / "Font.ttf") # We don't really need glyf but ... perhaps it's informative assert_expected_ttx(svgs, font, "glyphmap_games.ttx", include_tables=["GlyphOrder", "cmap"])
def test_build_static_font_default_config_cli_svg_list(): tmp_dir = _run((locate_test_file("minimal_static/svg/61.svg"), )) font = TTFont(tmp_dir / "Font.ttf") assert "fvar" not in font
def test_build_variable_font(): tmp_dir = _run((locate_test_file("minimal_vf/config.toml"), )) font = TTFont(tmp_dir / "MinimalVF.ttf") assert "fvar" in font
original = config.load(config_file) config.write(tmp_dir, original) reloaded = config.load(tmp_dir) assert original == reloaded @pytest.mark.parametrize( "relative_base, src, expected_files", [ # relative single file ( test_data_dir(), "minimal_static/svg/61.svg", {locate_test_file("minimal_static/svg/61.svg")}, ), # relative pattern ( test_data_dir(), "linear_gradient_transform*.svg", { locate_test_file("linear_gradient_transform.svg"), locate_test_file("linear_gradient_transform_2.svg"), locate_test_file("linear_gradient_transform_3.svg"), }, ), # absolute single file ( test_data_dir(), locate_test_file("minimal_static/svg/61.svg").resolve(),