7.2. CID-keyed

7.2.1. ghostscrip6 - 使用 CJK TrueType 當作是 CID-Keyed fonts

這個 port 主要是讓 ghostscript6 可以使用 CJK (Chinese, Japanese, Korean) TrueType 當作是 CID-Keyed fonts

ghostscript6 的安裝:

       # cd /usr/ports/chinese/ghostscript6
        # make install

安裝 CJK CID-Keyed 字型到 Ghostscrip6

首先到 ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/ 取得以下檔案

    Taiwan - ac13.tar.Z(Adobe-CNS1) 
    China - ag13.tar.Z(Adobe-GB1) 
    Japan - aj14.tar.Z(Adobe-Japan1), aj20.tar.Z(Adobe-Japan2) 
    Korea - ak12.tar.Z(Adobe-Korea1) 
    others - ai0.tar.Z

使用 ghostscript6 來列印文件

    # gs -sDEVICE=cdj550 -sOutputFile=/dev/lpt0 xx.ps
         

gs --help 會有更多的選項

以此套件搭配 arphicttf 就可以讓大部分的軟體可以透過 gs 讀取 ttf 來產生正確的 gs 檔。

以下是利用 ttfm 來將 arphicttf 的字型加入 gs 的列表:

    # ttfm.sh --add ghostscript6 bkai00mp.ttf
    # ttfm.sh --add ghostscript6 bsmi00lp.ttf

這樣會分別產生常用的 CID-keyed:ArphicKaiB5-Regular-Eten-B5-H 以及 ArphicMingB5-Regular-Eten-B5-H 以供需要列印的軟體使用,例如 Mozilla、KDE等。

Tips on PostScript: http://www.aihara.co.jp/~taiji/tops/

ghostscript6 WWW: http://www.cs.wisc.edu/~ghost/index.html

7.2.2. ghostscript-gnu-zhfont - 讓 gs 能夠使用 CJK

gs-cjk project 是一個讓 Aladdin/Artifex/GNU ghostscript(gs) 能夠使用 CJK 功能的發展計畫。在這個網站中,所提供的程式集, 包含讓 gs 能夠把 CJK ( 繁、簡中文,日文,韓文 ) 的全真字型當作CID-keyed 的字型來處理的必要修補檔案( patch), 以及改進在 gs CID-keyed 字型的handler。

ghostscript-gnu-zhfont 的安裝:

    # cd /usr/ports/outta-port/ghostscript-gnu-zhfont
    # make install
         

gs-cjk WWW: http://www.gyve.org/gs-cjk/

7.2.3. moefonts-cid - 由 Adobe 轉譯 MOE CIDFonts

這個字型蒐集用來被 ghostscript 所使用,用來列印中文文件。

中文 CID-Keyed 字型(MOEKai 和 MOESung) 由 Adobe 所提供的, 原本為 48x48 點陣字型,從台灣教育部而來,為 Dynalab 所製作。 這些字型能夠自由的使用。

moefonts-cid 的安裝:

    # cd /usr/ports/chinese/moefonts-cid
    # make install

CID-Keyed 可以從 ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/samples/ 取得 MOEKai-Regular MOESung-Regular 這兩個 CIDFont,並在 ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/ 取得 ac14.tar.Z,裡面包含了 Adobe-CNS1 的 CMap 檔案。

裝完後就有如下的 CID-keyed 可以使用:

    MOEKai-Regular-ETen-B5-H
    MOEKai-Regular-ETen-B5-V
    MOESung-Regular-ETen-B5-H
    MOESung-Regular-ETen-B5-V

以下是一個測試的範例:

    % cat cid.ps
    /MOEKai-Regular-ETen-B5-H findfont 60 scalefont setfont
    50 600 moveto (眾裡尋他千百度) show                          
    50 520 moveto (驀然回首) show      
    50 440 moveto (那人卻在燈火欄珊處) show
    showpage                               
    quit
    % gv -antialias cid.ps
    % ps2ps cid.ps cid2.ps
    % ps2pdf cid.ps
    % ps2pdf cid2.ps
    % xpdf cid.pdf (可能不行)
    % xpdf cid2.pdf

snapshot: http://freebsd.sinica.edu.tw/~statue/snapshot/cid-gv.png

目前已經可以由 ttfm 搭配 chinese/ghostscrip6 的方式來取代,而且效果更好。

以下是以 MOESung-Regular 為例子,來增加粗體、斜體、粗斜體支援, 在安裝時,由於必須額外安裝 adobe-cmaps 來搭配, 所以會 DEPENDS print/adobe-cmaps。

再來是建立粗體,斜體,粗斜體等,在看完 ttfm 的 gs-cjk 模組後, 有個想法就是 gs-cjk 的做法是在 ttf 上面建立粗體,斜體,粗斜體等, 這些做法是不是應該也適用於 moefonts-cid?

