Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextAttribute TRACKING not working in corretto-11 #249

Open
sj30798 opened this issue Feb 28, 2022 · 1 comment
Open

TextAttribute TRACKING not working in corretto-11 #249

sj30798 opened this issue Feb 28, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@sj30798
Copy link

sj30798 commented Feb 28, 2022

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.

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.

jainsh@147ddae05544: /Users/jainsh/test-analysis/fonts
➜   /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/bin/javac Test.java
jainsh@147ddae05544: /Users/jainsh/test-analysis/fonts
➜   /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/bin/java Test
Tracking: 0.0, Width: 249.1875, height: 36.359375
Tracking: 25.0, Width: 249.1875, height: 36.359375
Tracking: 50.0, Width: 249.1875, height: 36.359375
jainsh@147ddae05544: /Users/jainsh/test-analysis/fonts
➜   /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/bin/javac Test.java
jainsh@147ddae05544: /Users/jainsh/test-analysis/fonts
➜   /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home/bin/java Test
Tracking: 0.0, Width: 249.1875, height: 36.359375
Tracking: 25.0, Width: 259.5875244140625, height: 36.359375
Tracking: 50.0, Width: 269.9875183105469, height: 36.359375
jainsh@147ddae05544: /Users/jainsh/test-analysis/fonts
➜   /Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home/bin/java Test
Tracking: 0.0, Width: 249.1875, height: 36.359375
Tracking: 25.0, Width: 249.1875, height: 36.359375
Tracking: 50.0, Width: 249.1875, height: 36.359375

Platform information

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)
@sj30798 sj30798 added the bug Something isn't working label Feb 28, 2022
@mrserb
Copy link
Contributor

mrserb commented Mar 9, 2022

Hi, thank you for the bug report. Could you please check behavior of this problem using jdk17?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants