在 PS/EPS 和 ghostscript 中使用阿里巴巴普惠体

系统字体配置、中文显示和输入法问题
回复
头像
careone
帖子: 839
注册时间: 2007-12-17 21:41

在 PS/EPS 和 ghostscript 中使用阿里巴巴普惠体

#1

帖子 careone » 2019-12-16 12:11

在 PS/EPS 和 ghostscript 中使用阿里巴巴普惠体

2019-12-16

测试环境:
Debian 10.2 amd64
Ghostscript 9.27

字体版本:
阿里巴巴普惠体 1.10, 2019-7 月发布。包含 5款 TTF 字体格式的中文字体,以及11款 OTF 格式的西文字体。
说明:2019年4月发布的最初版本的字体包中,5款中文字体为 OTF 格式。不能用下面的配置方案,在 ghostscript 和 PS/EPS 文件中正常显示中文。

步骤:
1.从官网下载字体。说明:下载过程中,可能要求输入alibaba账号和密码。如:淘宝,天猫...帐号。
下载地址:
进入网址: https://alibabafont.taobao.com/ ,点屏幕上方的“官方字体”,进入下载页面。

2.解压缩字体包,并复制到指定目录。
运行命令:

sudo mkdir -p /usr/share/fonts/truetype/alibaba/

解压缩字体包后,可以看到两个压缩包,一个是中文字体包,继续解压缩,得到5款 TTF 格式(TrueType)的字体。
-------------------

代码: 全选

Alibaba-PuHuiTi-Bold.ttf
Alibaba-PuHuiTi-Heavy.ttf
Alibaba-PuHuiTi-Light.ttf
Alibaba-PuHuiTi-Medium.ttf
Alibaba-PuHuiTi-Regular.ttf
-------------------
把这5个 ttf 字体文件, 直接复制到上面新建的目录下。不用改字体文件名称。

另一个包是西文字体,解压后,可以得到11款 OTF 格式(OpenType)的sans 字体。
说明:对于中文用户,只需要5款 TTF 中文字体就可以。其它11款 sans 字体可以不用管。

3. 新建一个cidfmap字体配置文件
以 root 用户打开 /etc/ghostscript/cidfmap.d/ 文件夹,在下面新建一个 xxx.conf 文件。
如:86gs-cjk-alibaba-gb1.conf

文件内容如下:

代码: 全选

/Alibaba-PuHuiTi-Light <</FileType /TrueType /Path (/usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Light.ttf) /SubfontId 0 /CSI [(GB1) 5] >> ;
/Alibaba-PuHuiTi-Regular <</FileType /TrueType /Path (/usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Regular.ttf) /SubfontId 0 /CSI [(GB1) 5] >> ;
/Alibaba-PuHuiTi-Medium <</FileType /TrueType /Path (/usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Medium.ttf) /SubfontId 0 /CSI [(GB1) 5] >> ;
/Alibaba-PuHuiTi-Bold <</FileType /TrueType /Path (/usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Bold.ttf) /SubfontId 0 /CSI [(GB1) 5] >> ;
/Alibaba-PuHuiTi-Heavy <</FileType /TrueType /Path (/usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Heavy.ttf) /SubfontId 0 /CSI [(GB1) 5] >> ;

/SimSun /Alibaba-PuHuiTi-Medium
%/SimFang /Alibaba-PuHuiTi-Regular
%/SimKai /Alibaba-PuHuiTi-Light
/SimHei /Alibaba-PuHuiTi-Bold
说明:
1. 以 % 开头的是注释行。可以忽略。
2. 前5行,后面的 [(GB1) 5] 代表字符集版本。支持的数字有0-5共6种。简单地说,这个数字相当于字符集的版本号。5是目前最高版本。 0 相当于 gb2312简体中文编码。 1,2 相当于 gbk 中文编码。3,4 相当于 GB18030编码。5 是目前最高版本。
3.前5行,双连线 -- 前面的,代表字体名称(中间不要带空格)。后面的,代表字符集编码格式。
4.后面的4行:用来使用替代字体。比如说,最后一行,如果系统里没有安装 SimHei (相当于Windows 系统下的黑体),则把
Alibaba-PuHuiTi-Bold (粗体),当成黑体。

步骤3:更新配置
以 root 用户运行 update-gsfontmap
sudo update-gsfontmap

完成。

查看效果:
新建一个普通的 txt 文本文件,输入内容,保存为

xxx.ps

再用 okular, evince 等程序打开这个 PS 文件,即可查看中文字体的显示效果。
xxx.ps 示例内容如下:

代码: 全选

%!PS-Adobe-3.0
%%Title:
% original filename: sample-xxx-zh_CN.ps
% version 0.5, 2019-12-16 updated, by Careone

/Alibaba-PuHuiTi-Light--UniGB-UTF8-H findfont 20 scalefont setfont
80 750 moveto
(1. Alibaba-PuHuiTi-Light 阿里巴巴普惠体) show

