mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.14k stars 235 forks source link

The same font is blurred by shape? #697

Closed xcfdszzr closed 2 years ago

xcfdszzr commented 2 years ago

Dear author, how should I handle this problem, online urgent waiting

         <!-- Transparent control-less frame -->
            <style type="rootpane" id="common-frame-transparent" extends="frame">
                <ui>
                    <installComponents>false</installComponents>
                </ui>
                <painter>

                    <decorations>
                        <decoration>
        <!--                    <WebShape round="4,4,2,2"/>-->
                            <WebShadow color="0,0,0" type="outer" opacity="0.5" width="30"/>
                        </decoration>
                        <decoration states="focused">
                            <WebShadow type="outer" opacity="0.5"/>
                        </decoration>
                        <decoration states="maximized">
                            <WebShape round="0"/>
                            <WebShadow type="outer" width="0"/>
                            <LineBorder opacity="0"/>
                        </decoration>
                        <decoration states="fullscreen">
                            <WebShape round="0"/>
                            <WebShadow type="outer" width="0"/>
                            <LineBorder opacity="0"/>
                        </decoration>
                        <decoration states="unix">
                            <WebShape round="0"/>
                            <WebShadow type="outer" width="0"/>
                            <LineBorder opacity="0"/>
                        </decoration>
                    </decorations>
                </painter>
                <style type="panel" id="content" extends="transparent"/>
            </style>

image image

                      final String title = getExampleLanguagePrefix () + "content";
                      final JFrame frame = new JFrame ();
                      UILanguageManager.registerComponent ( frame.getRootPane (), title );
                      frame.getRootPane ().putClientProperty ( StyleId.STYLE_PROPERTY, getStyleId () );
                      frame.setIconImages ( WebLookAndFeel.getImages () );
                      WebLabel aaaaaaaarpa = new WebLabel("AAAAAAAARPA简单简单应用问题", WebLabel.CENTER);
                      aaaaaaaarpa.setFont(new Font("微软雅黑", Font.BOLD,16));

                      WebLabel aaaaaaaarpa2 = new WebLabel("AAAAAAAARPA简单简单应用问题", WebLabel.CENTER);
                      aaaaaaaarpa2.setFont(new Font("宋体", Font.BOLD,16));
                      frame.getContentPane().setLayout(new BorderLayout());
                      frame.getContentPane().add(aaaaaaaarpa);
                      frame.getContentPane().add(aaaaaaaarpa2,BorderLayout.NORTH);
                      frame.setAlwaysOnTop ( true );
                      frame.setSize ( 500, 400 );
                      frame.setLocationRelativeTo ( DemoApplication.getInstance () );
                      frame.setDefaultCloseOperation ( WindowConstants.DISPOSE_ON_CLOSE );
                      frame.setVisible ( true );

issus : The same font is blurred by shape

             StyleId.frameDecorated Shape displays the font

image

           StyleId.of("common-frame-transparent")    No shape property to display font

image

mgarin commented 2 years ago

The reason why font is blurry on the decorated frame vs undecorated one is that different font antialiasing technique is being used. Blurry one is a grayscale antialias (default Swing implementation):

image

The crisp one is a subpixel font antialias (native implementation):

image

Unfortunately this is a known JDK issue - subpixel font antialias simply doesn't work on non-opaque destinations, which non-opaque window is. You can check this issue for more details: #130

There are some potential workarounds for this that can maybe be done in WebLaF, but so far I didn't find an optimal way to implement them without having some major drawbacks for performance or usability.

I could suggest a couple of options to avoid this issue:

Unfortunately neither of these solves the problem, these are all workarounds until we either get a better support for subpixel antialias in JDK, or I find a way to workaround it within the library.

Generally it's been a while since the last time I've looked into this issue, so I'll try to find some time and peek at possible solutions again - maybe there are some new developments on that front, or maybe I've missed something.

xcfdszzr commented 2 years ago

@mgarin
image

  Dear author, can you provide a custom label component to handle this, or can a higher JDK handle this problem?  

  Anxious processing font this problem, online anxious waiting process.....
mgarin commented 2 years ago

Unfortunately I don't have any solution for this right now. Also as far as I know - higher JDK versions have the same issue.

xcfdszzr commented 2 years ago

@mgarin

image

I am so sad about this question, but thank you for your answer. Please inform me if there is any future plan

mgarin commented 2 years ago

I recommend you to subscribe for #130 notifications, I'll be posting updates there once there will be any. Will be closing this issue for now as a duplicate.