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 >rgba-components drop "%f %f %f" sprintf ;
46 { "sans-serif" [ "/Helvetica" ] }
47 { "serif" [ "/Times" ] }
48 { "monospace" [ "/Courier" ] }
49 [ " is unsupported" append throw ]
52 [ [ bold?>> ] [ italic?>> ] bi or [ "-" append ] when ]
53 [ bold?>> [ "Bold" append ] when ]
54 [ italic?>> [ "Italic" append ] when ]
56 "/BaseFont " prepend ,
58 ] { } make "\n" join ;
60 M: timestamp pdf-value
61 "%Y%m%d%H%M%S" strftime "D:" prepend ;
64 escape-string "(" ")" surround ;
67 [ "[" % [ pdf-value % " " % ] each "]" % ] "" make ;
69 M: hashtable pdf-value
72 [ swap % " " % pdf-value % "\n" % ] assoc-each
76 : pdf-write ( obj -- )