GNU PIC の出力画像を綺麗にする
GNU PIC の出力画像が綺麗でないことが不満だったが、一旦SVGファイルにしてから、png などの画像にすれば綺麗になることがわかった。
SVG に直してから変換した画像出力。
今までのスクリプト
pic2plot コマンドで ppm ファイルにして、余計な余白を削除している。
#!/bin/sh PIC_FILE=$1 if [ ! -f "$PIC_FILE" ]; then echo "Usage : "`basename $0`" pic_file [gif_file]" exit 1 fi if [ $# -eq 2 ] then GIF_FILE=$2 else GIF_FILE=`echo $PIC_FILE | sed 's/[^.]*$/gif/'` fi perl -pe 's/\x0D\x0A|\x0D/\x0A/g' $PIC_FILE | \ iconv -t EUC-JP | \ pic2plot -T pnm -F HersheyEUC --bitmap-size '1024x1024' |\ pnmcrop |\ (ppmtogif 2> /dev/null) > $GIF_FILE
改良したスクリプト
pic2plot コマンドの出力を SVG にしてから、 ppm -> 最終画像 に変換するようにした(ついでに、 gif から png に変更)。一番のポイントは rsvg-convert を使って画像変換するようにしたこと。
#!/bin/sh PIC_FILE=$1 if [ ! -f "$PIC_FILE" ]; then echo "Usage : "`basename $0`" pic_file [png_file]" exit 1 fi if [ $# -eq 2 ] then PNG_FILE=$2 else PNG_FILE=`echo $PIC_FILE | sed 's/[^.]*$/png/'` fi case "$OS" in Windows* ) # for cygwin FONT='Arial-Roman' PNG2PPM='pngtopam' ;; *) FONT='Helvetica' PNG2PPM='pngtopnm' ;; esac perl -pe 's/\x0D\x0A|\x0D/\x0A/g' $PIC_FILE | \ iconv -t EUC-JP | \ pic2plot -T svg -F $FONT --bitmap-size '1024x1024' | \ rsvg-convert -f png | $PNG2PPM | pnmcrop | pnmtopng > $PNG_FILE
PIC ファイル
.PS ellipse "document"; arrow; box width 0.6 "\fIpic\fP(1)" arrow; box width 1.1 "\fIgtbl\fP(1) or \fIgeqn\fP(1)" "(optional)" dashed; arrow; box width 0.6 "\fIgtroff\fP(1)"; arrow; ellipse "PostScript" .PE