def liangbarsky(left, top, right, bottom, x1, y1, x2, y2):
    """Clips a line to a rectangular area.

    This implements the Liang-Barsky line clipping algorithm. ``left``,
    ``top``, ``right`` and ``bottom`` define the bounds of the clipping area,
    by which the line from ``(x1, y1)`` to ``(x2, y2)`` will be clipped.

    Args:
        left (int): The left boundary of the clipping area.
        top (int): The top boundary of the clipping area.
        right (int): The right boundary of the clipping area.
        bottom (int): The bottom boundary of the clipping area.
        x1 (int): The x-coordinate of the starting point of the line.
        y1 (int): The y-coordinate of the starting point of the line.
        x2 (int): The x-coordinate of the end point of the line.
        y2 (int): The y-coordinate of the end point of the line.

    Returns:
        tuple: The start and end coordinates of the clipped line in the form
        ``(cx1, cy1, cx2, cy2)``. If the line does not intersect with the
        rectangular clipping area, all 4 values will be ``None``.

    """
    dx = x2 - x1 * 1.0
    dy = y2 - y1 * 1.0
    dt0, dt1 = 0.0, 1.0
    xx1 = x1
    yy1 = y1

    if bottom > top:
        bottom, top = (top, bottom)

    checks = ((-dx, x1 - left),
              (dx, right - x1),
              (-dy, y1 - bottom),
              (dy, top - y1))

    for p, q in checks:
        if p == 0 and q < 0:
            return None, None, None, None
        if p != 0:
            dt = q / (p * 1.0)
            if p < 0:
                if dt > dt1:
                    return None, None, None, None
                dt0 = max(dt0, dt)
            else:
                if dt < dt0:
                    return None, None, None, None
                dt1 = min(dt1, dt)

    if dt0 > 0:
        x1 += dt0 * dx
        y1 += dt0 * dy
    if dt1 < 1:
        x2 = xx1 + dt1 * dx
        y2 = yy1 + dt1 * dy

    return x1, y1, x2, y2