/Alibaba-PuHuiTi-Regular--UniGB-UTF8-H findfont 20 scalefont setfont
80 725 moveto
(2. Alibaba-PuHuiTi-Regular 阿里巴巴普惠体) show

/Alibaba-PuHuiTi-Medium--UniGB-UTF8-H findfont 20 scalefont setfont
80 700 moveto
(3. Alibaba-PuHuiTi-Medium 阿里巴巴普惠体) show

/Alibaba-PuHuiTi-Bold--UniGB-UTF8-H findfont 20 scalefont setfont
80 675 moveto
(4. Alibaba-PuHuiTi-Bold 阿里巴巴普惠体) show

/Alibaba-PuHuiTi-Heavy--UniGB-UTF8-H findfont 20 scalefont setfont
80 650 moveto
(5. Alibaba-PuHuiTi-Heavy 阿里巴巴普惠体) show
%
%
/OPPOSans-Light--UniGB-UTF8-H findfont 20 scalefont setfont
80 625 moveto
(6. OPPOSans-Light 字体) show

/OPPOSans-Regular--UniGB-UTF8-H findfont 20 scalefont setfont
80 600 moveto
(7. OPPOSans-Regular 字体) show

/OPPOSans-Medium--UniGB-UTF8-H findfont 20 scalefont setfont
80 575 moveto
(8. OPPOSans-Medium 字体) show

/OPPOSans-Bold--UniGB-UTF8-H findfont 20 scalefont setfont
80 550 moveto
(9. OPPOSans-Bold 字体) show

/OPPOSans-Heavy--UniGB-UTF8-H findfont 20 scalefont setfont
80 525 moveto
(10. OPPOSans-Heavy 字体) show
%
%
/SimSun--UniGB-UTF8-H findfont 20 scalefont setfont
80 500 moveto
(11. SimSun 字体) show

/SimFang--UniGB-UTF8-H findfont 20 scalefont setfont
80 475 moveto
(12. SimFang 字体) show

/SimKai--UniGB-UTF8-H findfont 20 scalefont setfont
80 450 moveto
(13. SimKai 字体) show

/SimHei--UniGB-UTF8-H findfont 20 scalefont setfont
80 425 moveto
(14. SimHei 字体) show
%
%

showpage
%%Trailer
%%EOF
魁拔不死,天下不宁。
魁拔既死,天下不平。
--------------
Careone <emacslocale^126.com>
https://sourceforge.net/projects/emacslocale/files/
头像
careone
帖子: 839
注册时间: 2007-12-17 21:41

Re: 在 PS/EPS 和 ghostscript 中使用阿里巴巴普惠体

#2

帖子 careone » 2019-12-16 12:17

本来打个字体 DEB 包,方便 Ubuntu/Debian 用户直接安装使用的。看了一下官方的字体版本声明,想了想,还是算了。免得自找麻烦。
有兴趣的朋友,可以自己打包使用。这个提供几个打包相关的文件范例。仅供技术参考。

文件1: DEBIAN/control

代码: 全选

Package: fonts-alibaba-puhuiti-all
Version: 1.10
Architecture: all
Maintainer: anyone <fonts@alibaba.com>
Installed-Size: 40832
Depends:
Suggests:
Recommends: fonts-wqy-zenhei|ttf-wqy-zenhei,fonts-wqy-microhei|ttf-wqy-microhei
Conflicts:
Replaces:
Provides:
Section: fonts
Priority: optional
Multi-Arch: foreign
Homepage: https://ics.alibaba.com/project/Hn8mXx , https://alibabafont.taobao.com/
Description: Alibaba PuHuiTi fonts, version 1.10, 2019-7-04 updated. 阿里巴巴字体-普惠体
 Download 1: https://ics.alibaba.com/project/Hn8mXx
 .
 Download 2: https://alibabafont.taobao.com/
 .
 Download 3: https://aifont.alicdn.com/AlibabaPuHuiTi/AlibabaPuHuiTiAll.zip
 .
 copyright 
 版权申明
 *
 .
 1、阿里巴巴普惠体(中文字体,指定5款字重),Alibaba Sans(西文字体,指定11款字重),以下合称阿里巴巴字体,允许任何个人和企业免费使用,包括商用用途,但禁止用于违法用途。
 .
 Alibaba PuHuiTi (5 specific Chinese font styles), Alibaba Sans (11 specific English font styles), collectively referred to as “Alibaba Font”, is made available for download solely for use by individuals and corporates for free, including for commercial uses.
 .
 Any illegal activities are expressly prohibited.  
 *
 .
 2、阿里巴巴字体版权归属阿里巴巴(中国)有限公司,未经授权,任何人和第三方媒介不得上传、发布、转载字体文件,禁止售卖,违者必究。
 .
 Alibaba Font is the copyrighted work of Alibaba (China) Co., Ltd.  
 .
 No such font may be uploaded, published, reproduced and made available for sale, without Alibaba’s express prior written consent.
 .
 Violators will be prosecuted to the full extent of the law.
 *
 .
 3、为确保字体文件不被篡改,保障用户可以安全使用,请务必从阿里巴巴字体官方指定通道下载。
 .
 To ensure that the font files are not tampered, and can be used safely by users, please download the font files from Alibaba’s official channels.


