Java Jdk-awt.font in CentOS on the problem of Chinese characters, install Chinese fonts

Source: Internet
Author: User

There is a need to generate a two-dimensional code, and there is a text description, but the use of awt.font into Chinese, there has been garbled problem. There are several solutions on the Web, but the following are the methods that are useful for testing on CentOS.

The Java code is as follows: New Java.awt.Font ("Song Body", font.bold,13);

1, copy SIMSUN.TTC from windows (some say suffix ttf, no test), copy to/usr/share/fonts, you can create a new folder, such as I created a Chinese, that is, the path is/user/share/ Fonts/chinese

2, upload SIMSUN.TTC to/usr/share/fonts/chinese, execute chmod 777 SIMSUN.TTC (Modify Execute permission)

3, execute FC-CACHE-FV under/usr/share/fonts/chinese path, install font to System

4, execution fc-list can see the fonts that have been installed, and can see the fonts installed.

5, restart Tomcat.

The previous idea has been to use the Java.awt.Font public static Font createfont (int fontformat,file fontfile) method to do, That is, the introduction of a TTF file (renamed SIMSUN.TTC to Simsun.ttf, this place must be a TTF suffix or error), because this is the API code level implementation, without altering the server environment, but has been unsuccessful

1. Download the font file (*.ttf file) you want to install from your native C:\Windows\Fonts copy or network to the/usr/share/fonts/chinese/truetype directory (if you do not have this directory on your system, you mkdir create it yourself , or rename it to the folder name you like)

2, modify the permissions of the font file, so that users other than the root user can also use

# Cd/usr/share/fonts/chinese/truetype
# chmod 755 *.ttf

3. Create Font Cache

# Mkfontscale (if prompted Mkfontscale:command not found, you need to install it yourself # Yum install Mkfontscale)
# Mkfontdir
# FC-CACHE-FV (if prompted Fc-cache:command not found, you need to install # Yum installs Fontconfig)

4. Restart the computer
# reboot

Java Jdk-awt.font in CentOS on the problem of Chinese characters, install Chinese fonts

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.