Linux および UNIX でプリンタドライバの役割をするのが Ghostscript です。
Ghostscript 8.60 では ESP Ghostscriptの成果を取り込み対応デバイスが増えました。そのうちの1つが RPDL デバイスで、RICOH imagio MP C3500 などが含まれます。ここでは、CentOS 4 の cups 経由で RICOH imagio MP C3500 に印刷すべく、Ghostscript 8.60 をインストールしてみました。
参考にしたサイト
ありがとうございます。
問題点
RICOH imagio MP C3500 の製品情報 によると、対応しているページ記述言語は RPCS および RPDL IV で、PostScript はオプション*1となっています。CentOS 4 の Ghostscript 7.07 は RPDL 非対応ですので、Linux からこのプリンタに直接印刷することはできません*2。
ダウンロード
- Ghostscript download | SourceForge.net から、Ghostscritp 8.60 ソースファイルをダウンロード。
- ghostscript-8.60.tar.bz2
- Ghostscript fonts download | SourceForge.net から、Ghostscript フォントをダウンロード。
- ghostscript-fonts-std-8.11.tar.gz
- ghostscript-fonts-other-6.0.tar.gz
- ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/samples/ から、和田研フォントCID版をダウンロード。
- WadaGo-Bold
- WadaMin-Regular
- フリーの TrueType フォント
- IPAフォント はCentOS 5 インストール個人的ノート に書かれているようにすると取得できます。
CID フォントで動作確認し、後で TrueType フォントを使えるようにします。
Makefile の生成 (間違い編)
(注釈: 急ぐ方は下方の「Makefile の生成 (やり直し編)」へ進んで下さい。)
ソースファイルの展開は NFS 上以外でやるようにします*3。/tmp 以下などでやりましょう。
$ tar -xjf ghostscript-8.60.tar.bz2
$ cd ghostscript-8.60
$ ./configure --prefix=/usr/local/gs --with-drivers=ALL
ここの ./configure のオプションが後で問題となります…。
ビルドおよびインストール
$ make
$ make check
$ sudo make install
/usr/local/gs 以下にインストールされます。
フォントをインストールします。
$ sudo tar -xzf ghostscript-fonts-std-8.11.tar.gz -c /usr/local/gs/share/ghostscript/font
$ sudo tar -xzf ghostscript-fonts-other-6.0.tar.gz -c /usr/local/gs/share/ghostscript/font
$ sudo mkdir -p /usr/local/gs/share/ghostscript/8.60/Resource/CIDFont
$ cp WadaGo-Bold /usr/local/gs/share/ghostscript/8.60/Resource/CIDFont
$ cp WadaMin-Regular /usr/local/gs/share/ghostscript/8.60/Resource/CIDFont
設定
CID フォントの代替設定と、フォントパスの設定をやります。
$ cd /usr/local/gs/share/ghostscript/8.60/lib
$ sudo cp -p cidfmap cidfmap.orig
$ sudo cp -p gs_res.ps gs_res.ps.orig
$ sudo vim cidfmap gs_res.ps
$ diff -Nur cidfmap.orig cidfmap
--- cidfmap.orig 2007-08-11 11:24:47.000000000 +0900 +++ cidfmap 2007-08-12 20:53:23.000000000 +0900 @@ -26,3 +26,12 @@ % /ShinGo-Bold /HeiseiKakuGo-W5 ; % /Ryumin-Medium << /FileType /TrueType /Path (H:/AuxFiles/Fonts/BATANG.TTC) /SubfontID 3 /CSI [(Japan1) 2] >> ; % + +/Ryumin-Light /WadaMin-Regular ; +/GothicBBB-Medium /WadaGo-Bold ; + +/Ryumin-Light /WadaMin-Regular ; +/Ryumin-Medium /WadaMin-Regular ; +/GothicBBB-Medium /WadaGo-Bold ; +/HeiseiMin-W3 /WadaMin-Regular ; +/HeiseiKakuGo-W5 /WadaGo-Bold ;
$ diff -Nur gs_res.ps.orig gs_res.ps
--- gs_res.ps.orig 2007-08-11 11:24:49.000000000 +0900 +++ gs_res.ps 2007-08-11 11:27:50.000000000 +0900 @@ -317,9 +317,9 @@ } if pssystemparams begin .default_resource_dir - /FontResourceDir (Font) .resource_dir_name + /FontResourceDir (/usr/local/tmp/share/ghostscript/8.60/Resource/Font/) .resource_dir_name readonly .forcedef % pssys'params is r-o - /GenericResourceDir () .resource_dir_name + /GenericResourceDir (/usr/local/tmp/share/ghostscript/8.60/Resource/) .resource_dir_name readonly .forcedef % pssys'params is r-o pop % .default_resource_dir /GenericResourcePathSep
/usr/local/tmp/share/ghostscript/8.60/Resource/Font/ は作成していませんが、ここには(必要に応じて)フォントスペックファイルを置くようです。
- フォントスペックファイルについては http://centos.it-cafe.jp/kankyou/kan003.html#ghost に詳しい説明があります。PostScriptフォントと、CMapファイルおよびCIDフォントとの関連がよく分かります。
- http://www.interq.or.jp/mars/cherry/mac/gs-tiger.htmlの「日本語フォントのインストール(3/3)」にできあがり品Font.tar.bz2 があります。
なくても印刷はできますので、ここではなしでいきます。
表示テスト (失敗編)
$ export PATH=/usr/local/gs/bin:$PATH
$ which gs
/usr/local/gs/bin/gs
$ gs -h | grep rpdl
pxlmono r4081 rpdl samsunggdi sgirgb sj48 spotcmyk st800 stcolor sunhmono
RPDL に対応していることがわかります。続いて、サンプルの PostScript ファイルを表示できるかやってみます。
$ gs -sDEVICE=x11 /usr/local/gs/share/ghostscript/8.60/examples/tiger.ps
$ gs -sDEVICE=x11 /usr/local/gs/share/ghostscript/8.60/examples/alphabet.ps
虎とアルファベットが表示されます。ここまでは問題なし。
ところが、日本語がうまくいきません。
$ export LANG=ja_JP.eucJP
$ echo hage | a2ps -o ~/hage.ps
$ gs -sDEVICE=x11 ~/hage.ps
とやると、
GPL Ghostscript 8.60 (2007-08-01) Copyright (C) 2007 Artifex Software, Inc. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Loading NimbusMonL-Regu font from /usr/local/gs/share/ghostscript/fonts/n022003l.pfb... 2983232 1656080 2151128 830451 1 done. Loading NimbusMonL-Bold font from /usr/local/gs/share/ghostscript/fonts/n022004l.pfb... 3164168 1842333 2151128 835385 1 done. Loading NimbusMonL-BoldObli font from /usr/local/gs/share/ghostscript/fonts/n022024l.pfb... 3344512 2022504 2151128 839003 1 done. Loading NimbusMonL-ReguObli font from /usr/local/gs/share/ghostscript/fonts/n022023l.pfb... 3498896 2186164 2151128 842621 1 done. Loading NimbusSanL-Regu font from /usr/local/gs/share/ghostscript/fonts/n019003l.pfb... 3572544 2145581 2090576 415897 1 done. Loading NimbusSanL-Bold font from /usr/local/gs/share/ghostscript/fonts/n019004l.pfb... 3686560 2274650 2090576 419515 1 done. Loading NimbusRomNo9L-Medi font from /usr/local/gs/share/ghostscript/fonts/n021004l.pfb... 3869816 2471182 2090576 423533 1 done. Loading NimbusRomNo9L-Regu font from /usr/local/gs/share/ghostscript/fonts/n021003l.pfb... 4072504 2669156 2090576 427151 1 done. Can't find (or can't open) font file Resource/Font/Ryumin-Light-EUC-H. Can't find (or can't open) font file Ryumin-Light-EUC-H. Querying operating system for font files... Can't find (or can't open) font file Resource/Font/Ryumin-Light-EUC-H. Can't find (or can't open) font file Ryumin-Light-EUC-H. Didn't find this font on the system! Substituting font Courier for Ryumin-Light-EUC-H. Can't find (or can't open) font file Resource/Font/GothicBBB-Medium-EUC-H. Can't find (or can't open) font file GothicBBB-Medium-EUC-H. Didn't find this font on the system! Substituting font Courier for GothicBBB-Medium-EUC-H. Error: /invalidfont in --scalefont-- Operand stack: euc-jpdict fCourier --dict:17/19(L)-- 0.909091 Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1889 1 3 %oparray_pop 1888 1 3 %oparray_pop 1872 1 3 %oparray_pop 1755 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- Dictionary stack: --dict:1142/1684(ro)(G)-- --dict:0/20(G)-- --dict:72/200(L)-- --dict:59 /200(L)-- --dict:11/18(L)-- Current allocation mode is local Last OS error: 2 Current file position is 16840 GPL Ghostscript 8.60: Unrecoverable error, exit code 1
気になるのは、
Can't find (or can't open) font file Resource/Font/Ryumin-Light-EUC-H.
フォントスペックファイル (PostScript フォントに対し、どの CID フォントおよび CMap ファイルを使うかを指定するファイル) を見に行っているのかと思いましたが、"font file" と書いてあるので CID フォントが見つからないという意味のようです。
hage.ps を Windows の Ghostscript 8.60 で表示させるとちゃんと表示されます。試しに、8.60/lib/cidfmap で 'MS ゴシック' を指定している箇所をわざとコメントアウトしてフォントが見つからない状態を作り出してみると、
Can't find (or can't open) font file C:\opt\gs\gs8.60\Resource/Font/Ryumin-Light-EUC-H.
エラーメッセージが違いますね。フォントファイルがフルパスで表示されています。どうやら、先ほどコンパイルしたバイナリは/usr/local/tmp/share/ghostscript/8.60/lib/gs_res.ps を無視しているようです。
そこで、ようやく気づいたのが、
$ gs -h
(略) Search path: . : %rom%lib/ : /usr/local/gs/share/ghostscript/8.60/lib : /usr/local/gs/share/ghostscript/8.60/Resource : /usr/local/gs/share/ghostscript/fonts : /usr/local/gs/share/fonts/default/ghostscript : /usr/local/gs/share/fonts/default/Type1 : /usr/local/gs/share/fonts/default/TrueType : /usr/lib/DPS/outline/base : /usr/openwin/lib/X11/fonts/Type1 : /usr/openwin/lib/X11/fonts/TrueType Initialization files are compiled into the executable. For more information, see /usr/local/gs/share/ghostscript/8.60/doc/Use.htm. Please report bugs to bugs.ghostscript.com.
「初期設定はコンパイル時に実行ファイル中に含めました」と書かれています。こうなると、gs_*.ps を読んでくれません。
Makefile の生成 (やり直し編)
/usr/local/tmp 以下へインストールしてみます。gs_*.ps を読んでくれるようにするには、./configure 時に ''--disable-compile-inits'' をつける必要があるようです。GhostScript 8.x 系では有名な Tips のようですね。
./configure --prefix=/usr/local/tmp --disable-compile-inits --with-drivers=ALL
後は先ほどと同じようにビルド、インストール、および設定します。
ビルドおよびインストール (再掲)
$ make
$ make check
$ sudo make install
/usr/local/tmp 以下にインストールされます。
フォントをインストールします。
$ sudo tar -xzf ghostscript-fonts-std-8.11.tar.gz -c /usr/local/tmp/share/ghostscript/font
$ sudo tar -xzf ghostscript-fonts-other-6.0.tar.gz -c /usr/local/tmp/share/ghostscript/font
$ sudo mkdir -p /usr/local/tmp/share/ghostscript/8.60/Resource/CIDFont
$ cp WadaGo-Bold /usr/local/tmp/share/ghostscript/8.60/Resource/CIDFont
$ cp WadaMin-Regular /usr/local/tmp/share/ghostscript/8.60/Resource/CIDFont
設定 (再掲)
CID フォントの代替設定と、フォントパスの設定をやります。
$ cd /usr/local/tmp/share/ghostscript/8.60/lib
$ sudo cp -p cidfmap cidfmap.orig
$ sudo cp -p gs_res.ps gs_res.ps.orig
$ sudo vim cidfmap gs_res.ps
$ diff -Nur cidfmap.orig cidfmap
--- cidfmap.orig 2007-08-11 11:24:47.000000000 +0900 +++ cidfmap 2007-08-12 20:53:23.000000000 +0900 @@ -26,3 +26,12 @@ % /ShinGo-Bold /HeiseiKakuGo-W5 ; % /Ryumin-Medium << /FileType /TrueType /Path (H:/AuxFiles/Fonts/BATANG.TTC) /SubfontID 3 /CSI [(Japan1) 2] >> ; % + +/Ryumin-Light /WadaMin-Regular ; +/GothicBBB-Medium /WadaGo-Bold ; + +/Ryumin-Light /WadaMin-Regular ; +/Ryumin-Medium /WadaMin-Regular ; +/GothicBBB-Medium /WadaGo-Bold ; +/HeiseiMin-W3 /WadaMin-Regular ; +/HeiseiKakuGo-W5 /WadaGo-Bold ;
$ diff -Nur gs_res.ps.orig gs_res.ps
--- gs_res.ps.orig 2007-08-11 11:24:49.000000000 +0900 +++ gs_res.ps 2007-08-11 11:27:50.000000000 +0900 @@ -317,9 +317,9 @@ } if pssystemparams begin .default_resource_dir - /FontResourceDir (Font) .resource_dir_name + /FontResourceDir (/usr/local/tmp/share/ghostscript/8.60/Resource/Font/) .resource_dir_name readonly .forcedef % pssys'params is r-o - /GenericResourceDir () .resource_dir_name + /GenericResourceDir (/usr/local/tmp/share/ghostscript/8.60/Resource/) .resource_dir_name readonly .forcedef % pssys'params is r-o pop % .default_resource_dir /GenericResourcePathSep
/usr/local/tmp/share/ghostscript/8.60/Resource/Font/ は作成していませんが、ここには(必要に応じて)フォントスペックファイルを置くようです。
- フォントスペックファイルについては http://centos.it-cafe.jp/kankyou/kan003.html#ghost に詳しい説明があります。PostScriptフォントと、CMapファイルおよびCIDフォントとの関連がよく分かります。
- http://www.cymric.jp/old/mac/gs-tiger.htmlの「日本語フォントのインストール(3/3)」にできあがり品Font.tar.bz2 があります。
なくても印刷はできますので、ここではなしでいきます。
表示テスト (成功編)
$ export LANG=ja_JP.eucJP
$ echo hage | a2ps -o ~/hage.ps
$ gs -sDEVICE=x11 ~/hage.ps
(略) Scanning /usr/local/tmp/share/ghostscript/8.60/Resource/CIDFont/ for fonts... 2 files, 2 scanned, 2 new fonts. (略)
と、うまくいきました。
印刷テスト
CentOS のプリンタ設定ツールからやってみます。
その前に、/usr/bin/gs を今インストールしたもので置き換えます。
$ sudo mv /usr/bin/gs /usr/bin/gs.orig
$ cd /usr/bin
$ sudo ln -s /usr/local/tmp/bin/gs
CentOS のプリンタ設定ツールを起動します。LANG=ja_JP.eucJP だと解像度設定のところで落ちるので LANG=C にしておきます。
$ LANG=C sudo system-config-printer-tui
TrueType フォントを使う
和田研 CID フォントはさすがに品質が悪いので、TrueType フォントを利用することを考えます。ここでは IPA フォントを利用してみます。/usr/X11R6/lib/X11/fonts/ipa/ 以下に ipam.ttf, ipag.ttf がコピーされていると仮定します。
/usr/local/tmp/share/ghostscript/8.60/lib/cidfmap を以下のようにします。
$ cd /usr/local/tmp/share/ghostscript/8.60/lib
$ sudo cp cidfmap.orig cidfmap
$ sudo vi cidfmap
$ diff -Nur cidfmap.orig cidfmap
--- cidfmap.orig 2007-08-11 11:24:47.000000000 +0900 +++ cidfmap 2007-08-12 23:05:29.000000000 +0900 @@ -26,3 +26,12 @@ % /ShinGo-Bold /HeiseiKakuGo-W5 ; % /Ryumin-Medium << /FileType /TrueType /Path (H:/AuxFiles/Fonts/BATANG.TTC) /SubfontID 3 /CSI [(Japan1) 2] >> ; % + +/ipaMincho << /FileType /TrueType /CSI [(Japan1) 6] /Path (ipam.ttf) >> ; +/ipaGothic << /FileType /TrueType /CSI [(Japan1) 6] /Path (ipag.ttf) >> ; + +/Ryumin-Light /ipaMincho ; +/Ryumin-Medium /ipaMincho ; +/HeiseiKakuGo-W5 /ipaGothic ; +/GothicBBB-Medium /ipaGothic ; +/HeiseiMin-W3 /ipaMincho ;
$ cd /usr/local/tmp/share/ghostscript/fonts
$ sudo ln -s /usr/X11R6/lib/X11/fonts/ipa/ipam.ttf
$ sudo ln -s /usr/X11R6/lib/X11/fonts/ipa/ipag.ttf
リンクを貼るのがポイントです。cidfmap でフルパス指定すると、印刷時にエラーとなります。このエラーですが、/etc/cups/cupsd.conf で loglevel を debug にしておくと、下記のようなログが記録されます。
D [11/Aug/2007:12:11:09 +0900] [Job 17] renderer command: gs -q -dBATCH -dPARANOIDSAFER -dQUIET -dNOPAUSE -sDEVICE=rpdl -sOutputFile=- - D [11/Aug/2007:12:11:09 +0900] [Job 17] foomatic-gswrapper: /usr/local/tmp/bin/gs '-dBATCH' '-dPARANOIDSAFER' '-dQUIET' '-dNOPAUSE' '-sDEVICE=rpdl' '-sOutputFile=| cat >&3' '/dev/fd/0' 3>&1 1>&2 D [11/Aug/2007:12:11:09 +0900] [Job 17] Error: /invalidfileaccess in /findfont D [11/Aug/2007:12:11:09 +0900] [Job 17] Operand stack: D [11/Aug/2007:12:11:09 +0900] [Job 17] kanj Ryumin-Light-H D [11/Aug/2007:12:11:09 +0900] [Job 17] Execution stack: D [11/Aug/2007:12:11:09 +0900] [Job 17] %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1889 1 3 %oparray_pop 1888 1 3 %oparray_pop 1872 1 3 %oparray_pop 17551 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 1847 2 3 %oparray_pop D [11/Aug/2007:12:11:09 +0900] [Job 17] Dictionary stack: D [11/Aug/2007:12:11:09 +0900] [Job 17] --dict:1154/1684(ro)(G)-- --dict:0/20(G)-- --dict:80/200(L)-- D [11/Aug/2007:12:11:09 +0900] [Job 17] Current allocation mode is local D [11/Aug/2007:12:11:09 +0900] [Job 17] GPL Ghostscript 8.60: Unrecoverable error, exit code 1 D [11/Aug/2007:12:11:09 +0900] [Job 17] renderer return value: 1 D [11/Aug/2007:12:11:09 +0900] [Job 17] renderer received signal: 1 D [11/Aug/2007:12:11:09 +0900] [Job 17] Process dying with "Possible error on renderer command line or PostScript error. Check options.", exit stat: 3
このエラーについて詳しくは [FreeBSD-users-jp 90279] Re: cups に ついて などをご覧ください。
印刷テストを同じようにやってみると、フォントが綺麗な日本語テストページが印刷されます。