LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 4888|回复: 7

Slackware 9.0的中文打印

[复制链接]
发表于 2003-8-6 09:52:43 | 显示全部楼层 |阅读模式
软硬件配置:
- 操作系统:Slackware 9.0
- 打印机:HP LaserJet 6L
- 打印服务程序:CUPS 1.1.18
- ghostscript 7.05
- Mozilla 1.4 中文版

说明:下面的操作几乎都需要root权限。

一、安装打印服务程序
Slackware 9.0 默认的打印服务程序是lpd,而现在更流行的是CUPS,设置也非常简单。可以到slackware下载的镜像站,在发行版本的 extra目录中下载,目前的版本是cups-1.1.18。用installpkg安装。
安装完毕后,会在/etc/rc.d/目录生成rc.cups文件,用root身份,运行 /etc/rc.d/rc.cups start ,即可启动cups打印服务。用浏览器访问 http://localhost:631/ 即可对cups和打印机进行设置,详情请看cups的文档。
添加打印机并成功打印出测试页之后,gedit和starsuite就直接能在我的HP LJ6L打印出中文。


二、设置ghostscript的中文支持
许多程序能够通过ghostscript生成postscript文件(.ps),如果能使ghostscript支持中文,就能够间接支持这些程序的中文打印。Slackware9.0自带的ghostscript是7.05版。

1. 下载CMap字体文件

ftp://ftp.gyve.org/pub/gs-cjk/adobe-cmaps-200211.tar.gz
ftp://ftp.gyve.org/pub/gs-cjk/acro5-cmaps-2001.tar.gz

把上面两个文件解压缩到/usr/share/ghostscript/Resource目录(如果没有这个目录,请自己mkdir)

cp adobe-cmaps-200211.tar.gz /usr/share/ghostscript/Resource
cp acro5-cmaps-2001.tar.gz /usr/share/ghostscript/Resource
tar zxvf adobe-cmaps-200211.tar.gz
tar zxvf acro5-cmaps-2001.tar.gz
rm *.gz

再建两个字体目录:
mkdir /usr/share/ghostscript/Resource/CIDFont /usr/share/ghostscript/Resource/Font


2.下载freetype-1.3.1(后面的ttfm需要)

http://sourceforge.net/project/showfiles.php?group_id=3157

下载源码,自行编译安装,完成后运行 ldconfig 更新库文件索引


3. 下载ttfm

http://www.linuxeden.com/download/softdetail.php?softid=650

下载 ttfm-1.0-6.i386.rpm 和 gscjk.ttfm

安装:
rpm -ivh ttfm-1.0-6.i386.rpm --nodeps
cp gscjk.ttfm /usr/share/fonts/install/


4.安装中文字体
我用的是ms windows提供的simsun.ttf, simhei.ttf, simkai.ttf 和simfang.ttf
把这四个字体放到 /usr/share/fonts/ttf目录中,也可以仅在这个目录里建立指向字体所在路径的符号链接。
然后:

cd /usr/share/fonts/install
ttfm.sh --initm gscjk.ttfm

这样就会在 /usr/share/ghostscript/Resource/CIDFont 和 /usr/share/ghostscript/Resource/Font 目录中生成对上面四种中文字体的描述文件。


5.让ghostscript启动时自动加载我们安装的中文字体

首先,修改 /usr/share/ghostscript/7.05/lib/gs_res.ps 文件,在其中找到这样两行:

/FontResourceDir (/usr/share/ghostscript/fonts/) readonly .forcedef
/GenericResourceDir (/usr/share/ghostcript/) readonly .forcedef  

改为:
/FontResourceDir (/usr/share/ghostscript/Resource/Font/) readonly .forcedef
/GenericResourceDir (/usr/share/ghostscript/Resource/) readonly .forcedef  

然后,建立CIDFnmap文件:
touch /usr/share/ghostscript/7.05/lib/CIDFnmap.zh
编辑这个文件,输入下面的内容:

  1. /SimSun (/usr/share/fonts/ttf/simsun.ttf) 1 ;
  2. /SimHei (/usr/share/fonts/ttf/simhei.ttf) 1 ;
  3. /FangSong_GB2312 (/usr/share/fonts/ttf/simfang.ttf) 1 ;
  4. /KaiTi_GB2312 (/usr/share/fonts/ttf/simkai.ttf) 1 ;

  5. /Adobe-GB1              /SimSun ;
  6. /STSong-Light           /SimSun ;
  7. /STFangsong-Light       /FangSong_GB2312 ;
  8. /STHeiti-Regular        /SimHei ;
  9. /STKaiti-Regular        /KaiTi_GB2312 ;
复制代码

这个文件指明了TrueType字体的路径,并建立了字体的别名。如果需要繁体中文,可以根据上面的原理自己添加Mingliu等字体。

最后,编辑/usr/share/ghostscript/7.05/lib/CIDFnmap,在文件末尾加入一行:

