1 ! Copyright (C) 2011-2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors arrays assocs calendar colors colors.gray
5 combinators combinators.short-circuit fonts formatting
6 hashtables io kernel make math math.parser sequences strings
13 : escape-string ( str -- str' )
27 GENERIC: pdf-value ( obj -- str )
29 M: number pdf-value number>string ;
31 M: t pdf-value drop "true" ;
33 M: f pdf-value drop "false" ;
36 [ red>> ] [ green>> ] [ blue>> ] tri
40 gray>> dup dup "%f %f %f" sprintf ;
50 { "sans-serif" [ "/Helvetica" ] }
51 { "serif" [ "/Times" ] }
52 { "monospace" [ "/Courier" ] }
53 [ " is unsupported" append throw ]
56 [ [ bold?>> ] [ italic?>> ] bi or [ "-" append ] when ]
57 [ bold?>> [ "Bold" append ] when ]
58 [ italic?>> [ "Italic" append ] when ]
60 "/BaseFont " prepend ,
62 ] { } make "\n" join ;
64 M: timestamp pdf-value
65 "%Y%m%d%H%M%S" strftime "D:" prepend ;
68 escape-string "(" ")" surround ;
71 [ "[" % [ pdf-value % " " % ] each "]" % ] "" make ;
73 M: hashtable pdf-value
76 [ swap % " " % pdf-value % "\n" % ] assoc-each
80 : pdf-write ( obj -- )