2009/11/19

PostScript 日本語フォント

 

PostScript実習マニュアル
P.63 3.8.10 日本語のフォント

Ryumin-Light-RKSJ-H 明朝体の横組み。
Ryumin-Light-RKSJ-V 明朝体の縦組み。
GothicBBB-Medium-RKSJ-H ゴシック体の横組み。
GothicBBB-Medium-RKSJ-V ゴシック体の縦組み。

ちなみに、これらのフォント名を持つフォント辞書は、文字コードとしてShift JIS を使っています。これらのフォント名に含まれているRKSJ という部分をEUC に置き換えると、文字コードとしてEUC-JP を使うフォント辞書の名前になります。

2009/11/18

PostScript 色, setrgbcolor, setcmykcolor, setgray, 線, setlinecap, setlinejoin, setlinemilter, setdash

setrgbcolor.pscmykcolor.ps setgray.ps cap.psjoin.psmiter.ps dash.ps rowdash.ps

 

 setrgbcolor.ps

% P.50 3.4 色 3.4.2 加法混色
% red green blue setrgbcolor

% rgb
/hline {
    5 dict begin
        /blue exch def
        /green exch def
        /red exch def
        /y exch def
        /x exch def
        newpath
        x y moveto
        30 0 rlineto
        30 setlinewidth
        red green blue setrgbcolor
        stroke
    end
} def

/hundredlines {
    4 dict begin
        /red 0 def
        300 40 660 {
            /y exch def
            /green 0 def
            100 40 460 {
                /x exch def
                x y red green 0 hline
                /green green 0.1 add def
            } for
            /red red 0.1 add def
        } for
    end
} def
hundredlines
showpage

cmykcolor.ps 

% P.51 3.4.3 減法混色
% cyan magenta yellow black setcmykcolor

/hline {
    6 dict begin
        /black exch def
        /yellow exch def
        /magenta exch def
        /cyan exch def
        /y exch def
        /x exch def
        newpath
        x y moveto
        30 0 rlineto
        30 setlinewidth
        cyan magenta yellow black setcmykcolor
        stroke
    end
} def

/hundredlines {
    4 dict begin
        /cyan 0 def
        300 40 660 {
            /y exch def
            /magenta 0 def
            100 40 460 {
                /x exch def
                x y cyan magenta 0 0 hline
                /magenta magenta 0.1 add def
            } for
            /cyan cyan 0.1 add def
        } for
    end
} def
hundredlines
showpage

setgray.ps

% setgray
/dline {
    newpath
    150 100 moveto
    300 600 rlineto
    40 setlinewidth
    stroke
} def

/hline {
    2 dict begin
        /gray exch def
        /y exch def
        newpath
        100 y moveto
        400 0 rlineto
        30 setlinewidth
        gray setgray
        stroke
        end
}def

/elevenlines {
    3 dict begin
        /gray 0 def
        200 40 600 {
            /y exch def
            y gray hline
            /gray gray 0.1 add def
        } for
    end
} def

dline
elevenlines
showpage

cap.ps

% cap
/hline {
    2 dict begin
        /cap exch def
        /y exch def
        newpath
        150 y moveto
        300 0 rlineto
        100 setlinewidth
        0.5 1 1 setrgbcolor
        cap setlinecap
        stroke
        newpath
        150 y moveto
        300 0 rlineto
        1 setlinewidth
        1 0 0 setrgbcolor
        0 setlinecap
        stroke
    end
}def

650 0 hline
500 1 hline
350 2 hline
showpage

join.ps

% join
/harpoon {
    2 dict begin
        /join exch def
        /y exch def
        newpath
        150 y moveto
        250 0 rlineto
        -150 120 rlineto
        80 setlinewidth
        0.5 1 1 setrgbcolor
        join setlinejoin
        stroke
        newpath
        150 y moveto
        250 0 rlineto
        -150 120 rlineto
        1 setlinewidth
        1 0 0 setrgbcolor
        0 setlinejoin
        stroke
    end
}def

600 0 harpoon
400 1 harpoon
200 2 harpoon
showpage

miter.ps 

% join
/harpoon {
    2 dict begin
        /join exch def
        /y exch def
        newpath
        150 y moveto
        250 0 rlineto
        -150 120 rlineto
        80 setlinewidth
        0.5 1 1 setrgbcolor
        join setlinejoin
        stroke
        newpath
        150 y moveto
        250 0 rlineto
        -150 120 rlineto
        1 setlinewidth
        1 0 0 setrgbcolor
        0 setlinejoin
        stroke
    end
}def

600 0 harpoon
400 1 harpoon
200 2 harpoon
showpage