(CIDFnmap.zh) .runlibfile

6.测试

cd /usr/share/ghostscript/7.05/examples/cjk
gv gscjk_ag.ps

如果能看到四种字体的汉字,说明ghostscript简体中文字体设置成功。

三、设置mozilla支持中文打印
编辑 mozilla安装目录里面的/defauts/pref 目录下的 unix.js 文件,找到相应的行改成如下内容,如果没有这些行,自己增加。

pref("print.postscript.nativecode.zh-TW", "gbk");
pref("print.postscript.nativefont.zh-TW", "SimSun-GBK-EUC-H");
pref("print.postscript.nativecode.zh-CN", "gbk");
pref("print.postscript.nativefont.zh-CN", "SimSun-GBK-EUC-H");

完成后,存盘,重新启动mozilla。
如果直接让mozilla输出到打印机,中文不能正常打印而是以方框显示。因此需要采用间接的方法,打印时,选择打印到文件 mozilla.ps,然后:

ps2ps mozilla.ps out.ps
lpr out.ps

也可以先打印成mozilla.ps,然后选择菜单的“文件/打印/打印机属性”,在打印命令栏设定如下:

ps2ps mozilla.ps out.ps && lpr out.ps && rm mozilla.ps out.ps -f

以上命令输入一次后就不用再输入第二次了。再选直接打印到打印机,每次打印完后会把/home/USER目录下的mozilla.ps和out.ps文件删掉,以便下次打印其他文档。
这样就实现了mozilla的中文打印(谢谢kite兄指教)。


四、其他程序的中文打印
试验过gedit和starsuite6.0,均在安装cups并设置好打印机后,直接支持中文打印。
abiword的中文打印支持需另行设置,我没有测试,请参考最后附的参考文档。
其他的程序,如果直接打印不支持中文,可看看其是否有生成.ps文件的打印选项,然后尝试类似mozilla的方式进行打印。
基于qt的程序按上面的方法设置后似乎还不能支持中文打印,我测试过kedit,中文打印出来是乱码。

参考文档:《Slackware 8.1上的中文列印》
http://zope.slat.org/Members/Kea ... ack_cprint.stx/view
发表于 2003-8-6 10:10:28 | 显示全部楼层
Good idea
发表于 2003-8-6 23:39:02 | 显示全部楼层
发现这样可能省事点:先打印成mozilla.ps,然后在打印命令栏设定如下,
ps2ps mozilla.ps out.ps && lpr out.ps && rm mozilla.ps out.ps -f
以上命令输入一次后就不用再输入第二次了。然后选直接打印到打印机,每次打印完后会把/home/USER目录下的mozilla.ps和out.ps文件删掉,以便下次打印其他文档。

我记得以前在mozilla下不用这么麻烦的,设好打印命令,不用另现打印成ps,就点打印即可,我现在用mozillafirebird,不知是否不同。
 楼主| 发表于 2003-8-7 09:17:06 | 显示全部楼层
现在的mozilla也是不能直接执行兄弟上面说的那些打印命令。有人搞了个叫wprint的东西,是为了直接支持mozilla的中文打印的,但用在简体环境还有问题,主要是字体的设置,兄弟可以试试。
发表于 2003-8-7 09:39:42 | 显示全部楼层
对不能直接执行,但可以点打印成ps后再点直接打印即可,这样可能省事点。不知有没有哪位精通shell的编一个万全之脚本来个自动点的

关于wprint,我是试用过,打印效果是惨不忍睹,很多漏字现象。
 楼主| 发表于 2003-8-7 12:05:50 | 显示全部楼层
发现ghostscript不能正确解析MingLiU字体,笔划混乱。
繁体中文打印用文鼎字体才正常。
发表于 2003-12-18 18:07:28 | 显示全部楼层
Slackware 9.1/-current
Print Chinese with ghostscript and view Chinese with gv mini-Howto


(1) Software requirements:
   Install ghostscript (espgs-7.05.6), font (gnu-gs-fonts) and
ghostview (gv) packages


(2) Font requirements:
   Install SimSun, SimHei and other Chinese TTF fonts to XFree86
TTF font dir


(3) Hack the ghostscript:

   Backup file /usr/share/ghostscript/7.05/lib/CIDFnmap, then
modify it as follows:
    %(CIDFnmap.Win) .runlibfile
    % Add the following line
    (CIDFnmap.zhcn) .runlibfile

   Add file /usr/share/ghostscript/7.05/lib/CIDFnmap.zhcn as
follows:
------------------- cut here -------------------------------------------
/SimSun     (simsun.ttc)        ;
/STSong-Light           /SimSun         ;   
/Beijing                /SimSun         ;   
/NSimSun    (simsun.ttc)    2   ;
/Adobe-GB1              /SimSun         ;   
/song                   /SimSun         ;   
/zycjksun               /SimSun         ;   

