def rect(svg, node, font_size):
    """Draw rect tag."""
    width, height = svg.point(node.get('width'), node.get('height'), font_size)
    if width <= 0 or height <= 0:
        return

    x, y = svg.point(node.get('x'), node.get('y'), font_size)

    rx = node.get('rx')
    ry = node.get('ry')
    if rx and ry is None:
        ry = rx
    elif ry and rx is None:
        rx = ry
    rx, ry = svg.point(rx, ry, font_size)

    if rx == 0 or ry == 0:
        svg.stream.rectangle(x, y, width, height)
        return

    if rx > width / 2:
        rx = width / 2
    if ry > height / 2:
        ry = height / 2

    # Inspired by Cairo Cookbook
    # https://cairographics.org/cookbook/roundedrectangles/
    arc_to_bezier = 4 * (2 ** .5 - 1) / 3
    c1, c2 = arc_to_bezier * rx, arc_to_bezier * ry

    svg.stream.move_to(x + rx, y)
    svg.stream.line_to(x + width - rx, y)
    svg.stream.curve_to(
        x + width - rx + c1, y, x + width, y + c2, x + width, y + ry)
    svg.stream.line_to(x + width, y + height - ry)
    svg.stream.curve_to(
        x + width, y + height - ry + c2, x + width + c1 - rx, y + height,
        x + width - rx, y + height)
    svg.stream.line_to(x + rx, y + height)
    svg.stream.curve_to(
        x + rx - c1, y + height, x, y + height - c2, x, y + height - ry)
    svg.stream.line_to(x, y + ry)
    svg.stream.curve_to(x, y + ry - c2, x + rx - c1, y, x + rx, y)
    svg.stream.close()
Draw rect tag.
weasyprint/svg/shapes.py