I'm trying to manually scale some fonts in my Java Swing application (ie. for a high res screen).
at 96 DPI (100%), Windows Look & Feel tells me the default font is Tahoma size 11. (using Label.font in the WLF) At 200% it's 21, 300% is 32, 400% is 43, and 500% is 53. (note that point size == font ascent)
My original approach is to take "my" default font: Tahoma size 11. Then calculate the scaling factor (ie. 2.0 for 200%). From there I want to calculate the font point size, however doing a straight up multiplication isn't in line with the Windows scaling,
so the question(s):
- How does font scaling work in Windows? and
How do I scale my fonts? (There is also other scaling done for components, etc.) The two main fonts in my application are Tahoma(11) and Segoe UI (12).
new WindowsLookAndFeel().getDefaults().getFont("Label.font") //returns 11 @ 100% Font font = StyleContext.getDefaultStyleContext().getFont("Tahoma", Font.PLAIN, 11); //my inital Composite font (Tahoma with Dialog fallback) Font newFont = font.deriveFont(zoomFactor * 11); // this gets me 22 @ 200%
Thanks!
11px per96dpi and scale it to11*[real]/96px per[real]dpi - Mike 'Pomax' Kamermans11pxmight not actually be a true pixel value but a pixel representation of a (fractional)ptvalue, in which case the 21px at 192dpi can easily be due to afloor(...)on the conversion result frompttopx. At that point you may need to know which text shaper you're dealing with (GDI, GDI+, DirectWrite?), or set your font size based on the dimensions of the container it needs to end up in. - Mike 'Pomax' Kamermans