Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWT string width depends on DPI

Tags:

java

fonts

awt

We are developing an application for printing. The same text is rendered using AWT in two modes with different resolutions - screen (small DPI) and printing (300 DPI).

The problem is that text layout depends on DPI. And this dependency is non-linear. There are examples:

enter image description here Width: 200 px, font size: 10 pt

enter image description here Width: 400 px, font size: 20 pt

enter image description here Width: 600 px, font size: 30 pt

The rectangle width and font size are increasing proportionally from the first to the third image. But on the first image we have only "lazy", on the second we have "lazy do", and on the third only "lazy d".

Is there any way to constrain text layout while increasing total image size in pixels?

like image 456
Andrey Minogin Avatar asked Jan 16 '26 20:01

Andrey Minogin


1 Answers

graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
like image 60
Andrey Minogin Avatar answered Jan 19 '26 18:01

Andrey Minogin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!