On Fri, 18 Sep 2026 18:57:28 GMT, Martin Fox <[email protected]> wrote:

>> This PR attempts to improve LCD text rendering on Windows and Linux. Changes 
>> include:
>> 
>> - (Windows only) When setting up DirectWrite the code now uses the 
>> NATURAL_SYMMETRIC rendering mode except for very small glyphs where it uses 
>> NATURAL. Using NATURAL_SYMMETRIC avoids distorted glyphs at specific pixel 
>> sizes (see [JDK-8389632](https://bugs.openjdk.org/browse/JDK-8389632)) and 
>> retains the curves along the top and bottom of the glyphs. Using NATURAL at 
>> small sizes avoids glyphs turning very fuzzy and light.
>> 
>> - The code is now consistently converts the colors from sRGB to a linear 
>> space (more or less), composites them, and then converts the result back to 
>> sRGB.
>> 
>> - The shader applies a contrast equation to the LCD glyph mask which helps 
>> emphasize the stems. The same equation is used by Skia and probably added by 
>> Microsoft when they cleaned up text rendering for Chromium. BTW it’s just 
>> the equation for a parabola that goes through points (0, 0) and (1, 1).
>> 
>> My testing was mostly done on a 27 inch display with a resolution of 
>> 2560x1440 and a screen scale of 150%. This was low enough to notice a 
>> difference. Resolutions higher than that (like full-on Retina) tend to hide 
>> a lot of sins.
>> 
>> I recommend reading “The Raster Tragedy in Skia” which is concise but covers 
>> a lot of ground. It contains a section on the challenges of compositing text 
>> in sRGB space and also the issues getting LCD text to look dark enough 
>> without inflating the stems. I wish I had found this earlier in the process.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Martin Fox has updated the pull request with a new target base due to a merge 
> or a rebase. The incremental webrev excludes the unrelated changes brought in 
> by the merge/rebase. The pull request contains eight additional commits since 
> the last revision:
> 
>  - Merge remote-tracking branch 'upstream/master' into fontwork
>  - Glyph shaping and LCD rendering changes require system properties
>  - Added Swing version of the cascade
>  - Added manual text rendering test
>  - Upped contrast and adjusted it for white-on-black text
>  - Merge remote-tracking branch 'upstream/master' into fontwork
>  - Slight tweak to natural/symmetric choice
>  - LCD text rendering is sharper and on Windows less likely to create 
> distorted glyphs

thank you for adding the properties!  I presume no properties set means results 
in the existing behavior?

modules/javafx.graphics/src/main/java/com/sun/javafx/font/PrismFontFactory.java 
line 63:

> 61:     private static boolean lcdEnabled;
> 62:     private static float lcdContrast = -1;
> 63:     private static boolean newLCDRendering;

I'd suggest renaming it to something more meaningful

modules/javafx.graphics/src/main/java/com/sun/javafx/font/PrismFontFactory.java 
line 135:

> 133:         lcdEnabled = lcdProp.equals("true");
> 134:         String lcdRenderProp = System.getProperty("prism.lcdrendering", 
> "default");
> 135:         newLCDRendering = lcdEnabled && lcdRenderProp.equals("new");

I wonder if a different, more descriptive value would be better than "new".  
What if in the future there is something newer than "new"?

modules/javafx.graphics/src/main/java/com/sun/javafx/font/PrismFontFactory.java 
line 138:

> 136: 
> 137:         String glyphShapingProp = 
> System.getProperty("prism.glyphshaping", "default");
> 138:         symmetricGlyphs = glyphShapingProp.equals("symmetric");

can we get these new properties documented somewhere?

specifically, I'd like to see
1. full property name
2. possible values, default value when the property is not specified
3. brief explanation of the property effect on rendering, assuming the user has 
no prior background
4. applicable platforms (explaining differences between the platforms, if any)

a set of screenshots illustrating different options might also be good.  Maybe 
we could create /doc-files/graphics/ and put an .md file there?

modules/javafx.graphics/src/main/java/com/sun/prism/impl/ps/BaseShaderContext.java
 line 532:

> 530:     public Shader validateLCDOp(BaseShaderGraphics g, BaseTransform 
> xform,
> 531:                                 Texture tex0, Texture tex1, boolean 
> firstPass,
> 532:                                 boolean newLCDRendering, Paint fillColor)

"new"...

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

PR Review: https://git.openjdk.org/jfx/pull/2284#pullrequestreview-5251898185
PR Review Comment: https://git.openjdk.org/jfx/pull/2284#discussion_r4050173865
PR Review Comment: https://git.openjdk.org/jfx/pull/2284#discussion_r4050134062
PR Review Comment: https://git.openjdk.org/jfx/pull/2284#discussion_r4050167325
PR Review Comment: https://git.openjdk.org/jfx/pull/2284#discussion_r4050188234

Reply via email to