1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors colors.constants combinators kernel math
7 CONSTANT: default-serif-font-name "serif"
8 CONSTANT: default-sans-serif-font-name "sans-serif"
9 CONSTANT: default-monospace-font-name "monospace"
11 CONSTANT: default-font-size 12
13 SYMBOL: default-font-foreground-color
14 COLOR: black default-font-foreground-color set-global
16 SYMBOL: default-font-background-color
17 COLOR: white default-font-background-color set-global
19 TUPLE: font name size bold? italic? foreground background ;
23 default-font-foreground-color get >>foreground
24 default-font-background-color get >>background ; inline
26 : font-with-foreground ( font color -- font' )
27 [ clone ] dip >>foreground ; inline
29 : font-with-background ( font color -- font' )
30 [ clone ] dip >>background ; inline
32 : font-with-size ( font size -- font' )
33 [ clone ] dip >>size ; inline
35 : reverse-video-font ( font -- font )
37 [ foreground>> >>background ]
38 [ background>> >>foreground ] bi ;
40 : derive-font ( base font -- font' )
43 [ [ name>> ] either? >>name ]
44 [ [ size>> ] either? >>size ]
45 [ [ bold?>> ] either? >>bold? ]
46 [ [ italic?>> ] either? >>italic? ]
47 [ [ foreground>> ] either? >>foreground ]
48 [ [ background>> ] either? >>background ]
52 : serif-font ( -- font )
54 default-serif-font-name >>name
55 default-font-size >>size ;
57 : sans-serif-font ( -- font )
59 default-sans-serif-font-name >>name
60 default-font-size >>size ;
62 : monospace-font ( -- font )
64 default-monospace-font-name >>name
65 default-font-size >>size ;
67 : strip-font-colors ( font -- font' )
68 clone f >>background f >>foreground ;
70 TUPLE: metrics width ascent descent height leading cap-height x-height ;
72 : compute-height ( metrics -- metrics )
73 dup [ ascent>> ] [ descent>> ] bi + >>height ; inline
75 TUPLE: selection string start end color ;
77 C: <selection> selection