Configuring Chinese Font Support for GMT5 on Ubuntu 16.04
Prerequisites
- Operating System: Ubuntu 16.04 LTS
- Ghostscript Version: 9.18
- GMT Version: 5.4.1
Step 1: Font File Transfer
Transfer the following commonly-used Chinese font files from a Windows system (located in C:\Windows\Fonts) to your Ubuntu machine:
simsun.ttc(SimSun - Song Typeface)simfang.ttf(SimFang - Fangsong Typeface)simhei.ttf(SimHei - Hei Typeface)simkai.ttf(SimKai - Kai Typeface)
Copy these files to the /usr/share/fonts/ directory on your Ubuntu system.
Step 2: Ghostscript Chinese Font Configuration
Installing Required Packages
First, ensure the necessary Ghostscript Chinese font support package is installed:
sudo apt-get update
sudo apt-get install poppler-data
Locating the Configuration File
The Ghostscript Chinese font configuration file resides at:
/etc/ghostscript/cidfmap.d/90gs-cjk-resource-gb1.conf
Installing Linux Default CJK Fonts
Install the default Chinese fonts that Ghostscript expects:
sudo apt-get install fonts-arphic-uming fonts-arphic-ukai
Modifying the Configuration
The default configuration file contains entries for four font names that ultimately point to the same underlying fonts. You need to modify this file to support both Linux defaults and your Windows fonts.
Original content (remove lines related to STSong-Light and similar fonts):
/BousungEG-Light-GB <</FileType /TrueType /Path (/usr/share/fonts/truetype/arphic/uming.ttc) /SubfontId 0 /CSI [(GB1) 4]>> ;
/GBZenKai-Medium <</FileType /TrueType /Path (/usr/share/fonts/truetype/arphic/ukai.ttc) /SubfontId 0 /CSI [(GB1) 4]>> ;
/Song-Medium /GBZenKai-Medium ;
/Adobe-GB1 /BousungEG-Light-GB ;
/Adobe-GB1-Bold /GBZenKai-Medium ;
Add Windows font mappings after the existing content:
/STSong-Light <</FileType /TrueType /Path (/usr/share/fonts/simsun.ttc) /SubfontId 0 /CSI [(GB1) 4]>> ;
/STFangsong-Light <</FileType /TrueType /Path (/usr/share/fonts/simfang.ttf) /SubfontId 0 /CSI [(GB1) 4]>> ;
/STHeiti-Regular <</FileType /TrueType /Path (/usr/share/fonts/simhei.ttf) /SubfontId 0 /CSI [(GB1) 4]>> ;
/STKaiti-Regular <</FileType /TrueType /Path (/usr/share/fonts/simkai.ttf) /SubfontId 0 /CSI [(GB1) 4]>> ;
Apply the changes by regenerating the font map:
sudo update-gsfontmap
This command merges all configuration files from /etc/ghostscript/cidfmap.d/*.conf into a single file at /var/lib/ghostscript/fonts/cidfmap. Ghostscript reads from this merged file rather than the individual configuration files—a key difference between Ubuntu/Debian and CentOS distributions.
Step 3: Verifying Linux Font Support in Ghostscript
Create a PostScript test file named linux_font_test.ps using a text editor:
%!PS-Adobe-3.0
/BousungEG-Light-GB--UniGB-UTF8-H findfont 20 scalefont setfont
150 400 moveto
(BousungEG Font) show
/GBZenKai-Medium--UniGB-UTF8-H findfont 20 scalefont setfont
150 375 moveto
(GBZenKai Font) show
/MSungGBK-Light--UniGB-UTF8-H findfont 20 scalefont setfont
150 350 moveto
(MSungGBK Font) show
/Adobe-GB1--UniGB-UTF8-H findfont 20 scalefont setfont
150 325 moveto
(Adobe Font) show
showpage
%%Trailer
%%EOF
To specify a Chinese font in PostScript, use the FontName--CMap format. The CMap parameter can be either UniGB-UTF8-H (common on Linux) or GB-EUC-H (common on Windows), determining the encoding scheme for Chinese characters.
Render the file with Ghostscript to verify proper display:
gs linux_font_test.ps
Note: Some fonts like MSungGBK-Light may not render correctly depending on your Ghostscript installation.
Step 4: Verifying Windows Font Support in Ghostscript
Create another PostScript test file named windows_font_test.ps:
%!PS-Adobe-3.0
/STSong-Light--UniGB-UTF8-H findfont 20 scalefont setfont
150 400 moveto
(Song Typeface - 宋体) show
/STFangsong-Light--UniGB-UTF8-H findfont 20 scalefont setfont
150 375 moveto
(Fangsong Typeface - 仿宋体) show
/STHeiti-Regular--UniGB-UTF8-H findfont 20 scalefont setfont
150 350 moveto
(Hei Typeface - 黑体) show
/STKaiti-Regular--UniGB-UTF8-H findfont 20 scalefont setfont
150 325 moveto
(Kai Typeface - 楷体) show
showpage
%%Trailer
%%EOF
Render this file with Ghostscript:
gs windows_font_test.ps
If Chinese characters display correctly, Ghostscript is properly configured to use Windows Chinese fonts.
Step 5: Configuring GMT for Chinese Font Support
Updating the GMT Font Configuration
Open the GMT custom fonts configuration file:
/opt/GMT-5.4.1/share/postscriptlight/PSL_custom_fonts.txt
Append the following entries to the end of the file (after the commented section):
STSong-Light--UniGB-UTF8-H 0.700 1
STFangsong-Light--UniGB-UTF8-H 0.700 1
STHeiti-Regular--UniGB-UTF8-H 0.700 1
STKaiti-Regular--UniGB-UTF8-H 0.700 1
The columns represent: font name, capital letter height scaling factor, and encoding flag.
Verifying GMT Font Registration
Check that GMT recognizes the newly added fonts:
pstext -L
The output should include entries 35-38 corresponding to your Chinese fonts:
Font # Font Name
------------------------------------
0 Helvetica
1 Helvetica-Bold
...
35 STSong-Light--UniGB-UTF8-H
36 STFangsong-Light--UniGB-UTF8-H
37 STHeiti-Regular--UniGB-UTF8-H
38 STKaiti-Regular--UniGB-UTF8-H
Creating a Test Plot
Execute the following Bash script to generate a test plot with Chinese text:
#!/bin/bash
gmt gmtset FONT_TITLE 40p,35,black
gmt pstext -R0/10/0/3 -JX15c/3c -Bafg -B+t"GMT Chinese Support" -F+a+c+f -P > gmt_chinese_test.ps << EOF
3 2.1 0 LM 35p,35,red GMT宋体
3 0.9 0 LM 35p,36,blue GMT仿宋
7 2.1 0 LM 35p,37,black GMT黑体
7 0.9 0 LM 35p,38,green GMT楷体
EOF
rm -f gmt.*
Open the generated gmt_chinese_test.ps file to verify that all four Chinese typefaces render correctly. The plot should display distinct fonts for Song, Fangsong, Hei, and Kai typefaces in their respective colors.