@staticmethod
def rescale_into(dimen, max_dimen):
    """ Scale down dimen to fit into max_dimen. """
    scale = 1.0
    if dimen[0]:
        scale = min(scale, max_dimen[0] / float(dimen[0]))
    if dimen[1]:
        scale = min(scale, max_dimen[1] / float(dimen[1]))
    if scale < 1.0:
        dimen = int(dimen[0] * scale) if dimen[0] else None, int(dimen[1] *
            scale) if dimen[1] else None
    return dimen
