Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasting unicode emoji to a text component makes component lose AA #179

Closed
tropicaldev opened this issue May 2, 2019 · 8 comments

Comments

@tropicaldev
Copy link

commented May 2, 2019

using:

  • radiance 1.0.2 (version compatible with java 8)
  • Java 1.8u192
  • Win 10

When pasting text that has unicode chars like emojis to a text component, that component loses anti-aliasing.

Setting to system look and feel the text component don't lose anti-aliasing.

@DanielWebelsiep

This comment has been minimized.

Copy link

commented May 2, 2019

I think it is the same problem like #178. The AntiAliasing font settings in Neon does not work correctly. All standard L&Fs stores the font AA settings in the UIManager.getDefaults() table. In Radiance the font AA settings are only set by NeonCortex class during rendering.

For example the MetalLookAndFeel and WindowsLookupAndFeel calling SwingUtilities2.putAATextInfo(lafCond, table) in initComponentDefaults(UIDefaults table) method to initialize the font AA settings. The SubstanceLookAndFeel does not do that, because StringUtilities2 is private since java 9. But the AA settings from the UIManager.getDefault(RenederingHint.KEY_TEXT_ANTIALIASING) are used to initialize the font metrics and font rendering. In NeonContex class only the GraphicsConfiguration is modified with desktop hints, so rendering works most times. But the font metrics for the text cursor are running without AA settings so the pixel position is wrong, The component size is also calculated without AA. Then starting the application the FontStrikeDescription is created without AA and cached in the private Strike cache. If a breakpoint is set into sun.font.FontStrikeDesc.getAAHintIntVal(Font2D, Font, FontRenderContext) it can be analysed. The AntiAliasing hint is always OFF with SubstanceLookAndFeel. I modified SubstanceLookupAndFeel and copy code from SwingUtilities2 to fix problem #178.

protected void initComponentDefaults(UIDefaults table) {
    SubstanceCortex.GlobalScope.initFontDefaults(table);
    this.skin.addCustomEntriesToTable(table);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
	Map<Object, Object> desktopHints = (Map<Object, Object>) toolkit.getDesktopProperty("awt.font.desktophints");

    Object aaHint = desktopHints.get(RenderingHints.KEY_TEXT_ANTIALIASING);
    if (aaHint == null
            || aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF
            || aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) 
	{
        // do nothing
    }
	else
	{
        table.put(RenderingHints.KEY_TEXT_ANTIALIASING, aaHint);
        table.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, desktopHints.get(RenderingHints.KEY_TEXT_LCD_CONTRAST));
    }		
}
@tropicaldev

This comment has been minimized.

Copy link
Author

commented May 2, 2019

I tested with the suggested fix but the problem persists.

Note that i had to include the initial super.initComponentDefaults(table) or else an exception is thrown because some components needs to have some defaults (like Jtree indents ) when instanciated.

DanielWebelsiep, I assume you are not experiencing the same problem when pasting an emoji to a textcomponent...what's your Radiance and Java versions?

@kirill-grouchnikov

This comment has been minimized.

Copy link
Owner

commented May 2, 2019

I'll add the code from Daniel in 2.5-SNAPSHOT tonight. I can't comment on whether this might fix it for older Radiance releases.

It's definitely not something that is part of the "official" anti-aliasing documentation at https://docs.oracle.com/javase/9/docs/api/java/awt/doc-files/DesktopProperties.html. Not sure what's the "official" source for JDK classes these days. The fix proposed above relies on what https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.desktop/share/classes/sun/swing/SwingUtilities2.java is doing in OpenJDK 11. That seems to be different from https://github.com/frohoff/jdk8u-jdk/blob/master/src/share/classes/sun/swing/SwingUtilities2.java, so that fix might not indeed work on earlier versions of Java.

And for that matter, it might not work on any version - since this is all undocumented and relying on the particular implementation details. From my point of view, this should really be populated by BasicLookAndFeel and not by "leaf" core look-and-feel classes, as that would effectively provide correct support for third-party look-and-feels.

@tropicaldev

This comment has been minimized.

Copy link
Author

commented May 2, 2019

i just looked at java 8 laf srcs...

To work in radiance 1.0.2 with java 8 the fix needs to be:

protected void initComponentDefaults(UIDefaults table) {
    
    super.initComponentDefaults(table);
    SubstanceCortex.GlobalScope.initFontDefaults(table);
    this.skin.addCustomEntriesToTable(table);

    //fix
    //https://github.com/kirill-grouchnikov/radiance/issues/179
    Object aaTextInfo = SwingUtilities2.AATextInfo.getAATextInfo(true);
    table.put(SwingUtilities2.AA_TEXT_PROPERTY_KEY, aaTextInfo);  

}

no change to have the fix in the latest version of radiance that suports java 8?

@kirill-grouchnikov

This comment has been minimized.

Copy link
Owner

commented May 2, 2019

Both 2.0 and 2.5-SNAPSHOT require Java 9 as the minimum.

@DanielWebelsiep

This comment has been minimized.

Copy link

commented May 2, 2019

We migrate from Java 8 to Java 11 for our upcoming release. To test the fix I used Adopt OpenJDK 11.0.3+7 and the Radiance 2.0.1 source code. The changes on java 9 to support high dpi displayes with http://openjdk.java.net/jeps/263 should explain the code differences.

@kirill-grouchnikov

This comment has been minimized.

Copy link
Owner

commented May 2, 2019

This particular one is not about high dpi displays. It is about platform-consistent text antialiasing that has been available since Java 6 - https://docs.oracle.com/javase/6/docs/api/java/awt/doc-files/DesktopProperties.html

However, this specific area has not exposed any additional APIs that third-party look-and-feel providers need to maintain consistent text rendering (antialiasing, current desktop font family, style and size, etc). So there's a lot of hacks in Substance to try and maintain that consistency (that is missing, afaict from Metal and Nimbus). These are hacks because they rely on something that is, unfortunately, semi-private undocumented implementation details.

kirill-grouchnikov added a commit that referenced this issue May 3, 2019
Latest fixes
* Kotlin -> 1.3.31
* Kotlin coroutines -> 1.2.1
* Gradle -> 5.4.1
* Remove SVNKit version (no longer used)
* Lucent - Kotlin equivalent of Lumen - #169
* More additions for ribbon keyboard traversal - #159
* Fix / workaround for text antialiasing - #179
@DanielWebelsiep

This comment has been minimized.

Copy link

commented May 3, 2019

I could verify the bugfix and also #178 with java 11 on windows 10 with Radiance 2.5-SNAPSHOT. I had to change the standard font to Sansserif under Window to support our Unicode test String.
"mmm Text ߀äüöÄÜÖ čšžČŠŽ Пасха это は区理知の 😉 😊 😋 😎 AA"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.