因此就建立了 MOESung-Regular-Bold

    %!PS-Adobe-3.0 Resource-CIDFont
    %%BeginResource: CIDFont (MOESung-Regular-Bold)
    /MOESung-Regular-Bold
    /MOESung-Regular /CIDFont findresource
    16 dict begin
      /basecidfont exch def
      /basefont-H /.basefont-H /Identity-H [ basecidfont ] composefont def
      /basefont-V /.basefont-V /Identity-V [ basecidfont ] composefont def
      /CIDFontName dup basecidfont exch get def
      /CIDFontType 1 def
      /CIDSystemInfo dup basecidfont exch get def
      /FontInfo dup basecidfont exch get def
      /FontMatrix [ 1 0 0 1 0 0 ] def
      /FontBBox [
        basecidfont /FontBBox get cvx exec
        4 2 roll basecidfont /FontMatrix get transform
        4 2 roll basecidfont /FontMatrix get transform
      ] def
      /cid 2 string def
      /BuildGlyph {
        gsave
        exch begin
          dup 256 idiv cid exch 0 exch put
          256 mod cid exch 1 exch put
          rootfont /WMode known { rootfont /WMode get 1 eq } { false } ifelse
          { basefont-V } { basefont-H } ifelse setfont
          .03 setlinewidth 1 setlinejoin
          newpath
          0 0 moveto cid false charpath stroke
          0 0 moveto cid show
          currentpoint setcharwidth
        end
        grestore
      } bind def
      currentdict
    end
    /CIDFont defineresource pop
    %%EndResource
    %%EOF

以及 MOESung-Regular-Bold-ETen-B5-H.gsf

    /MOESung-Regular-Bold-ETen-B5-H
    /MOESung-Regular-Bold (MOESung-Regular-Bold)
    /ETen-B5-H (CMap/ETen-B5-H)
    
    1 index /CMap resourcestatus
    {pop pop pop}
    {runlibfile} ifelse
    /CMap findresource
    
    3 1 roll
    1 index /CIDFont resourcestatus
    {pop pop pop}
    {runlibfile} ifelse
    /CIDFont findresource
    
    [ exch ] composefont pop

結果發現在測試檔 cid.ps

    /MOESung-Regular-ETen-B5-H findfont 30 scalefont setfont
    50 600 moveto (2000年5月29日) show
    /MOESung-Regular-Bold-ETen-B5-H findfont 30 scalefont setfont
    50 560 moveto (2000年5月29日) show
    /MOESung-Regular-Italic-ETen-B5-H findfont 30 scalefont setfont
    50 520 moveto (2000年5月29日) show
    /MOESung-Regular-BoldItalic-ETen-B5-H findfont 30 scalefont setfont
    50 480 moveto (2000年5月29日) show
    /MOEKai-Regular-ETen-B5-H findfont 30 scalefont setfont
    50 440 moveto (2000年5月29日) show
    /MOEKai-Regular-Bold-ETen-B5-H findfont 30 scalefont setfont
    50 400 moveto (2000年5月29日) show
    /MOEKai-Regular-Italic-ETen-B5-H findfont 30 scalefont setfont
    50 360 moveto (2000年5月29日) show
    /MOEKai-Regular-BoldItalic-ETen-B5-H findfont 30 scalefont setfont
    50 320 moveto (2000年5月29日) show
    showpage
    quit

粗體的部分出現了預期的效果,所以就繼續製作斜體與粗斜體, 這部分可以參考 gs-cjk,斜體的名稱定為 MOESung-Regular-Italic, 而粗斜體則是 MOESung-Regular-BoldItalic。

最後,記得把這些 .gsf 寫入 /usr/local/share/ghostscript/7.05/lib/Fontmap.GS 寫法是:字型 (字型.gsf) ;

    /MOESung-Regular-ETen-B5-H (MOESung-Regular-ETen-B5-H.gsf) ;
    /MOESung-Regular-Bold-ETen-B5-H (MOESung-Regular-Bold-ETen-B5-H.gsf) ;
    /MOESung-Regular-BoldItalic-ETen-B5-H (MOESung-Regular-BoldItalic-ETen-B5-H.gsf) ;
    /MOESung-Regular-Italic-ETen-B5-H (MOESung-Regular-Italic-ETen-B5-H.gsf) ;

最後修改一下 -H 成 -V 再重複上面的過程即可, 其他的字型也是幾乎一樣的做法就可以完工了, 不過,真的比不上用 ttf 做出來的呀

如此建立完,就會有一堆可用的 CID-keyed 字型

    MOESung-Regular-ETen-B5-H
    MOESung-Regular-Bold-ETen-B5-H
    MOESung-Regular-BoldItalic-ETen-B5-H
    MOESung-Regular-Italic-ETen-B5-H

這樣子在配合文書軟體上,應該會更好,我想文書軟體慢慢的也會把列印的部分用 gs 所提供的字型來模擬,像是 editors/Abiword 就是個很棒的例子, 而 kde2 則是自己做粗體,斜體等的模擬,不過我還沒去測試到粗體和斜體的部分, 等有空閒了再去試試。

snapshot: http://freebsd.sinica.edu.tw/~statue/snapshot/moefonts-cid.png