1 ! Copyright (C) 2011-2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors combinators formatting io kernel math
9 : comment ( string -- ) "% " write print ;
11 : foreground-color ( color -- ) pdf-write " rg" print ;
13 : background-color ( color -- ) pdf-write " RG" print ;
18 : text-start ( -- ) "BT" print ;
20 : text-end ( -- ) "ET" print ;
22 : text-location ( x y -- ) "1 0 0 1 %f %f Tm\n" printf ;
24 : text-leading ( n -- ) "%d TL\n" printf ;
26 : text-rise ( n -- ) "%d Ts\n" printf ;
28 : text-size ( font -- )
35 [ " is unsupported" append throw ]
40 { [ dup [ bold?>> ] [ italic?>> ] bi and ] [ 9 ] }
41 { [ dup bold?>> ] [ 3 ] }
42 { [ dup italic?>> ] [ 6 ] }
46 ] [ size>> ] bi "/F%d %d Tf\n" printf ;
48 : text-write ( string -- ) pdf-write " Tj" print ;
50 : text-nl ( -- ) "T*" print ;
52 : text-print ( string -- ) pdf-write " '" print ;
58 : line-width ( n -- ) "%d w\n" printf ;
60 : line-dashed ( on off -- ) "[ %d %d ] 0 d\n" printf ;
62 : line-solid ( -- ) "[] 0 d" print ;
64 : line-move ( x y -- ) "%f %f m\n" printf ;
66 : line-line ( x y -- ) "%f %f l\n" printf ;
68 : gray ( percent -- ) "%.f g\n" printf ;
70 : rectangle ( x y width height -- ) "%d %d %d %d re\n" printf ;
72 : stroke ( -- ) "S" print ;
74 : fill ( -- ) "f" print ;
76 : B ( -- ) "B" print ;
78 : b ( -- ) "b" print ;
80 : c ( -- ) "300 400 400 400 400 300 c" print ; ! FIXME: