Esempio n. 1
0
def contour() -> 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]
Esempio n. 2
0
def test_glyph_get_bounds():
    a = Glyph("a")
    pen = a.getPen()
    pen.moveTo((0, 0))
    pen.curveTo((10, 10), (10, 20), (0, 20))
    pen.closePath()

    b = Glyph("b", components=[Component("a", (1, 0, 0, 1, -50, 100))])

    layer = Layer(glyphs=[a, b])

    assert a.getBounds(layer) == BoundingBox(xMin=0, yMin=0, xMax=7.5, yMax=20)

    assert a.getControlBounds(layer) == BoundingBox(xMin=0,
                                                    yMin=0,
                                                    xMax=10,
                                                    yMax=20)

    with pytest.raises(
            TypeError,
            match="layer is required to compute bounds of components"):
        b.getBounds()
    with pytest.raises(
            TypeError,
            match="layer is required to compute bounds of components"):
        b.getControlBounds()

    assert b.getBounds(layer) == (-50, 100, -42.5, 120
                                  )  # namedtuple is a tuple
    assert b.getControlBounds(layer) == (-50, 100, -40, 120)
Esempio n. 3
0
def test_insertGlyph():
    g = Glyph()
    pen = g.getPen()
    pen.moveTo((0, 0))
    pen.lineTo((1, 1))
    pen.lineTo((0, 1))
    pen.closePath()

    layer = Layer()
    layer.insertGlyph(g, "a")

    assert "a" in layer
    assert layer["a"].name == "a"
    assert layer["a"].contours == g.contours
    assert layer["a"] is not g

    layer.insertGlyph(g, "b")
    assert "b" in layer
    assert layer["b"].name == "b"
    assert layer["b"].contours == layer["a"].contours
    assert layer["b"] is not layer["a"]
    assert layer["b"] is not g

    assert g.name is None

    with pytest.raises(KeyError, match="glyph named 'a' already exists"):
        layer.insertGlyph(g, "a", overwrite=False)

    with pytest.raises(ValueError,
                       match=".*Glyph .* has no name; can't add it"):
        layer.insertGlyph(g)
Esempio n. 4
0
def layer() -> 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
Esempio n. 5
0
def _draw_glyph_extents(ufo: ufoLib2.Font, glyph: Glyph):
    # apparently on Mac (but not Linux) Chrome and Firefox end up relying on the
    # extents of the base layer to determine where the glyph might paint. If you
    # leave the base blank the COLR glyph never renders.

    # TODO we could narrow this to bbox to cover all layers

    pen = glyph.getPen()
    pen.moveTo((0, 0))
    pen.lineTo((ufo.info.unitsPerEm, ufo.info.unitsPerEm))
    pen.endPath()

    return glyph
Esempio n. 6
0
def layer() -> Layer:
    a = Glyph("a")
    pen = a.getPen()
    pen.moveTo((8, 0))
    pen.lineTo((18, 0))
    pen.lineTo((18, 20))
    pen.lineTo((8, 20))
    pen.closePath()
    a.width = 30
    a.appendAnchor({"x": 10, "y": 30, "name": "top"})

    b = Glyph("b", width=a.width, components=[Component("a", (1, 0, 0, 1, 2, -5))])

    layer = Layer(glyphs=[a, b])
    return layer
Esempio n. 7
0
def _draw_glyph_extents(ufo: ufoLib2.Font, glyph: Glyph,
                        bounds: Tuple[float, float, float, float]):
    # apparently on Mac (but not Linux) Chrome and Firefox end up relying on the
    # extents of the base layer to determine where the glyph might paint. If you
    # leave the base blank the COLR glyph never renders.

    if rectArea(bounds) == 0:
        return

    start, end = bounds[:2], bounds[2:]

    pen = glyph.getPen()
    pen.moveTo(start)
    pen.lineTo(end)
    pen.endPath()

    return glyph