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 splitting
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 name>> { "sans-serif" "monospace" } member?
57 [ "Italic" "Oblique" replace ] when
60 "/BaseFont " prepend ,
62 ] { } make join-lines ;
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 -- )