-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from fonttools/contour-component-bounds
also add getBounds and getControlBounds for Contour and Component classes
- Loading branch information
Showing
7 changed files
with
104 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from ufoLib2.objects import Component, Glyph, Layer | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def layer(): | ||
a = Glyph("a") | ||
pen = a.getPen() | ||
pen.moveTo((0, 0)) | ||
pen.curveTo((10, 10), (10, 20), (0, 20)) | ||
pen.closePath() | ||
|
||
layer = Layer(glyphs=[a]) | ||
return layer | ||
|
||
|
||
def test_component_getBounds(layer): | ||
assert Component("a", (1, 0, 0, 1, 0, 0)).getBounds(layer) == (0, 0, 7.5, 20) | ||
assert Component("a", (1, 0, 0, 1, -5, 0)).getBounds(layer) == (-5, 0, 2.5, 20) | ||
assert Component("a", (1, 0, 0, 1, 0, 5)).getBounds(layer) == (0, 5, 7.5, 25) | ||
|
||
|
||
def test_component_getControlBounds(layer): | ||
assert Component("a", (1, 0, 0, 1, 0, 0)).getControlBounds(layer) == (0, 0, 10, 20) | ||
assert Component("a", (1, 0, 0, 1, -5, 0)).getControlBounds(layer) == (-5, 0, 5, 20) | ||
assert Component("a", (1, 0, 0, 1, 0, 5)).getControlBounds(layer) == (0, 5, 10, 25) | ||
|
||
|
||
def test_component_not_in_layer(layer): | ||
with pytest.raises(KeyError, match="b"): | ||
Component("b", (1, 0, 0, 1, 0, 0)).getBounds(layer) | ||
with pytest.raises(KeyError, match="b"): | ||
Component("b", (1, 0, 0, 1, 0, 0)).getControlBounds(layer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from ufoLib2.objects import Glyph | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def contour(): | ||
g = Glyph("a") | ||
pen = g.getPen() | ||
pen.moveTo((0, 0)) | ||
pen.curveTo((10, 10), (10, 20), (0, 20)) | ||
pen.closePath() | ||
return g.contours[0] | ||
|
||
|
||
def test_contour_getBounds(contour): | ||
assert contour.getBounds() == (0, 0, 7.5, 20) | ||
assert contour.getBounds(layer={}) == (0, 0, 7.5, 20) | ||
assert contour.bounds == (0, 0, 7.5, 20) | ||
|
||
|
||
def test_contour_getControlBounds(contour): | ||
assert contour.getControlBounds() == (0, 0, 10, 20) | ||
assert contour.getControlBounds(layer={}) == (0, 0, 10, 20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters