Float font size is not working in OpenJDK. Seems that the font size is rounded off while calculating string bounds e.g. 11.4 -> 11 & 11.5 -> 12 However in oracle jdk its working perfectly.
Any idea how to resolve this in OpenJDK 8?
Program:
import java.awt.Font;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;
public class TestFont {
public static void main(String []args){
FontRenderContext frc = new FontRenderContext(null, true, true);
Font font = new Font("Courier New",0,(int)11.5);
font = font.deriveFont(11.5f);
Rectangle2D bound = font.getStringBounds("PAGE",0,4, frc);
System.out.println("Char width:"+ bound.getWidth() / 4);
Font2D font2D = FontUtilities.getFont2D(font);
System.out.println("Font2D:" + font2D.toString());
}
}
Results:
OpenJDK 7,8,9:
Char width:7.201171875
Font2D:** TrueType Font: Family=Courier New Name=Courier New style=0 fileName=C:\windows\Fonts\cour.ttf
Oracle JDK 8:
Char width:6.901123046875
Font2D:** TrueType Font: Family=Courier New Name=Courier New style=0 fileName=C:\windows\Fonts\cour.ttf
That 's what i was thinking ^^. here is a topic related to your issue :
Fonts slightly wider in OpenJDK vs OracleJDK