You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Corretto-11.0.14.9.1, the TextAttribute.TRACKING is not working while doing font rendering. Irrespective of whatever tracking value provided, the rendered font is the same.
To Reproduce
By running the below java file with Corretto 11, we can observe that the change in tracking values do not change the width of rendered text. Whereas its working correctly in Corretto 8.
import java.awt.*;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.awt.font.FontRenderContext;
import java.awt.font.TextAttribute;
import java.awt.geom.AffineTransform;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
private static final String GEORGIA = "Georgia";
public static void main(final String[] args) {
getTextDimensionsForGivenFontProperties("ASSISTA AGORA", 32D, 0, GEORGIA, 0D);
getTextDimensionsForGivenFontProperties("ASSISTA AGORA", 32D, 0, GEORGIA, 25D);
getTextDimensionsForGivenFontProperties("ASSISTA AGORA", 32D, 0, GEORGIA, 50D);
}
private static void getTextDimensionsForGivenFontProperties(final String text, final Double fontSize,
final Integer fontStyle, final String font,
final Double tracking){
try {
AffineTransform affinetransform = new AffineTransform();
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
Font preTrackingFont;
preTrackingFont = new Font(GEORGIA, fontStyle, fontSize.intValue());
Map<TextAttribute, Object> attributeMap = new HashMap<>();
// As we are using 1000s of ems as measure we have to divide value of tracking by 1000 here.
Double trackingForAttributeMap = tracking * 0.001;
attributeMap.put(TextAttribute.TRACKING, trackingForAttributeMap);
Font customFont = preTrackingFont.deriveFont(attributeMap);
final Double width = customFont.getStringBounds(text, frc).getWidth();
final Double height = customFont.getStringBounds(text, frc).getHeight();
System.out.println("Tracking: " + tracking + ", Width: " + width + ", height: " + height);;
} catch (Exception e){
throw new RuntimeException(e);
}
}
}
Expected behavior
By running the above code using JDK 11 and JDK 8, we can see the difference in expected width in Java 8 and Java 11. Expectation is to have same output in Java 8 and Java 11.
OS: Amazon Linux 2, MacOS Big Sur 11.6.4
Version
openjdk 11.0.14 2022-01-18 LTS
OpenJDK Runtime Environment Corretto-11.0.14.9.1 (build 11.0.14+9-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.9.1 (build 11.0.14+9-LTS, mixed mode)
The text was updated successfully, but these errors were encountered:
Describe the bug
In Corretto-11.0.14.9.1, the TextAttribute.TRACKING is not working while doing font rendering. Irrespective of whatever tracking value provided, the rendered font is the same.
To Reproduce
By running the below java file with Corretto 11, we can observe that the change in tracking values do not change the width of rendered text. Whereas its working correctly in Corretto 8.
Expected behavior
By running the above code using JDK 11 and JDK 8, we can see the difference in expected width in Java 8 and Java 11. Expectation is to have same output in Java 8 and Java 11.
Platform information
The text was updated successfully, but these errors were encountered: