On Mon, 25 Jan 2021 16:22:33 GMT, Matthias Perktold <github.com+7334069+mperkt...@openjdk.org> wrote:
> @prsadhuk asked me to take over his pull request #1628, since I filed the bug > an suggested this fix. > > I thought the current behavior would be buggy, but actually the units are > quite precise. I checked the size of a text in font-size of 1 in, and it > really was approximately 1 inch. The problem is just that browsers behave > differently. > > Swing follows the CSS 2.1 spec: > https://www.w3.org/TR/CSS21/syndata.html#length-units. > But in CSS 2.2, length units where redefined: > https://www.w3.org/TR/CSS22/syndata.html#length-units. > Now `px` is also an absolute unit, and there are constant conversion factors > between all absolute units. > > The CSS 2.2 spec includes the following two notes regarding this change: > >> Note that if the anchor unit is the pixel unit, the physical units might not >> match their physical measurements. Alternatively if the anchor unit is a >> physical unit, the pixel unit might not map to a whole number of device >> pixels. > >> Note that this definition of the pixel unit and the physical units differs >> from previous versions of CSS. In particular, in previous versions of CSS >> the pixel unit and the physical units were not related by a fixed ratio: the >> physical units were always tied to their physical measurements while the >> pixel unit would vary to most closely match the reference pixel. (This >> change was made because too much existing content relies on the assumption >> of 96dpi, and breaking that assumption breaks the content.) > > So the spec changed the behavior to better support high-DPI devices with > existing content, and that is exactly my intention with this PR as well. src/java.desktop/share/classes/javax/swing/JEditorPane.java line 1567: > 1565: /** > 1566: * Key for a client property used to indicate whether > 1567: * <a href="https://www.w3.org/TR/CSS22/syndata.html#length-units"> Does this change require a CSR? test/jdk/javax/swing/text/html/HtmlFontSizeTest.java line 42: > 40: > 41: public class HtmlFontSizeTest { > 42: static Rectangle w3cFrameSize, stdFrameSize; These fields are accessed from two different threads. Shall they be declared as `volatile` then? Declaring each field on its own line would follow the Java Code Conventions. test/jdk/javax/swing/text/html/HtmlFontSizeTest.java line 92: > 90: System.out.println("frame height without W3C:" + stdFrameSize); > 91: > 92: float ratio = (float)w3cFrameSize.width/(float)stdFrameSize.width; Spaces around / operator. Java Code Conventions recommend “casts should be followed by a blank,” however, it's not always followed. Suggestion: float ratio = (float)w3cFrameSize.width / (float)stdFrameSize.width; test/jdk/javax/swing/text/html/HtmlFontSizeTest.java line 96: > 94: > 95: String str = String.format("%.1g%n",ratio); > 96: if (str.compareTo(String.format("%.1g%n",1.3f)) != 0) { “A comma should appear after commas in argument lists.” Suggestion: String str = String.format("%.1g%n", ratio); if (str.compareTo(String.format("%.1g%n", 1.3f)) != 0) { test/jdk/javax/swing/text/html/HtmlFontSizeTest.java line 2: > 1: /* > 2: * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. Suggestion: * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. ------------- PR: https://git.openjdk.java.net/jdk/pull/2223