public static int calculateMaxFontsize(final int initialFontsize, final int minFontsize, final int maxFontsize, final int availableSize) {
        int fontsize = initialFontsize;
        final TextPaint tPaint = new TextPaint();

        int height = getTextHeight(tPaint, initialFontsize, availableSize);
        if (height > availableSize) {
            while (height > availableSize && fontsize > minFontsize) {
                fontsize--;
                height = getTextHeight(tPaint, fontsize, availableSize);
            }
        } else {
            while (height < availableSize && fontsize < maxFontsize) {
                fontsize++;
                height = getTextHeight(tPaint, fontsize, availableSize);
            }
        }
        return fontsize;
    }
calculate maximum font size a text can use to fit into given size

@param initialFontsize - font size to start tests with
@param minFontsize     - minimum font size to return
@param maxFontsize     - maximum font size to use
@param availableSize   - available space for text
@return maximum font size within given ranges
main/src/main/java/cgeo/geocaching/utils/DisplayUtils.java