dash.ps

% dash
/vline {
    newpath
    100 150 moveto
    100 750 lineto
    500 150 moveto
    500 750 lineto
    1 0 0 setrgbcolor
    stroke
} def

/hline {
    3 dict begin
        /offset exch def
        /array exch def
        /y exch def
        newpath
        100 y moveto
        400 0 rlineto
        0 0.4 0.8 setrgbcolor
        40 setlinewidth
        array offset setdash
        stroke
    end
}def

vline
700 [] 0 hline
600 [ 30 10 ] 0 hline
500 [ 20 ] 0 hline
400 [ 10 20 30 ] 0 hline
300 [ 50 10 10 10 ] 0 hline
200 [ 50 10 10 10 ] 20 hline
showpage

rowdash.ps

% roudash
newpath
100 200 moveto
400 0 rlineto
-200 500 rlineto
closepath
60 setlinewidth
0.4 0.8 0 setrgbcolor
1 setlinecap
1 setlinejoin
[200 80] 0 setdash
stroke
showpage

 

  • PostScript実習マニュアル
  • PostScript - PDF,Web まとめ
  • PostScript file, ファイルIO

     

    access string

    % P.40 2.13 ファイル 2.13.2 ファイルのオープン
    % /in (hoge.txt) (access string) file def

    % access string
    % r
    % w
    % a
    % r+
    % w+
    % a+

     

    % P.43 2.13.8 標準入出力のファイルオブジェクト
    % 標準入力 %stdin
    % 標準出力 %stdout
    % 標準エラー %stderr
    % /in (%stdin) (r) file def

     

    IO関連オペレータ

    % file
    % closefile
    % read
    % readline
    % readstring
    % token
    % write
    % writestring
    % print
    % deletefile
    % renamefile

     

    読み込み

    /cat {
        3 dict begin
            /path exch def
            /in path (r) file def
            /s 256 string def
            {
                in s readline not {
                    pop exit
                } if
                =
            } loop
            in closefile
        end
    } def

    (c:/test.txt) cat
    % test
    % aaa
    % bbb
    % ccc

    % c:/test.txt
    % test
    % aaa
    % bbb
    % ccc

     

    コピー

    /copy {
        4 dict begin
            /path2 exch def
            /path1 exch def
            /in path1 (r) file def
    %         /out path2 (w) file def
            /out path2 (a+) file def
            {
                in read not {
                    exit
                } if
                out exch write
            } loop
            in closefile
            out closefile
        end
    } def

    (c:/test.txt) (c:/test1.txt) copy

     

    PostScript mmへの変換

    /mm {
        2.834646 mul
    } def

     

    PostScript fill, eofill

    fill-eofill-star

    % P.50 3.3.6 領域の内部性の判定

    /star {
        2 dict begin
            /y exch def
            /x exch def
            newpath
            x y moveto
            300 0 rlineto
            -250 -200 rlineto
            100 300 rlineto
            100 -300 rlineto
        end
    } def

    0 0.4 0 setrgbcolor
    150 650 star
    fill
    150 300 star
    eofill
    showpage

     

  • PostScript実習マニュアル
  • PostScript - PDF,Web まとめ
  • memo

    総論 複数のプログラミング言語を学ぶ意義

    (PDF)複数のプログラミング言語を学ぶ意義 - まつもとゆきひろ

    Oz

    第1回 関数型プログラミングの世界へようこそ

    プログラミングを独習するには10年かかる

    GoldenScheme - Scheme on JavaScript

    和田英一@日本初のハッカーは、ちょっと変わった絵を描く
    LispとPostScriptさえあれば、私はハッピーになれる

    わーい \(^o^)/ LispをPostScriptで書いたLispで書いたよー!

    PHPは駄目な言語なのか?

    Attacking PHP
    世の中には「おかしなコードを書くことを助長する言語」もある という点だ。
    「PHPなめんな」と「(Perl|Python|Ruby)をなめんな」の違い

    悪いのはPHP自体じゃないかもしれないけど

    プログラミング言語は自由度が低いほど強力か?
    Factorに乗り換えるプログラマーは、Factorのより高位なプログラミング力を手に入れるために、ローカル変数を放棄しなくてはなりません。

    プログラム・プロムナード / Haskellプログラミング



    Fortranから最新言語まで、約2500種類のプログラミング言語の系図

    The History of Programming Languages

    TIOBE Programming Community Index for November 2009

    programming languages history

    Search for a particular language entry

    Computer Languages History - Computer Languages Timeline

    人工言語264種類、自然言語42種類のHello World

    The Hello World Collection

    プログラミング好きは2種類ある。

    DSLに関する読み物

    伝統的な言語指向プログラミング

    Schemeでラムダ計算

    ラムダ計算ABC

    JavaScriptで学ぶ・プログラマのためのラムダ計算

    プログラミング言語論教材

    プログラミング言語論教材/関数型言語

    Church Numerals と Lambda Calculus アルゴリズムとデータ構造入門 補足

    数理科学的バグ撲滅方法論のすすめ 第16回 すべてのものは関数である

    なんでもλ

    keisanki-software-kougaku-2005

    PostScript フィボナッチ数

    %!PS-Adobe-3.0
    % fibonacci

    /fib {
        1 dict begin
            /n exch def
            n 0 eq n 1 eq or {
                n
            } {
                n 2 sub fib
                n 1 sub fib
                add
            } ifelse
        end
    } def

    20 fib % 6765

     

    PostScript 階乗

    %!PS-Adobe-3.0 
    % factorial
    
    /fact { 
        1 dict begin 
            /n exch def 
            n 1 eq n 0 eq or { 
                1 
            } { 
                n 1 sub fact n mul 
            } ifelse 
        end 
    } def
    
    5 fact % 120

    PostScript GhostScript, some operators

     

    GS>(abcdefghijk) 3 4 getinterval ==
    (defg)

     

    GS>/s (abcdefghijk) def
    GS>s 3 (WXYZ) putinterval
    GS>s ==
    (abcWXYZhijk)

     

    GS>(437) cvi ==
    437

     

    GS>(3.14) cvr ==
    3.14

     

    GS>(kpf) cvn ==
    /kpf

     

    GS>437 3 string cvs ==
    (437)

     

    GS>(kpf) (9LISP) 123 5
    GS<4>pstack
    5
    123
    (9LISP)
    (kpf)

     

    GS<4>stack
    5
    123
    9LISP
    kpf
    GS<4>

     

    GS>(kpf) (9LISP) (hoge)
    GS<3>pop
    GS<2>stack
    9LISP
    kpf

     

    GS<2>count ==
    2
    GS<2>count

    GS<3>stack
    2
    9LISP
    kpf
    GS<3>pop
    GS<2>count ==
    2

     

    GS<2>clear
    GS>stack
    GS>

     

    GS>398 dup
    GS<2>pstack
    398
    398

     

    GS<2>(a) (b) (c) 2 index
    GS<6>pstack
    (a)
    (c)
    (b)
    (a)
    398
    398

     

    GS<6>(a) (b) (c) 3 copy
    GS<12>pstack
    (c)
    (b)
    (a)
    (c)
    (b)
    (a)
    (a)
    (c)
    (b)
    (a)
    398
    398

     

    GS<12>clear

     

    GS>(a) (b) (c) exch
    GS<3>pstack
    (b)
    (c)
    (a)

     

    GS<3>(9) (L) (I) (S) (P) 4 3 roll
    GS<8>pstack
    (L)
    (P)
    (S)
    (I)
    (9)
    (b)
    (c)
    (a)
    GS<8>

     

    GS>100 mark 1 2 3 4 5
    GS<7>pstack
    5
    4
    3
    2
    1
    -mark-
    100

     

    GS<7>counttomark
    GS<8>==
    5
    GS<7>counttomark ==
    5

     

    GS<7>cleartomark
    GS<1>pstack
    100
    GS<1>

    PostScript 配列を扱う手続き

     

    %!PS-Adobe-3.0
    % P.38 2.12.4 配列を扱う手続き

    /reverse {
        5 dict begin
            /ary exch def
            /n a1 length def
            /ret n array def
            0 1 n 1 sub {
                /i exch def
                /e ary i get def
                ret n i sub 1 sub e put
            } for
            ret
        end
    } def

    [1 2 3 4 5] reverse ==

    %!PS-Adobe-3.0
    % P.39 2.12.4 配列を扱う手続き
    % sum array elements

    /suma {
        2 dict begin
            /ary exch def
            /ret 0 def
            ary {
                /ret exch ret add def
            } forall
            ret
        end
    } def

    [1 2 3 4 5 6 7 8 9 10] suma == % 55

    %!PS-Adobe-3.0
    % P.40 2.12.4 配列を扱う手続き

    /amap {
        6 dict begin
            /f exch def
            /ary exch def
            /n ary length def
            /ret n array def
            0 1 n 1 sub {
                /i exch def
                /e ary i get def
                ret i e f put
            } for
            ret
        end
    } def

    [1 2 3 4 5] { 10 mul } amap ==
    % [10 20 30 40 50]
    [true false false true] { { 1 } { 0  } ifelse } amap ==
    % [1 0 0 1]