]> gitweb.factorcode.org Git - factor.git/blob - extra/pdf/text/text.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / extra / pdf / text / text.factor
1 ! Copyright (C) 2011-2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: accessors combinators formatting io kernel math
5 pdf.values sequences ;
6
7 IN: pdf.text
8
9 : comment ( string -- ) "% " write print ;
10
11 : foreground-color ( color -- ) pdf-write " rg" print ;
12
13 : background-color ( color -- ) pdf-write " RG" print ;
14
15
16 ! text
17
18 : text-start ( -- ) "BT" print ;
19
20 : text-end ( -- ) "ET" print ;
21
22 : text-location ( x y -- ) "1 0 0 1 %f %f Tm\n" printf ;
23
24 : text-leading ( n -- ) "%d TL\n" printf ;
25
26 : text-rise ( n -- ) "%d Ts\n" printf ;
27
28 : text-size ( font -- )
29     [
30         [
31             name>> {
32                 { "Helvetica" [ 1 ] }
33                 { "Times"     [ 2 ] }
34                 { "Courier"   [ 3 ] }
35                 [ " is unsupported" append throw ]
36             } case
37         ]
38         [
39             {
40                 { [ dup [ bold?>> ] [ italic?>> ] bi and ] [ 9 ] }
41                 { [ dup bold?>> ] [ 3 ] }
42                 { [ dup italic?>> ] [ 6 ] }
43                 [ 0 ]
44             } cond nip +
45         ] bi
46     ] [ size>> ] bi "/F%d %d Tf\n" printf ;
47
48 : text-write ( string -- ) pdf-write " Tj" print ;
49
50 : text-nl ( -- ) "T*" print ;
51
52 : text-print ( string -- ) pdf-write " '" print ;
53
54
55
56 ! graphics
57
58 : line-width ( n -- ) "%d w\n" printf ;
59
60 : line-dashed ( on off -- ) "[ %d %d ] 0 d\n" printf ;
61
62 : line-solid ( -- ) "[] 0 d" print ;
63
64 : line-move ( x y -- ) "%f %f m\n" printf ;
65
66 : line-line ( x y -- ) "%f %f l\n" printf ;
67
68 : gray ( percent -- ) "%.f g\n" printf ;
69
70 : rectangle ( x y width height -- ) "%d %d %d %d re\n" printf ;
71
72 : stroke ( -- ) "S" print ;
73
74 : fill ( -- ) "f" print ;
75
76 : B ( -- ) "B" print ;
77
78 : b ( -- ) "b" print ;
79
80 : c ( -- ) "300 400 400 400 400 300 c" print ; ! FIXME: