Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8346988

Poor font rendering in JavaFX SwingNode

XMLWordPrintable

    • x86_64
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      $ cat /etc/issue
      Antergos Linux \r (\l)

      $ uname -a
      Linux hostname 6.12.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 27 Dec 2024 14:24:37 +0000 x86_64 GNU/Linux

      $ java --version
      openjdk 23.0.1 2024-10-15
      OpenJDK Runtime Environment (build 23.0.1+13)
      OpenJDK 64-Bit Server VM (build 23.0.1+13, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      Font rendering is no longer crisp for a JavaFx SwingNode.

      This happened after an operating system update on December 23. Here are the packages that were updated (sorry, I haven't tracked down what package may be the problem):

      7zip-24.09-3
      amdvlk-2024.Q4.3-1
      appstream-1.0.4-1
      audit-4.0.2-3
      avahi-1:0.8+r194+g3f79789-3
      bind-9.20.4-1
      boost-libs-1.86.0-4
      botan2-2.19.5-2
      botan-3.6.1-2
      breeze-icons-6.9.0-1
      brotli-1.1.0-3
      btrfs-progs-6.12-2
      c-ares-1.34.4-1
      catatonit-0.2.1-1
      clang-18.1.8-5
      cmake-3.31.3-1
      curl-8.11.1-3
      dbus-1.16.0-1
      device-mapper-2.03.29-1
      egl-wayland-4:1.1.17-1
      egl-x11-1.0.0-1
      exo-4.20.0-2
      fakeroot-1.36.2-1
      ffmpeg-2:7.1-5
      firefox-133.0.3-2
      garcon-4.20.0-2
      gcc-14.2.1+r134+gab884fffe3fc-2
      gcc-fortran-14.2.1+r134+gab884fffe3fc-2
      gcc-libs-14.2.1+r134+gab884fffe3fc-2
      gdal-3.10.0-4
      glab-1.51.0-1
      glib2-2.82.4-2
      gobject-introspection-runtime-1.82.0-2
      gpgme-1.24.1-3
      graphviz-12.1.2-2
      gst-plugins-bad-libs-1.24.10-2
      gst-plugins-base-1.24.10-2
      gst-plugins-base-libs-1.24.10-2
      gst-plugins-good-1.24.10-2
      gst-plugins-ugly-1.24.10-2
      gstreamer-1.24.10-2
      gtk4-1:4.16.7-3
      gtk-update-icon-cache-1:4.16.7-3
      icu-75.1-2
      imagemagick-7.1.1.43-1
      imath-3.1.12-2
      inkscape-1.4-3
      jemalloc-1:5.3.0-5
      js128-128.5.1-1
      json-glib-1.10.6-1
      karchive-6.9.0-1
      kauth-6.9.0-1
      kbd-2.7.1-1
      kbookmarks-6.9.0-1
      kcmutils-6.9.0-1
      kcodecs-6.9.0-1
      kcolorscheme-6.9.0-1
      kcompletion-6.9.0-1
      kconfig-6.9.0-1
      kconfigwidgets-6.9.0-1
      kcoreaddons-6.9.0-3
      kcrash-6.9.0-1
      kdbusaddons-6.9.0-1
      kglobalaccel-6.9.0-1
      kguiaddons-6.9.0-3
      ki18n-6.9.0-2
      kiconthemes-6.9.0-1
      kio-6.9.0-1
      kirigami-6.9.0-1
      kitemmodels-6.9.0-1
      kitemviews-6.9.0-1
      kjobwidgets-6.9.0-1
      knotifications-6.9.0-3
      kservice-6.9.0-1
      kwallet-6.9.0-1
      kwidgetsaddons-6.9.0-4
      kwindowsystem-6.9.0-1
      kxmlgui-6.9.0-3
      lensfun-1:0.3.4-5
      lib32-dbus-1.16.0-1
      lib32-gcc-libs-14.2.1+r134+gab884fffe3fc-2
      lib32-glib2-2.82.4-1
      lib32-libgpg-error-1.51-1
      lib32-libldap-2.6.9-1
      lib32-libtirpc-1.3.6-1
      lib32-libxcursor-1.2.3-1
      lib32-systemd-257.1-1
      libblockdev-3.2.1-3
      libblockdev-crypto-3.2.1-3
      libblockdev-fs-3.2.1-3
      libblockdev-loop-3.2.1-3
      libblockdev-mdraid-3.2.1-3
      libblockdev-nvme-3.2.1-3
      libblockdev-part-3.2.1-3
      libblockdev-swap-3.2.1-3
      libbytesize-2.8-4
      libcaca-0.99.beta20-5
      libcamera-0.3.2-2
      libcamera-ipa-0.3.2-2
      libcap-ng-0.8.5-3
      libdisplay-info-0.2.0-2
      libfabric-2.0.0-1
      libfbclient-4.0.5.3140-1
      libgexiv2-0.14.3-2
      libgirepository-1.82.0-2
      libgit2-glib-1.2.0-5
      libice-1.1.2-1
      libieee1284-0.2.11-18
      libimobiledevice-1.3.0-15
      libixion-0.19.0-4
      libjpeg-turbo-3.1.0-1
      libkcddb-24.12.0-1
      libmediainfo-24.12-1
      libmupdf-1.25.2-1
      libnautilus-extension-47.1-2
      libnewt-0.52.24-3
      libnghttp3-1.7.0-1
      libngtcp2-1.10.0-1
      libnm-1.50.1-1
      libnvme-1.11.1-2
      liborcus-0.19.2-4
      libpeas-1.36.0-6
      libplist-2.6.0-2
      libreoffice-still-24.2.7-4
      libseccomp-2.5.5-4
      libsixel-1.10.3-7
      libsm-1.2.5-1
      liburcu-0.15.0-1
      libvoikko-4.3.2-4
      libvpl-2.14.0-1
      libvpx-1.15.0-1
      libwbclient-2:4.21.2-3
      libwebp-1.5.0-1
      libxau-1.0.12-1
      libxcvt-0.1.3-1
      libxfce4ui-4.20.0-3
      libxfce4util-4.20.0-2
      libxfce4windowing-4.20.0-3
      libxml2-2.13.5-2
      libxrender-0.9.12-1
      libxshmfence-1.3.3-1
      libxslt-1.1.42-2
      libxv-1.0.13-1
      libxxf86vm-1.1.6-1
      lilv-0.24.24-3
      linux-6.12.7.arch1-1
      linux-firmware-20241210.b00a7f7e-1
      linux-firmware-whence-20241210.b00a7f7e-1
      linux-headers-6.12.7.arch1-1
      llvm-18.1.8-5
      llvm-libs-18.1.8-5
      lvm2-2.03.29-1
      mediainfo-24.12-1
      mesa-1:24.3.2-1
      mkinitcpio-39.2-3
      mlt-7.28.0-4
      mpg123-1.32.10-1
      netpbm-10.86.44-1
      net-snmp-5.9.4-6
      networkmanager-1.50.1-1
      nftables-1:1.1.1-2
      ninja-1.12.1-2
      nvidia-565.77-9
      nvidia-utils-565.77-2
      onetbb-2022.0.0-2
      opencl-clover-mesa-1:24.3.2-1
      opencl-headers-2:2024.10.24-1
      opencl-nvidia-565.77-2
      opencl-rusticl-mesa-1:24.3.2-1
      openjpeg2-2.5.3-1
      openmpi-5.0.6-2
      openpmix-5.0.5-1
      pahole-1:1.28-3
      pcsclite-2.3.1-1
      perl-http-message-7.00-1
      perl-uri-5.31-1
      php-8.3.15-1
      php-cgi-8.3.15-1
      php-fpm-8.3.15-1
      poppler-24.12.0-1
      poppler-glib-24.12.0-1
      postgresql-libs-16.6-1
      procps-ng-4.0.5-1
      proj-9.5.1-1
      protobuf-29.2-1
      protobuf-c-1.5.0-10
      prrte-3.0.8-1
      python-3.13.1-1
      python-appdirs-1.4.4-11
      python-beautifulsoup4-4.12.3-3
      python-cachecontrol-1:0.14.1-2
      python-cairo-1.27.0-2
      python-certifi-2024.12.14-1
      python-chardet-5.2.0-6
      python-charset-normalizer-3.4.0-5
      python-coverage-7.6.9-1
      python-cssselect-1.2.0-8
      python-dbus-1.3.2-5
      python-filelock-3.16.1-2
      python-gobject-3.50.0-2
      python-idna-3.10-2
      python-lockfile-0.12.2-14
      python-lxml-5.3.0-2
      python-msgpack-1.0.5-3
      python-numpy-2.2.1-2
      python-packaging-24.2-3
      python-pillow-11.0.0-3
      python-pycups-2.0.4-3
      python-pyserial-3.5-7
      python-requests-2.32.3-4
      python-six-1.16.0-10
      python-soupsieve-2.6-2
      python-urllib3-1.26.20-4
      python-zstandard-0.23.0-2
      qscintilla-qt5-2.14.1-4
      qt6-multimedia-6.8.1-2
      qt6-multimedia-ffmpeg-6.8.1-2
      redshift-1.12-14
      scour-0.38.2-5
      solid-6.9.1-2
      sqlite-3.47.2-1
      sudo-1.9.16.p2-2
      system-config-printer-1.5.18-5
      systemd-257.1-1
      systemd-libs-257.1-1
      systemd-sysvcompat-257.1-1
      talloc-2.4.2-4
      tcl-8.6.16-1
      tdb-1.4.12-2
      thunar-4.20.0-2
      thunar-archive-plugin-0.5.2-5
      thunar-volman-4.20.0-2
      thunderbird-128.5.1-1
      tinysparql-3.8.2-2
      tk-8.6.16-1
      tumbler-4.20.0-2
      util-linux-2.40.2-2
      util-linux-libs-2.40.2-2
      v4l-utils-1.28.1-2
      vapoursynth-R70-2
      vim-9.1.0954-1
      vim-runtime-9.1.0954-1
      volume_key-0.3.12-10
      vulkan-tools-1.4.303-2
      webkitgtk-6.0-2.46.5-1
      wine-9.22-1
      xcb-proto-1.17.0-3
      xfce4-appfinder-4.20.0-2
      xfce4-battery-plugin-1.1.6-1
      xfce4-mailwatch-plugin-1.3.2-1
      xfce4-notifyd-0.9.6-4
      xfce4-panel-4.20.0-4
      xfce4-pulseaudio-plugin-0.4.9-2
      xfce4-session-4.20.0-5
      xfce4-settings-4.20.0-3
      xfce4-taskmanager-1.5.8-1
      xfce4-terminal-1.1.4-1
      xfconf-4.20.0-2
      xfdesktop-4.20.0-7
      xfwm4-4.20.0-2
      xorg-server-21.1.15-1
      xorg-server-common-21.1.15-1
      xorg-server-devel-21.1.15-1
      xorg-server-xephyr-21.1.15-1
      xorg-server-xnest-21.1.15-1
      xorg-server-xvfb-21.1.15-1


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      wget -q -nc https://repo1.maven.org/maven2/org/jsoup/jsoup/1.18.3/jsoup-1.18.3.jar
      wget -q -nc https://repo1.maven.org/maven2/org/xhtmlrenderer/flying-saucer-core/9.11.2/flying-saucer-core-9.11.2.jar
      wget -q -nc https://repo1.maven.org/maven2/org/slf4j/slf4j-simple/2.1.0-alpha1/slf4j-simple-2.1.0-alpha1.jar
      wget -q -nc https://repo1.maven.org/maven2/org/slf4j/slf4j-api/2.1.0-alpha1/slf4j-api-2.1.0-alpha1.jar

      readonly CLASSPATH=$(find -name "*.jar" | tr "\n" ":")

      javac -classpath $CLASSPATH FlyingSourceTest.java
      java -classpath $CLASSPATH FlyingSourceTest


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Program compiles. Program runs. Font is crisp.
      ACTUAL -
      Font looks terrible. Letters are partly bold, lines are missing rows of pixels, and scrolling results in incomplete clearing of the view port. Probably easiest to see using a screen shot:

      See: <screenshot-1>

      See: <screenshot-2>

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.embed.swing.SwingNode;
      import javafx.scene.Scene;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;
      import org.jsoup.Jsoup;
      import org.jsoup.helper.W3CDom;
      import org.xhtmlrenderer.simple.XHTMLPanel;

      import javax.swing.*;

      import static javax.swing.SwingUtilities.invokeLater;
      import static javax.swing.UIManager.getSystemLookAndFeelClassName;
      import static javax.swing.UIManager.setLookAndFeel;

      public class FlyingSourceTest extends Application {
        static {
          System.setProperty("slf4j.internal.verbosity", "WARN");
        }

        private final static String HTML =
          """
          <html><head></head><body><h1 id="release">Release</h1>
          <h2 id="epilogue">Epilogue</h2>
          <h3 id="xander-angelos">Xander Angelos</h3>
          <p>A national security operative of the U.S. government once proposed rationing food in developing nations to restrict population growth. Starve people today to prevent people from starving tomorrow. How brilliant. Decades later, researchers learned that empowering women to make educated decisions about their own wombs reduces birth rates. Imagine that.</p>
          <p>Yet neither idea slays the bargainless beast that binds us. Hunger, humanity&rsquo;s everlasting, unrelenting stressor is timeless and impelling. Hunger calls us all to consume, to feed malignant, corporate machines.</p>
          </body></html>
          """;

        public static void main( String[] args ) {
          launch( args );
        }

        @Override
        public void start( Stage primaryStage ) {
          invokeLater( () -> {
            try {
              setLookAndFeel( getSystemLookAndFeelClassName() );
            } catch( Exception ignored ) {}

            primaryStage.setTitle( "Hello World!" );

            final var renderer = new XHTMLPanel();
            renderer.getSharedContext().getTextRenderer().setSmoothingThreshold( 0 );
            renderer.setDocument( new W3CDom().fromJsoup( Jsoup.parse( HTML ) ) );

            final var swingNode = new SwingNode();
            swingNode.setContent( new JScrollPane( renderer ) );

            StackPane root = new StackPane();
            root.getChildren().add( swingNode );

            Platform.runLater( () -> {
              primaryStage.setScene( new Scene( root, 300, 250 ) );
              primaryStage.show();
            } );

            primaryStage.setOnCloseRequest( _ -> {
              Platform.exit();
              System.exit( 0 );
            } );
          } );
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None.

      FREQUENCY : always


        1. lib.zip
          1.53 MB
        2. screenshot-1.png
          screenshot-1.png
          28 kB
        3. screenshot-2.png
          screenshot-2.png
          38 kB
        4. Test.java
          2 kB

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: