Java, Semeru Runtimes and Runtimes for Business

Java, Semeru Runtimes and Runtimes for Business

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

Thai font issue in IBM Semeru and OpenJDK

By Satya Satpathy posted 2 days ago

  

Co-authors: Paul Cheeseman, Ravi Patel, Syed Moinudeen

Problem
This article originates from a problem we investigated where some users of the IBM Semeru Runtime were not able to properly view Thai characters on the Windows operating system. The IBM Semeru Runtimes is generally a drop-in replacement for any OpenJDK based Java distribution, providing a no-cost Java runtime environment optimised for performance with broad platform support, so this improper display of Thai characters on Windows was a bit of a surprise. Instead of the expected Thai characters, users may see blank squares or rectangular placeholders commonly referred to as "tofu" which indicate that the system is unable to render the text properly. This typically occurs because the runtime cannot find a font that supports the Thai script. The issue can be reproduced with a simple standalone Java program, as shown below.

Example Java program

import javax.swing.*;
import java.awt.*;
public class ThaiFontTest {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame("Thai Font Rendering Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(400, 200);
            String thaiText = "\u0E2A\u0E27\u0E31\u0E14\u0E35";
            JLabel label = new JLabel(thaiText, SwingConstants.CENTER);
            label.setFont(new Font("Dialog", Font.PLAIN, 24));
            frame.getContentPane().add(label);
            frame.setVisible(true);
        });
    }
}

If you have not installed IBM Semeru Runtimes on your system, it's really easy with SDKMAN. The below commands can be used to install IBM Semeru 21 and to check java version.

sdk install java 21.0.6-sem

$ java -version
openjdk version "21.0.6" 2025-01-21 LTS
IBM Semeru Runtime Open Edition 21.0.6.0 (build 21.0.6+7-LTS)
Eclipse OpenJ9 VM 21.0.6.0 (build openj9-0.49.0, JRE 21 Mac OS X aarch64-64-Bit 20250121_371 (JIT enabled, AOT enabled)
OpenJ9   - 3c3d179854
OMR      - e49875871
JCL      - e01368f00df based on jdk-21.0.6+7)

As shown below, blank squares or rectangular placeholders may be displayed instead of the expected Thai characters:

The IBM Semeru Runtime, like other distributions based on OpenJDK, depends on operating system fonts for rendering Thai characters, and this problem occurs when the required "DokChampa" font on Windows is not available.

Solution

To resolve the problems caused by the missing font, IBM Semeru Runtimes or OpenJDK users should install the DokChampa font in their Windows operating system. This font is available as part of the Lao Supplemental Fonts package.

Other partial solutions exist, for example modification of the Runtime’s fontconfig.properties file to use an alternative font for Thai characters, but this approach does not provide support for all Thai/Lao characters. Installing the Lao Supplemental Fonts package ensures full support.

Why does the DokChampa font need to be installed?

The IBM Semeru 11, OpenJDK 11 or later releases use the DokChampa font to display the Thai characters. In prior releases Lucida Sans Regular was used instead.

Microsoft typography documentation

The Microsoft typography documentation describes supported languages for each Windows font, including DokChampa and Lucida Sans. This states that DokChampa supports the Thai language, while Lucida Sans does not.

Font Name

Design language

Supported Language

DokChampa

'Thai', 'Laoo'

'Thai', 'Laoo', 'Latn'

Lucida Sans

'Cyrl', 'Grek', 'Hebr', 'Latn'

'Cyrl', 'Grek', 'Hebr', 'Latn'

Installing the DokChampa font

Please follow the Microsoft documentation to understand the steps required to install the Lao Supplemental Fonts package.

After the installation of Lao Supplemental Fonts, the Java test program provided above will display the Thai characters successfully:

Conclusion

The IBM Semeru 11, OpenJDK 11 or later use the DokChampa font to display Thai characters on Windows, as recommended by the Microsoft typography documentation. However, this font may not be installed by default. In order to display Thai characters in Java programs on Windows, users need to install the Lao Supplemental Fonts optional feature, which includes the DokChampa font. IBM Semeru Runtimes can be downloaded for free, even for production use, from here.

References

0 comments
83 views

Permalink