Yes, you can display both simplified and traditional Chinese text in Java if you have a font that includes both character sets.
I wrote this short program to demonstrate:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.util.ArrayList; import java.util.List; import javax.imageio.ImageIO; public class ChineseFonts { public static final int GAP = 35; public static final int FONTS_PER_LINE = 2; public ChineseFonts(String s) { Rectangle rect = new Rectangle(0, 0, 1024, 768); BufferedImage bufferedImage = new BufferedImage((int) Math.ceil(rect.getWidth()), (int) Math.ceil(rect.getHeight()), BufferedImage.TYPE_4BYTE_ABGR); Graphics graphics = bufferedImage.getGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(rect.x, rect.y, rect.width, rect.height); graphics.setColor(Color.BLUE); String title = "Chinese Fonts on " + System.getProperty("os.name") + ", version " + System.getProperty("os.version"); int fontY = 30; printString(title, graphics, 0, fontY, new Font(Font.SERIF, Font.BOLD | Font.ITALIC, 28), false); fontY += GAP + 10; int counter = 0; for (String fontName : new String[]{Font.MONOSPACED, Font.SANS_SERIF, Font.SERIF}) { Font font = new Font(fontName, Font.PLAIN, 24); printString(s, graphics, counter++, fontY, font, true); if (counter % FONTS_PER_LINE == 0) fontY += GAP; } Font[] localFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); List<Font> chineseFonts = new ArrayList<Font>(); String simplifiedAndTraditionalChinese = "????"; for (int j = 0; j < localFonts.length; j++) { if (localFonts[j].canDisplayUpTo(simplifiedAndTraditionalChinese) == -1) { chineseFonts.add(localFonts[j].deriveFont(24F)); } } for (Font font : chineseFonts) { printString(s, graphics, counter++, fontY, font, true); if (counter % FONTS_PER_LINE == 0) fontY += GAP; } graphics.dispose(); try { ImageIO.write(bufferedImage, "png", new File("chineseFonts.png")); } catch (Exception e) {
Two simplified and 2 traditional Chinese characters are used on the Wikipedia page on Chinese characters. When you run it, all used fonts are printed on stdout, and the image is displayed with font names and Chinese characters.
Here are three logical fonts and the first physical font that worked:
- Monospaced
- Sanserif
- Serif
- Arial Unicode MS S