1 ! Copyright (C) 2011-2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: accessors assocs calendar colors combinators fonts
5 formatting hashtables io kernel make math math.parser sequences
6 splitting strings xml.entities ;
12 : escape-string ( str -- str' )
26 GENERIC: pdf-value ( obj -- str )
28 M: number pdf-value number>string ;
30 M: t pdf-value drop "true" ;
32 M: f pdf-value drop "false" ;
35 >rgba-components drop "%f %f %f" sprintf ;
45 { "sans-serif" [ "/Helvetica" ] }
46 { "serif" [ "/Times" ] }
47 { "monospace" [ "/Courier" ] }
48 [ " is unsupported" append throw ]
51 [ [ bold?>> ] [ italic?>> ] bi or [ "-" append ] when ]
52 [ bold?>> [ "Bold" append ] when ]
53 [ italic?>> [ "Italic" append ] when ]
55 name>> { "sans-serif" "monospace" } member?
56 [ "Italic" "Oblique" replace ] when
59 "/BaseFont " prepend ,
61 ] { } make join-lines ;
63 M: timestamp pdf-value
64 "%Y%m%d%H%M%S" strftime "D:" prepend ;
67 escape-string "(" ")" surround ;
70 [ "[" % [ pdf-value % " " % ] each "]" % ] "" make ;
72 M: hashtable pdf-value
75 [ swap % " " % pdf-value % "\n" % ] assoc-each
79 : pdf-write ( obj -- )