Today encountered a garbled problem, the composition of the small ticket picture of the Chinese all became a mouth mouth, and later on the Internet to check the data, found that graphics2d used italicized word, and the Linux server does not have a corresponding font library.
The local font library is uploaded to solve the problem.
Local Font Library location: (WinXP italicized word) C:\WINDOWS\FONTS\SIMSUN.TTC
SIMSUN.TTC renamed to Simsun.ttf
RZ command (need to install in advance, other ways also line) copy to linux:/usr/java/jdk1.7.0_79/jre/lib/fonts/
Reference Document: http://ember319.iteye.com/blog/254015
The following is the original content
Problem Description:
Users log in to our system, when ordering products, we need to download a picture from the server side, displayed on the phone screen, the picture may contain Chinese and English characters, depending on the situation. Results test down, English no problem, Chinese print as block.
Environment Description:
The development platform is WinXP and the test environment is SOLARIS10.
Data Source:
The information used to print to the picture is obtained from another system via the Web Serice.
=====
Let's talk about the idea of the solution,
1, whether the problem of character encoding
In order to check the correct encoding of the obtained string, the following method is used to try a variety of character set encoding conversions, but none of them are effective;
Java code
- String message= "..."; information obtained by//WS
- New String (Message.getbytes ("UTF8"),"GBK");
Back to carefully consider our system, the system's JSP page and database encoding are used UTF-8 code, whether it is input, save or display no Chinese garbled problem, especially between the system using WS-Mode synchronization data, there is no garbled problem, The information that WS obtains is also UTF-8 encoded. In order to verify this idea, a JSP page was made, using Utf-8 to display the information obtained, and to display the Chinese correctly without any conversion. Finally, it is not a problem of character set encoding.
2, whether the printing process has been a problem
Looking at the description of the JDK API, I found that when using fonts, I did not specifically set, using the default font. Write a simple output platform default font class, the resulting font is the same information:
Java code
- Default font:java.awt.font[family=dialog,name=dialog,style=plain,size=]
So go online to find "Java drawstring Chinese garbled" keyword information, find a message csdn: http://topic.csdn.net/u/20080603/13/ 3590c1f9-30bc-4e4d-bb2a-ada472b05973.html. You can go and see it, I won't put it over. My actions are:
1) Specify the font to be printed to the picture in Chinese
Java code
- G2d.setfont (new Font ("Arial", Font.plain, 12));
2) Upload the italicized Word file from the WinXP to the server (Solaris)
My local font file address is "C:\WINDOWS\FONTS\SIMSUN.TTC", upload to the server address is: "/USR/JDK/INSTANCES/JDK1.5.0/JRE/LIB/FONTS/SIMSUN.TTC"
3) Verify that the small squares on the image are displayed correctly in Chinese by verifying the program
Printing pictures in Chinese garbled problem is solved here.
Consider, because the printing character becomes the picture, need to use the pixel arrangement, if the font is wrong, there is no way to print ah.
Graphics2D Chinese Characters