<Swing Dev> RFR: 8231286: HTML font size too large with high-DPI scaling and W3C_UNIT_LENGTHS

Sergey Bylokhov serb at openjdk.java.net
Wed Dec 9 03:38:37 UTC 2020


On Fri, 4 Dec 2020 17:30:11 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> Issue is when using a JEditorPane to render HTML views with W3C_UNIT_LENGTHS enabled, font-sizes set using CSS are much larger than the same font size outside the HTML.
> It's because CSS LengthUnit uses screen resolution to calculate units so for hidpi screens, the html font size is bigger. 
> Fix is to calculate the units based on the CSS absolute length mentioned in https://drafts.csswg.org/css-values-3/#absolute-lengths so hidpi scaling is not applied twice in CSS and again by Java.

src/java.desktop/share/classes/javax/swing/text/html/CSS.java line 2867:

> 2865: 
> 2866:             // mapping according to the CSS2 spec
> 2867:             // https://drafts.csswg.org/css-values-3/#absolute-lengths

Are you sure that you can get the exact values of these absolute lengths without using a DPI of the screen? I mean that these values can be measured with a ruler on the screen and they must correspond to "cm" is one centimeter, and "in" is one "inch" etc.

BTW how the browsers handle that?

test/jdk/javax/swing/text/html/CSS/HtmlFontSizeTest.java line 28:

> 26:  * @key headful
> 27:  * @summary  Verifies if HTML font size too large with high-DPI scaling and W3C_UNIT_LENGTHS
> 28:  * @run main/othervm -Dsun.java2d.uiScale=1.0 HtmlFontSizeTest

Can we skip this flag and additionally check the multi screen configuration in the test?

-------------

PR: https://git.openjdk.java.net/jdk/pull/1628


More information about the swing-dev mailing list