Calculating MDI Window Size with clientDPI
Hello everyone!
We finally migrated some old forms from pixel based to centimeter based forms. We now wanted to scale the form by passing the clientDPI Parameter to the Java Applet, which should scale the form automatically.
The problem is, we set the FORMS_MDI_WINDOW-size everytime we call/open a form, to adjust its borders. The Application runs with the resolution of 800x600.
We made a java.bean which gave us the offsets in pixel for the window-borders (according to the look and feel of the os) and added them to the height and width of the window size, which gave us perfect results for the standard dpi (96).
Now by setting the clientDPI to a bigger value (120) we figured that the window size doesn't really fit.
After some time it hit me, that i always calculated the offset with the old dpi, and this was not right. So I had to calculate the pixel offset (according to the new dpi) by multiplying it with a factor (eg. 96/120) and then add it to the size.
I also noticed, that i had to consider some constant elements like the toolbar and the statusbar, which do not change its size. After several mindblowing hours of calculating, i came to the value of 84 pixel for the height and 6 pixel for the width. All i had to do was calculate the difference between the two dpi settings and substract it from my actual size. The window did fit smooth as hell.
Unfortunately - I knew it couldn't be that easy - by setting the clientDPI to 144, the window did not fit again. I calculated back to the constant height and found out, that it should have been 90 pixel instead of 84. I was really confused and thought that i still missed something.
I did this for several other dpi settings:
48 DPI: 102 Pixel constant
72 DPI: 100 Pixel constant
120 DPI: 84 Pixel constant
144 DPI: 90 Pixel constant
As you can see, the values aren't really linear. I have no idea how to calculate these "constants".
I know this is a very very specific issue, but i am wondering as hell what my error in reasoning is. Does anybody have any Idea?
Best Regards,
a confused Developer
PS: Currently I did a workaround by passing some user specified offsets through the formsweb.cfg to manually add or substract pixel to/from the window size.