Enable the Java SDK to support Chinese Characters in Linux

Source: Internet
Author: User
1. Cause
JDK needs to read the font list from the font configuration file. The default font list does not contain any Chinese font.

2. Solution
Add a Chinese font to the JDK font configuration file

3. Procedure

3.1. Copy the font file to the JDK font directory.

CD/usr/local/Java/JRE/lib/Fonts
CP/usr/share/fonts/zh_cn/TrueType/gbsn00l. TTF.

3.2. Generate a font list file

Ttmkfdir-O fonts. dir

3.3. view the newly generated fonts. dir file and view the section about gbsn00l. TTF.

VI fonts. dir

3.4. It should be in the last line of the file

-Arphic Technology Co.-ar PL sungtil GB-Medium-r-normal -- 0-0-0-0-p-0-ascii-0

3.5. Return to the previous directory and add gbsn00lp. TTF to font. properties.

CD ..
VI font. Properties

3.6. Add method:
3.6.1 first, copy the line of text shown in section 3.4 and copy
Change 0-0-0-0-p-0 to *-% d-*-p -*
The purpose is to scale the font proportionally, which is now:

-Arphic Technology Co.-ar PL sungtil GB-Medium-r-normal -- *-% d-*-p-*-ascii-0

3.6.2 the font. properties file already contains 0 and 1 fonts. For example, if the first line is serif.0 and the second line is serif.1, you need to add

Serif.2 =-arphic Technology Co.-ar PL sungtil GB-Medium-r-normal -- *-% d-*-p-*-ascii-0

3.6.3 add xxxx.2 under each xxxx.1 until the # Missing glyph character of the file.

3.6.4 after the instance is added, save the disk and exit.

3.7. Add the environment variable java_fonts

VI/etc/profile

Java_fonts = $ java_home/JRE/lib/Fonts

3.8. Log On again to make the environment variable take effect

4. Test

Testchsgraphic. Java (jdk1.3)
ImportJava. AWT .*;ImportJava. AWT. image .*;
ImportJava. Io .*;ImportJava. util .*;
ImportCom.sun.image.codec.jpeg .*;
Public ClassTestchsgraphic {Public StaticVoidMain(String [] ARGs)ThrowsException {system.Setproperty("Java. AWT. Headless", "true"); bufferedimage Bi =New Bufferedimage(200,100, bufferedimage. type_int_rgb); graphics G = Bi.Getgraphics(); String S = "Chinese test ";// Note! The specific transcoding may be different!G.Drawstring(New String(S.Getbytes(), "Gb2312"), 50, 50); bi.Flush(); Fileoutputstream Fos =New Fileoutputstream("Test.jpg"); your imageencoder must Ie = Your codec.Createjpegencoder(FOS); IE.Encode(BI); FOS.Close();}}
Testchsgraphic. Java (jdk1.4)
ImportJava. AWT. graphics;ImportJava. AWT. bufferedimage;ImportJavax. ImageIO. ImageIO;
ImportJava. Io .*;
Public ClassTestchsgraphic {Public StaticVoidMain(String [] ARGs)ThrowsException {system.Setproperty("Java. AWT. Headless", "true"); bufferedimage Bi =New Bufferedimage(200,100, bufferedimage. type_int_rgb); graphics G = Bi.Getgraphics(); String S = "Chinese test ";// Note! The specific transcoding may be different!G.Drawstring(New String(S.Getbytes(), "Gb2312"), 50, 50); ImageIO.Write(Bi, "Jpeg ",New File("Test.jpg "));}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.