GMT Chinese support in Linux
Native GMT does not support Chinese characters. To enable GMT to support Chinese characters, some configuration is required. To understand the entire problem, you need to have a deeper understanding of the PostScript and CID fonts, which is a little too complicated. This blog post only introduces some basic principles, which are not necessarily accurate but adequate.
It is not difficult to modify the configuration. The trouble is that different releases have different packaging methods for ghostscript, and there are some differences between different ghostscript versions. The system information I am using is listed here. It has some reference significance for other releases and gs versions.
- Operating System: CentOS 7.0
- Ghostscript: 9.07
- GMT: 4.5.12 or 5.1.1 (take 4.5.12 as an example)
Preparations for installing gs
For most releases, gs is installed by default. The related file is located in/Usr/share/ghostscriptDirectory. In addition, you also need to install the Simplified Chinese configuration file.
The packages of the Chinese configuration files vary with different releases:
CentOS 7:
$ sudo yum install ghostscript-chinese-zh_CN
CentOS 6:
$ sudo yum install cjkuni-fonts-ghostscript
Ubuntu 14.04:
$ sudo apt-get install poppler-data
Ubuntu 12.04:
$ sudo apt-get install gs-cjk-resource
After the corresponding package is installed, the Directory of the Chinese configuration file is also different.Conf. dDirectory:
- CentOS 6, 7:/Usr/share/ghostscript/conf. d
- Ubuntu 12.04, 14.04:/Etc/ghostscript/cidfmap. d/90gs-cjk-resource-gb1.conf
Install GMT
You don't need to talk about this step. The GMT after installation is located/Opt/GMT-4.5.12The file related to the font is/Opt/GMT-4.5.12/share/pslib/PS_font_info.d.
Make gs support Chinese
In the following description, all paths are subject to the CentOS release.
Cidfmap
EnterConf. dDirectory with filesCidfmap. zh_CN(This directory also containsCIDFnmap. zh_CNAndFAPIcidfmap. zh_CN, No matter), the content is:
/BousungEG-Light-GB << /FileType /TrueType /Path (/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc) /SubfontId 0 /CSI [(GB1) 4] >> ;/GBZenKai-Medium << /FileType /TrueType /Path (/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc) /SubfontId 0 /CSI [(GB1) 4] >> ;/MSungGBK-Light /BousungEG-Light-GB ;/Adobe-GB1 /BousungEG-Light-GB ;
The details may not be understood, but the general (xia) knot (cai) is as follows:
- The first line defines the font name/BousungEG-Light-GB, The corresponding font file is/Usr/share/fonts/wqy-zenhei/wqy-zenhei.ttcThat is, wenquanyi zhenghei;
- The second row defines the font name/GBZenKai-Medium, The corresponding font file is also 文;
- The third and fourth rows define the font names respectively./MSungGBK-LightAndAdobe-GB1, Both correspond/BousungEG-Light-GB, Which is equivalent to defining an alias for the font.
The following points must be mentioned about this file:
- The font name is arbitrary. For example, the font name can be set/ABC;
- The font file only seems to beTtcOrTtfOf course, you may also use fonts in other formats to modify parameters;
- Because the Chinese fonts in Linux are not uniform, check whether the font file path in the configuration file is correct;
CMap
CMap is located in/Usr/share/ghostscript/9.07/Resource/CMapDirectory, you can see that there are many files, the specific meaning of the CMap file is unknown. Stay here for the moment. You only need to know thatUniGB-UTF8-HAndGB-EUC-HThe two cmaps can be used.
Test gs's support for Chinese Fonts
Linux has few Chinese fonts. Many may copy Chinese fonts in Windows to Linux. Assume that the Chinese font in Windows has been copied/Usr/share/fonts/winfonts/Directory, the gs configuration fileCidfmap. zh_CNMake some modifications so that gs can use the Windows Chinese font in Linux:
% Cidfmap. original contents remain unchanged in zh_CN/BousungEG-Light-GB </FileType/TrueType/Path (/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc) /SubfontId 0/CSI [(GB1) 4]>;/GBZenKai-Medium </FileType/TrueType/Path (/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc) /SubfontId 0/CSI [(GB1) 4]>;/MSungGBK-Light/BousungEG-Light-GB;/Adobe-GB1/BousungEG-Light-GB; % added support for Windows fonts/STSong-Light </FileType/TrueType/Path (/usr/share/fonts/winfonts/simsun. ttc)/SubfontId 0/CSI [(GB1) 4] >>;/STFangsong-Light </FileType/TrueType/Path (/usr/share/fonts/winfonts/simfang. ttf)/SubfontId 0/CSI [(GB1) 4] >>;/STHeiti-Regular </FileType/TrueType/Path (/usr/share/fonts/winfonts/simhei. ttf)/SubfontId 0/CSI [(GB1) 4] >>;/STKaiti-Regular </FileType/TrueType/Path (/usr/share/fonts/winfonts/simkai. ttf)/SubfontId 0/CSI [(GB1) 4]>;
Use the editor to create a PS file (yes, the PS file contains plain text, which can be edited directly in the editor !), NameGs_test.ps, The content is:
%! PS-Adobe-3. 0/STSong-Light -- UniGB-UTF8-H findfont 20 scalefont setfont150 400 moveto (Song Typeface show) show/STFangsong-Light -- UniGB-UTF8-H findfont 20 scalefont setfont150 375 moveto (Fangsong Typeface) show/STHeiti-Regular -- UniGB-UTF8-H findfont 20 scalefont setfont150 350 moveto (Hei Typeface) show/STKaiti-Regular -- UniGB-UTF8-H findfont 20 scalefont setfont150 325 moveto (Kai Typeface) showshowpage % Trailer % EOF
Use gs to view the PS file. If Chinese characters are correctly displayed, the Chinese configuration of gs is correct.
Note the following points:
- Here, we only use the Windows Font as an example. The method is similar for other Chinese characters, even Japanese and Korean fonts;
- The Chinese font in the PS file isCIDFont -- CMapHere, CMap selectsUniGB-UTF8-HIn Windows, it seems that you should chooseGB-EUC-H, The principle is unclear;
Enable GMT to support modifying configuration files in Chinese
Open the GMT Chinese configuration file/Opt/GMT-4.5.12/share/pslib/PS_font_info.dAdd the following statement at the end of the file (taking the Windows Font as an example ):
STSong-Light--UniGB-UTF8-H 0.700 1STFangsong-Light--UniGB-UTF8-H 0.700 1STHeiti-Regular--UniGB-UTF8-H 0.700 1STKaiti-Regular--UniGB-UTF8-H 0.700 1
The first column is the font name, the second column is the height of the letter A, and the third column is related to the encoding.
View the fonts currently supported by GMT
UsePstext-LCommand to view the current GMT font configuration:
1 2 3 4 5 6 7 8 910111213 |
$ pstext -LFont # Font Name------------------------------------0 Helvetica1 Helvetica-Bold... ......32 Palatino-BoldItalic33 ZapfChancery-MediumItalic34 ZapfDingbats35 STSong-Light--UniGB-UTF8-H36 STFangsong-Light--UniGB-UTF8-H37 STHeiti-Regular--UniGB-UTF8-H38 STKaiti-Regular--UniGB-UTF8-H |
0-34 is the Spanish font supported by GMT/gs by default, and 35-38 is the newly added Chinese font.
GMT Chinese test
GMT4 test script:
1 2 3 4 5 6 7 8 91011 |
#! /Bin/bashgmtset HEADER_FONT 35 pstext-R0/7/0/7-JX6i/6i-B1/1 :. "GMT Chinese support":-P> cn. ps <EOF1.5 5 35 0 35 lm gmt 1.5 1.5 4 35 0 36 lm gmt 1.5 3 35 0 37 lm gmt 2 35 0 38 lm gmt eoeofrm. gmt * |
The graph effect is as follows:
GMT5 test script:
1 2 3 4 5 6 7 8 91011 |
#! /Bin/bashgmt gmtset FONT_TITLE 40 p, 35, blackgmt pstext-R0/7/0/7-JX6i/6i-Bafg-B + t "GMT Chinese support"-F + a + c + f-P> gmt5_cn.ps <EOF3.5 5 0 LM 45 p, 35, red GMT 3.5 3.5 4 0 LM 45 p, 36, blue GMT Imitation Song 3.5 3 0 LM 45 p, 37, black GMT 2 0 LM 45 p, 38, green GMT eoeofrm gmt. * |
The graph effect is as follows:
Portability tests
- Local Machine: Use vi to open the PS file and display Chinese properly;
- Local Machine: gs check is normal;
- Local Machine: ps2raster is converted to PDF and can be viewed normally with evince and zathura;
- Local Machine: ps2pdf is converted to PDF, which can be viewed normally with evince and zathura;
Because no other machine is available, no portability test is available for the moment.
This article permanently updates the link address: