_Tips: EPSFを使って紙の上の正確な位置に図を描く

Tips: EPSFを使って紙の上の正確な位置に図を描く

(expanded from EPSFを使って紙の上の正確な位置に図を描く このページは編集しないでください)

(2020/3/19)

HTMLTeXなどを使うと簡単に綺麗な文書を作ることができるが、紙の上の正確な位置に図を描くことは難しい。HTMLだと absolute 属性を使えば絶対位置を指定することはできるが、EPSFを使う方法を考えてみた。
EPSFはEncapsulated PostScript Fileの略で、PostScriptを他の文書に埋め込むためのフォーマットである。 たとえば、小さな正方形を描くために以下のようなEPSFを用意する。


rect.eps
Copied!
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 50 50
0 0 moveto
0 50 lineto
50 50 lineto
50 0 lineto
0 0 lineto
stroke
%%Trailer
%%EOF

このEPSFを rects.ps のような他のPostScriptファイルで利用することができる。

rects.ps
Copied!
%!PS-Adobe-2.0
%%Pages: 1
%%BoundingBox: 0 0 595 842
%%EndComments
%%EndProlog
%%Page: 1 1

gsave
10 10 translate
% ここからrect.eps
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 50 50
0 0 moveto
0 50 lineto
50 50 lineto
50 0 lineto
0 0 lineto
stroke
%%Trailer
%%EOF
% ここまで
grestore

gsave
60 60 translate
% ここからrect.eps
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 50 50
0 0 moveto
0 50 lineto
50 50 lineto
50 0 lineto
0 0 lineto
stroke
%%Trailer
%%EOF
% ここまで
grestore

showpage

%%Trailer
%%EOF

この rects.ps ps2pdf PDFにすると以下のような図が表示される。

このようにすると、かなり正確に図を紙の上に印刷できると思う。

#Tips #ブログ 2020/3/19
Powered by Helpfeel