文件2: DEBIAN/md5sum

代码: 全选

d15670956c3cfc0957394e67f164f4f6  etc/ghostscript/cidfmap.d/86gs-cjk-alibaba-gb1.conf
5f071dd2422eab994287b9bd32d71468  usr/share/doc/fonts-alibaba-puhuiti-all/copyright
47f6fa31504f3860816b3c14bfdf15a5  usr/share/doc/fonts-alibaba-puhuiti-all/changelog
abadcd6a8032a510623911db62bec3ae  usr/share/doc/fonts-alibaba-puhuiti-all/法务版权声明.pdf
f141f10e585d361634da248e7d5168fb  usr/share/doc/fonts-alibaba-puhuiti-all/Law Policy for Alibaba Sans.pdf
feef6258fcbd360737935302295fc3dd  usr/share/doc/ghostscript/examples/cjk/sample-alibaba-puhuiti-zh_CN.ps
38edfe1889c8ab6ad5c238d91aefa22b  usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Bold.ttf
9c3c7ede7aa81c3758ee84b606921e8d  usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Medium.ttf
67bc9f4f94dcd785a1875161666ae7ca  usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Light.ttf
c3a51600ca6f01be3192e72fcfa8e4ac  usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Heavy.ttf
8d591595ec48e06178ace5eddfcee21c  usr/share/fonts/truetype/alibaba/Alibaba-PuHuiTi-Regular.ttf
b88269075f30e1d116f4b31a37f172ee  usr/share/fonts/opentype/alibaba/AlibabaSans-Bold.otf
d0127631c3a103a832aa9880e66bf63a  usr/share/fonts/opentype/alibaba/AlibabaSans-LightItalic.otf
74862f98dc71da64604f6f904715a54d  usr/share/fonts/opentype/alibaba/AlibabaSans-Heavy.otf
98c26977f10e409e4cce3c8007d5226b  usr/share/fonts/opentype/alibaba/AlibabaSans-Black.otf
b09743b6c661b9e18eccdd14cad7c723  usr/share/fonts/opentype/alibaba/AlibabaSans-BoldItalic.otf
dfe44df8baf34c76858bf0561b370218  usr/share/fonts/opentype/alibaba/AlibabaSans-MediumItalic.otf
5c2607a35e212127014877144a8339dd  usr/share/fonts/opentype/alibaba/AlibabaSans-HeavyItalic.otf
5a157a55f91382ecaa17df2ea4cd5681  usr/share/fonts/opentype/alibaba/AlibabaSans-Italic.otf
a67b98a45e257b2187e093ed81a0da22  usr/share/fonts/opentype/alibaba/AlibabaSans-Medium.otf
08ae43389c18f8c82e580e3416a3d9aa  usr/share/fonts/opentype/alibaba/AlibabaSans-Light.otf
d8e0f0e535b49af5c0f1613cd6ae2ba8  usr/share/fonts/opentype/alibaba/AlibabaSans-Regular.otf
文件4: DEBIAN/postinst

代码: 全选

#!/bin/sh
# filename: postinst
# 2019-12-16 updated
 
d01="/usr/share/fonts/truetype/alibaba"
d02="/etc/ghostscript/cidfmap.d"

f01="fonts.scale"
f02="fonts.dir"

#f21="86gs-cjk-alibaba-gb1.conf"

echo " step 1: install fonts..."
cd "$d01"
/usr/bin/mkfontscale
/usr/bin/mkfontdir
/usr/bin/fc-cache
#cd -

sleep 1

echo " step 2: update-gsfontmap"
echo "   DIR: $d02/"
## sample: /etc/ghostscript/cidfmap.d/86gs-cjk-alibaba-gb1.conf
/usr/sbin/update-gsfontmap

echo " Done."

exit 0
文件4: DEBIAN/postrm

代码: 全选

#!/bin/sh
# filename: postrm
# 2019-12-16 updated
 
d01="/usr/share/fonts/truetype/alibaba"
d02="/etc/ghostscript/cidfmap.d"

f01="fonts.scale"
f02="fonts.dir"

#f21="86gs-cjk-alibaba-gb1.conf"

echo " step 1: clear files..."
cd "$d01"

if [ -f "$d01/$f01" ]; then
  rm -f "$d01/$f01"
fi

if [ -f "$d01/$f02" ]; then
  rm -f "$d01/$f02"
fi

/usr/bin/fc-cache
#cd -

sleep 1

echo " step 2: update-gsfontmap"
echo "   DIR: $d02/"
## sample: /etc/ghostscript/cidfmap.d/86gs-cjk-resource-gb1.conf
/usr/sbin/update-gsfontmap

echo " Done."

exit 0
魁拔不死,天下不宁。
魁拔既死,天下不平。
--------------
Careone <emacslocale^126.com>
https://sourceforge.net/projects/emacslocale/files/
回复