The java.awt.Font.getStringBounds gives different results on openJdk11 and openJdk8

Viewed 126

I need to render PDF documents programmatically. I was using itext7 library and openJdk8. All worked fine but I decided to change openJdk8 on openJdk11 and my documents rendered with shifting y coordinates position. This result was gotten on openJdk8 and this result was gotten on openJdk11.
This is my code:

public void renderText(Font font, String text, double x, double y, FontRendererContext ctx) {
    Rectangle2D rect = font.getStringBounds(text, ctx);   // In this place I get a different result.
    pdf.addText(text, x, (pageHeight - y - rect.getY()));
}

I'm providing test example to reproduce this issue:

public static void main(String[] args {
    final String text = "Simple text";
    // load font
    final InputStream arialIs = Main.class.getClassLoader().getResourceAsStream("fonts/arial.ttf");
    Font font = Font.createFont(Font.TRUETYPE_FONT, arialIs);            
    GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
    Font newFont = font;
    newFont = newFont.deriveFont(14);
    
    // getting measuring
    final java.awt.geom.AffineTransform transform = newFont.getTransform();
    FontRenderContext frc = new FontRenderContext(transform, true, true);
    final Rectangle2D stringBounds = newFont.getStringBounds(text, frc);
    System.out.println(stringBounds);
}

How can I fix it on openJdk11?

0 Answers
Related