I'm measuring some font metrics in my program and then use those to create an output PDF file.
For that I'm using Graphics2D, FontContextRendered, GlyphVectors and all that goes along with it. I'm calling getGraphics() on a JTextArea with specified font.
However, if two users create the same document with the same data, but on two different devices, I need those documents to be exactly the same.
But, since Graphics2D uses current device's DPI, which my differ from device to device, that may not be the case.
Now I can do two things:
I'm guessing that second way is easier, but I don't know how to do it either way. Can you help me?
Graphics2D g2d;
final AffineTransform trans = g2d.getDeviceConfiguration().getNormalizingTransform();
System.out.println(trans.getScaleX()*72+" DPI horizontally");
System.out.println(trans.getScaleY()*72+" DPI vertically");
You can set the transformation to the Graphics2D
to force 72 DPI or scale it to any other DPI using the ratio between your desired DPI and 72 DPI.