corretto/corretto-11

java.awt.TextLayout class not working with corretto 8, in linux

pialinag opened this issue · 2 comments

Thank you for taking the time to help improve OpenJDK and Corretto 11.

If your request concerns a security vulnerability then please report it by email to aws-security@amazon.com instead of here.
(You can find more information regarding security issues at https://aws.amazon.com/security/vulnerability-reporting/.)

Otherwise, if your issue concerns OpenJDK 11
and is not specific to Corretto 11
we ask that you raise it to the OpenJDK community.
Depending on your contributor status for OpenJDK,
please use the JDK bug system or
the appropriate mailing list
for the given problem area or update project.

If your issue is specific to Corretto 11,
then you are in the right place.
Please proceed with the following.

Describe the bug

A clear and concise description of what the bug is.
I am unable to draw text using TextLayout after upgrading from sun/oracle jdk1.8 to corretto 8( jdk8.202.08.2_64bit and jdk8.212.04.2_64bit)

To Reproduce

Steps and (source) code to reproduce the behavior:-
My app uses activiti, which calls java awt classes to draw its bpmn modelling diagram.
Initially I was getting following NPE :
java.lang.NullPointerException
sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
sun.awt.FontConfiguration.init(FontConfiguration.java:107)
sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
sun.font.SunFontManager$2.run(SunFontManager.java:431)

Then I figured out it was the missing font libraries.

Just for the sake of investigation, I created my own fontconfig.properties in corretto jre/lib

I also find the fontmanager rpm package, needed by fontconfig, is also installed in my servers:
rpm -qa |grep -i font
fontconfig-2.10.95-10.el7.x86_64
fontpackages-filesystem-1.44-8.el7.noarch

And I copied the following fonts from jdk1.8/jre/lib to corretto jre/lib:
LucidaSansDemiBold.ttf, LucidaBrightDemiBold.ttf, LucidaSansRegular.ttf,LucidaBrightDemiItalic.ttf ,LucidaTypewriterBold.ttf,LucidaBrightItalic.ttf,LucidaTypewriterRegular.ttf,LucidaBrightRegular.ttf
LucidaTypewriterBoldOblique.ttf,LucidaSansDemiOblique.ttf,LucidaTypewriterOblique.ttf,LucidaSansOblique.ttf

Now I see the rectangles and lines in the diagram alright, but the text is not getting displayed.
This is how the awt classes are called to write the text within the rectangles:
AttributedString attributedString = new AttributedString(text);
attributedString.addAttribute(TextAttribute.FONT, g.getFont());
attributedString.addAttribute(TextAttribute.FOREGROUND, Color.black);
AttributedCharacterIterator characterIterator = attributedString.getIterator();
int currentHeight = 0;
List layouts = new ArrayList();
String lastLine = null;
LineBreakMeasurer measurer = new LineBreakMeasurer(characterIterator, g.getFontRenderContext());
TextLayout layout = null;
while (measurer.getPosition() < characterIterator.getEndIndex() && currentHeight <= boxHeight) {
int previousPosition = measurer.getPosition();
layout = measurer.nextLayout(boxWidth);
int height = ((Float)(layout.getDescent() + layout.getAscent() + layout.getLeading())).intValue();

layouts.add(layout);
currentHeight += height;

}
int currentY = y + (centered ? ((boxHeight - currentHeight) /2) : 0);
int currentX = 0;
for(TextLayout textLayout : layouts) {
currentY += textLayout.getAscent();
currentX = x + (centered ? ((boxWidth - ((Double)textLayout.getBounds().getWidth()).intValue()) /2) : 0);
textLayout.draw(g, currentX, currentY);
I see layout.getDescent(), layout.getAscent(), layout.getLeading() are returning huge numbers(always 240 in my case, whereas with oracle java 1.8, these used to be like getDescent()= 2.347168 layout.getAscent()= 10.45752)

Do these not work with corretto 8?

Expected behavior

A clear and concise description of what you expected to happen.
It should have painted text properly in the boxes like below:
image

Instead it shows empty box and line like below:
image

Screenshots

If applicable, add screenshots to help explain your problem.
It should have painted text properly in the boxes like below:
image

Instead it shows empty box and line like below:
image

Platform information

OS: [e.g. Amazon Linux 2]
Version [e.g. "11.0.1+13-1" (output from "java -version")]
my OS is Linux 3.10.0-514.10.2.el7.x86_64

Additional context

Add any other context about the problem here.

Hi,
I think this is the same as corretto/corretto-8#64 (comment). This is also the issues folder for Corretto11 not Corretto8

As I said in the other comment, please, undo all the changes you've done when trying to fix the font issue, the only thing corretto needs is fontconfig and a valid test with fc-match sans.

Closing issue, please re-open if the steps given above don't work.