/SimHei     (simhei.ttf)        ;
/STHeiti-Regular        /SimHei         ;
/hei                    /SimHei         ;
/zycjkhei               /SimHei         ;   

/SimFang    (simfang.ttf)       ;
/FangSong               /SimFang        ;   
/STFangsong-Light       /SimFang        ;   
/fang                   /SimFang        ;   
/zycjkfang              /SimFang        ;   

/SimKai     (simkai.ttf)        ;
/KaiTi                  /SimKai         ;   
/STKaiti-Regular        /SimKai         ;   
/kai                    /SimKai         ;   
/zycjkkai               /SimKai         ;   

/FZFangSong (fzfsjw.ttf)        ;
/FZWeiBei   (fzwbjw.ttf)        ;
/FZKai      (fzktjw.ttf)        ;
/FZShuTi    (fzstjw.ttf)        ;

/SIL-FangSong-          /STFangsong-Light   ;
/SIL-FangSong-Reg-Jian  /STFangsong-Light   ;
/SIL-Hei-Med-Jian       /STHeiti-Regular    ;
/SIL-Kai-               /STKaiti-Regular    ;
/SIL-Kai-Reg-Jian       /STKaiti-Regular    ;
/SIL-Song-Reg-Jian      /STSong-Light       ;
------------------- cut here -------------------------------------------

   Backup /usr/share/ghostscript/7.05/lib/gs_res.ps, then modify
it as follows:

    Find the following line
       /GenericResourceDir (/usr/share/ghostscript/) readonly .forcedef
    Replace it with the following line
       /GenericResourceDir (/usr/share/ghostscript/Resource/) readonly .forcedef


(4) Add Adobe CMAP for CID fonts to ghostscript

    Download ac14.tar.Z and ag14.tar.Z from the following link:
    ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/

    Execute the following commands:
    # cd /usr/share/ghostscript/
    # mkdir Resource
    # cd Resource
    # mkdir CMap
    # tar -zxvf /tmp/ac14.tar.Z
    # tar -zxvf /tmp/ag14.tar.Z
    # cp ac14/CMap/* ag14/CMap/* CMap
    # rm -rf ac14 ag14

    Alternatively, if you want the latest Adobe CMAP files, download
"Complete set of Adobe CMAP files for CID Fonts" in the "Adobe Font
Development Kit for OpenType" from adobe.com:
    http://partners.adobe.com/asn/tech/type/otfdk/index.jsp

    Execute the following commands:
    # cd /usr/share/ghostscript/
    # mkdir Resource
    # cd Resource
    # mkdir CMap
    # unzip /tmp/Adobe\ Cmaps.zip
    # cp Adobe\ Cmaps/Adobe-CNS1-2/* Adobe\ Cmaps/Adobe-CNS1-3/* \
      Adobe\ Cmaps/Adobe-CNS1-4/* Adobe\ Cmaps/Adobe-GB1-3/* \
      Adobe\ Cmaps/Adobe-GB1-4/* Adobe\ Cmaps/Adobe-Identity-0/* \
      CMap
    # rm -rf Adobe\ Cmaps

    Then create symbol links of the TrueType fonts in the ghostscript
fonts directory. I have tried to specify the full path of TrueType fonts
in CIDFnmap.zhcn instead of creating symbol links. However, it can only
make gv display Chinese. It's impossible to print Chinese!!!

    # cd /usr/share/ghostscript/fonts
    # ln -s /usr/X11R6/lib/X11/fonts/TTF/sim* .
    # ln -s /usr/X11R6/lib/X11/fonts/TTF/fz* .


(5) Hack Mozilla/Firebird preference file:
    Modify mozilla/default/pref/unix.js as follows:

    Look for the following line:
        pref("print.postscript.nativefont.zh-CN", "");

    Replace it with the following line:
        pref("print.postscript.nativecode.zh-CN", "gb2312");
        pref("print.postscript.nativefont.zh-CN", "SimSun-GB-EUC-H");

(6) Testing
    To view the mozilla.ps, use the following
    % gv mozilla.ps

    To test the mozilla.ps before send it to printer, use the following
command:
     % cat mozilla.ps | gs -q -dBATCH -dPARANOIDSAFER -dQUIET -dNOPAUSE -sDEVICE=x11 -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -dDuplex=true -dTumble=false -r300  -sOutputFile=- -
发表于 2004-2-27 06:03:00 | 显示全部楼层
真是好文章啊!!感谢windrose!
ttfm-1.0-6.i386.rpm 和 ttfm-1.0.tar.gz可在ftp://cle.linux.org.tw/pub/CLE/devel/ttfm/处下载,将ttfm-1.0.tar.gz解压,在modules文件夹可取得gscjk.ttfm文件
该方法同样适用于fedora core 1,(ghostscript版本7.07 ,测试字体信息可用ggv)我已经测试成功,如果想得到pdf文件,用ps2pdf命令转换

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表