Skip to content

Commit

Permalink
add dedicated bbox tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anthrotype committed Mar 8, 2021
1 parent 4b6d6c3 commit 88d6c82
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/empty.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions tests/write_font_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,50 @@ def test_write_font_binary(svgs, expected_ttx, config_overrides):
# SVG should not have identical paths or gradients
# in both cases this should be true when normalized to start from 0,0
test_helper.assert_expected_ttx(svgs, ttfont, expected_ttx)


@pytest.mark.parametrize(
"svgs, config_overrides, expected",
[
(
("one_rect.svg",),
{},
# original rect's (xMin, yMin, xMax, yMax) with no user-transform
(20, 60, 80, 80),
),
(
("one_rect.svg",),
# rotate 90 degrees clockwise around (20, 60)
{"transform": Affine2D.fromstring("rotate(-90, 20, 60)")},
(20, 0, 40, 60),
),
(
("one_rect.svg",),
# flatten so that bounds area == 0
{"transform": Affine2D.fromstring("matrix(0 0 0 1 0 0)")},
None,
),
(
# SVG contains no paths, UFO glyph empty: bounds are None
("empty.svg",),
{},
None,
),
],
)
def test_ufo_color_base_glyph_bounds(svgs, config_overrides, expected):
config_overrides = {"output": "ufo", **config_overrides}
config, glyph_inputs = test_helper.color_font_config(config_overrides, svgs)
ufo, _ = write_font._generate_color_font(config, glyph_inputs)

base_glyph = ufo["e000"]
bounds = base_glyph.getControlBounds(ufo)

if expected is not None:
assert bounds == pytest.approx(expected)
# 1 contour with 2 points
assert len(base_glyph) == 1
assert len(base_glyph[0]) == 2
else:
assert bounds is None
assert len(base_glyph) == 0

0 comments on commit 88d6c82

Please sign in to comment.