Java FontMetrics getMaxFontHeight(final java.awt.Font font)

Here you can find the source of getMaxFontHeight(final java.awt.Font font)

Description

Gets the maximum font height used by of ALL characters, as recorded by the font.

License

Apache License

Declaration

public static int getMaxFontHeight(final java.awt.Font font) 

Method Source Code

//package com.java2s;
/*/*w  w w . j av  a2  s. co  m*/
 * Copyright 2014 dorkbox, llc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.FontMetrics;
import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Gets the maximum font height used by of ALL characters, as recorded by the font.
     */
    public static int getMaxFontHeight(final java.awt.Font font) {
        // Because font metrics is based on a graphics context, we need to create a small, temporary image to determine the width and height
        BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = image.createGraphics();

        FontMetrics metrics = g.getFontMetrics(font);
        int height = metrics.getMaxAscent() + metrics.getMaxDescent();

        g.dispose();

        return height;
    }
}

Related

  1. getLineHeight(Component c, int defaultHeight)
  2. getLineHeight(Component component, int count)
  3. getLineHeight(FontMetrics fm)
  4. getLongestStringWidth(FontMetrics fm, String[] theStrings)
  5. getMaxFittingFontSize(Graphics g, Font font, String string, Dimension size)
  6. getMonospacedFontNames()
  7. getMonospacedFontsFamillyName()
  8. getPrefSize(FontMetrics fm, String keyTip)
  9. getStringForMaxWidth(FontMetrics fm, String s, int maxWidth)