1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel arrays sequences math math.order cache opengl
4 opengl.gl strings fonts colors accessors namespaces
12 : world-text-handle ( world -- handle )
13 dup text-handle>> [ <cache-assoc> >>text-handle ] unless
16 HOOK: flush-layout-cache font-renderer ( -- )
18 [ flush-layout-cache ] flush-layout-cache-hook set-global
20 HOOK: string-dim font-renderer ( font string -- dim )
22 HOOK: string-width font-renderer ( font string -- w )
24 HOOK: string-height font-renderer ( font string -- h )
26 M: object string-dim [ string-width ] [ string-height ] 2bi 2array ;
28 M: object string-width string-dim first ;
30 M: object string-height string-dim second ;
32 HOOK: draw-string font-renderer ( font string -- )
34 HOOK: free-fonts font-renderer ( world -- )
36 : combine-text-dim ( dim1 dim2 -- dim3 )
43 HOOK: x>offset font-renderer ( x font string -- n )
45 HOOK: offset>x font-renderer ( n font string -- x )
47 GENERIC: text-dim ( font text -- dim )
49 M: string text-dim string-dim ;
52 [ { 0 0 } ] 2dip [ string-dim combine-text-dim ] with each ;
54 : text-width ( font text -- w ) text-dim first ;
56 : text-height ( font text -- h ) text-dim second ;
58 HOOK: font-metrics font-renderer ( font -- metrics )
60 HOOK: line-metrics font-renderer ( font string -- metrics )
62 GENERIC: draw-text ( font text -- )
64 M: string draw-text draw-string ;
66 M: selection draw-text draw-string ;
72 [ [ 0.0 ] 2dip string-height 0.0 glTranslated ] 2bi
76 USING: vocabs.loader system combinators ;
79 { [ os macosx? ] [ "core-text" ] }
80 { [ os windows? ] [ "uniscribe" ] }
81 { [ os unix? ] [ "pango" ] }
82 } cond "ui.text." prepend require