/**
 * 
 */
package mathsquared.resultswizard2;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;

/**
 * Contains utility methods for working with fonts.
 * 
 * @author MathSquared
 * 
 */
public class FontUtils {
    public static Font shrinkFontForWidth (Font base, String text, int desiredWidth, Graphics getMetrics) {
        FontMetrics metrics = getMetrics.getFontMetrics(base);
        while (metrics.stringWidth(text) > desiredWidth) {
            base = base.deriveFont((float) base.getSize() - 1);
        }
        return base;
    }
}

@@ -236,16 +236,778 @@
 Utils %7B%0A
+    /**%0A     * Finds the smallest font size that will fit a string within a given width.%0A     * %0A     * %3Cp%3E%0A     * Specifically, returns a %7B@link Font%7D %3Ccode%3Eret%3C/code%3E with a size less than its current size such that %3Ccode%3EgetMetrics.getFontMetrics(ret).stringWidth(text) &lt;= desiredWidth%3C/code%3E.%0A     * %3C/p%3E%0A     * %0A     * @param base the base font which should be shrunk (not modified)%0A     * @param text the string to fit within the given width%0A     * @param desiredWidth the maximum possible width of the text, in pixels%0A     * @param getMetrics a %7B@link Graphics%7D object which should be used to obtain %7B@link FontMetrics%7D for the given font%0A     * @return a Font identical to %3Ccode%3Ebase%3C/code%3E except possibly with a different font size as above%0A     */%0A
     publ

Document FontUtils.shrinkFontForWidth