今天正好在看一段代码,然后突发其想用gvim打开,居然色彩渲染得不错,便顺手用来打印。发现报错:
1 2 |
E365: 无法打印 PostScript 文件 E365: Failed to print Postscript File |
于是仔细看了一下,应该是没指定打印设备,
1 2 |
set pdev=mylpserver :hardcopy |
去打印机旁把纸拿过来,看着打印效果还成,但上面的中文全都成了乱码了(倒问号),
回来继续捣腾,花了半天时间终于把中文乱码的问题解决了,网上的可借鉴资料不多,写下来希望对别人有些帮助。
相关环境/软件版本:
1 2 3 |
kernel-2.6.43.2-6.fc15.i686 vim-X11-7.3.315-1.fc15.i686 ghostscript-9.04-7.fc15.i686 |
配置步骤:
分析gvim利用lpr的调用来打印成ps,这边中文的问题主要出现在gs部分,因为平时利用其他软件打印均无此问题。
1. 启用ghostscript中文支持
yum install ghostscript-chinese-zh_CN
这个软件包,主要是在/usr/share/ghostscript/conf.d/下生成一个可用的配置文件cidfmap.zh_CN ,该文件指向的中文字体是附带的wqy-zhenhei.*
(此处仅以wqy-zhenhei为例,可自行配置cidfmap.zh_CN文件来选择自己需要的字体)
2. 配置gvim,以配合gs的格式
(此处BousungEG-Light-GB见配置文件cidfmap.zh_CN)
1 2 3 4 |
set printencoding=utf-8 set printmbcharset=ISO10646 set printmbfont=r:BousungEG-Light-GB,c:yes "BousungEG-Light-GB : ha > /tmp/asm0.ps |
3. 按步骤打印成ps文件,利用gs来查看。发现出错
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$gs /tmp/asm0.ps GPL Ghostscript 9.04 (2011-08-05) Copyright (C) 2011 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Can't find (or can't open) font file /usr/share/ghostscript/9.04/Resource/Font/NimbusMonL-Regu. Can't find (or can't open) font file NimbusMonL-Regu. Can't find (or can't open) font file /usr/share/ghostscript/9.04/Resource/Font/NimbusMonL-Regu. Can't find (or can't open) font file NimbusMonL-Regu. Querying operating system for font files... Loading NimbusMonL-Regu font from /usr/share/fonts/default/Type1/n022003l.pfb... 2680004 1338134 5111676 3100639 1 done. Loading NimbusMonL-Bold font from /usr/share/fonts/default/Type1/n022004l.pfb... 2797148 1460673 5128340 3123882 1 done. Loading NimbusMonL-ReguObli font from /usr/share/fonts/default/Type1/n022023l.pfb... 2914292 1572133 5145004 3146946 1 done. Loading NimbusMonL-BoldObli font from /usr/share/fonts/default/Type1/n022024l.pfb... 3031436 1684788 5161668 3169984 1 done. Loading a TT font from /usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc to emulate a CID font BousungEG-Light-GB ... Done. Can't find CMap UniGB-UCS2-H building a CIDDecoding resource. Error: /undefinedresource in findresource Operand stack: _CF0 UniGB-UTF8-H BousungEG-Light-GB CIDFont true BousungEG-Light-GB false BousungEG-Light-GB --dict:24/26(G)-- GB1.Unicode CIDDecoding true GB1.Unicode --dict:28/48(ro)(G)-- UniGB-UCS2-H Execution stack: ....... Dictionary stack: --dict:1153/1684(ro)(G)-- --dict:0/20(G)-- --dict:122/200(L)-- --dict:20/26(ro)(G)-- --dict:18/25(ro)(G)-- --dict:16/25(ro)(G)-- Current allocation mode is global Last OS error: 2 Current file position is 5614 GPL Ghostscript 9.04: Unrecoverable error, exit code 1 |
4. 按照出错提示
1 2 |
Can't find CMap UniGB-UCS2-H building a CIDDecoding resource. Error: /undefinedresource in findresource |
5. 检查我手上的TeXLive包的cmap设置,发现相关的文件都有,所以直接拿来建一个软链
1 |
# ln -s /usr/suse/texlive/texmf-local/fonts/cmap/ /usr/share/ghostscript/9.04/Resource/CMap |
6. 重新查看ps文件 一切正常。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$gs /tmp/asm0.ps GPL Ghostscript 9.04 (2011-08-05) Copyright (C) 2011 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Can't find (or can't open) font file /usr/share/ghostscript/9.04/Resource/Font/NimbusMonL-Regu. Can't find (or can't open) font file NimbusMonL-Regu. Can't find (or can't open) font file /usr/share/ghostscript/9.04/Resource/Font/NimbusMonL-Regu. Can't find (or can't open) font file NimbusMonL-Regu. Querying operating system for font files... Loading NimbusMonL-Regu font from /usr/share/fonts/default/Type1/n022003l.pfb... 2680004 1338134 5111676 3100639 1 done. Loading NimbusMonL-Bold font from /usr/share/fonts/default/Type1/n022004l.pfb... 2797148 1460673 5128340 3123882 1 done. Loading NimbusMonL-ReguObli font from /usr/share/fonts/default/Type1/n022023l.pfb... 2914292 1572133 5145004 3146946 1 done. Loading NimbusMonL-BoldObli font from /usr/share/fonts/default/Type1/n022024l.pfb... 3031436 1684788 5161668 3169984 1 done. Loading a TT font from /usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc to emulate a CID font BousungEG-Light-GB ... Done. >>showpage, press <return> to continue<< |