-
Bug
-
Resolution: Fixed
-
P4
-
7, 8u251, 14.0.1
-
b08
-
x86
-
os_x
A DESCRIPTION OF THE PROBLEM :
Normally, Font.getStringBounds() methods can be called with empty text and the result is a rectangle of font height and zero width. If the font uses kerning, ligatures, or a baseline transformation though, an IllegalArgumentException will be thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect similar output for test1 and test2.
ACTUAL -
test1 works as expected, test2 throws IllegalArgumentException
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import java.awt.font.*;
import java.text.AttributedCharacterIterator;
public class FontMetricsBug {
public static void main(String[] args) {
SwingUtilities.invokeLater(()->go());
}
public static void go() {
JFrame f =
new JFrame() {
public void paint(Graphics g) {
super.paint(g);
FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
Font f = new Font("Monospaced", 0, 10);
System.out.println("test1: " + f.getStringBounds("", frc));
java.util.Map<AttributedCharacterIterator.Attribute, Object> attrs = new java.util.HashMap<>();
attrs.put(java.awt.font.TextAttribute.KERNING, java.awt.font.TextAttribute.KERNING_ON);
Font f2 = f.deriveFont(attrs);
System.out.println("test2: " + f2.getStringBounds("", frc));
}
};
f.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create a work-around utility method to be used in cases where the text may be empty when calling Font.getStringBounds(), FontMetrics.getStringBounds(), and anything else that might indirectly call Font.getStringBounds().
FREQUENCY : always
Normally, Font.getStringBounds() methods can be called with empty text and the result is a rectangle of font height and zero width. If the font uses kerning, ligatures, or a baseline transformation though, an IllegalArgumentException will be thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run code
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect similar output for test1 and test2.
ACTUAL -
test1 works as expected, test2 throws IllegalArgumentException
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
import java.awt.font.*;
import java.text.AttributedCharacterIterator;
public class FontMetricsBug {
public static void main(String[] args) {
SwingUtilities.invokeLater(()->go());
}
public static void go() {
JFrame f =
new JFrame() {
public void paint(Graphics g) {
super.paint(g);
FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
Font f = new Font("Monospaced", 0, 10);
System.out.println("test1: " + f.getStringBounds("", frc));
java.util.Map<AttributedCharacterIterator.Attribute, Object> attrs = new java.util.HashMap<>();
attrs.put(java.awt.font.TextAttribute.KERNING, java.awt.font.TextAttribute.KERNING_ON);
Font f2 = f.deriveFont(attrs);
System.out.println("test2: " + f2.getStringBounds("", frc));
}
};
f.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create a work-around utility method to be used in cases where the text may be empty when calling Font.getStringBounds(), FontMetrics.getStringBounds(), and anything else that might indirectly call Font.getStringBounds().
FREQUENCY : always