]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/text/core-text/core-text.factor
Merge remote-tracking branch '8byte-jose/win32-unc-fix'
[factor.git] / basis / ui / text / core-text / core-text.factor
1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs accessors alien core-graphics.types core-text
4 core-text.fonts kernel hashtables namespaces sequences ui.text
5 ui.text.private destructors combinators core-foundation
6 core-foundation.strings math math.vectors init colors
7 colors.constants cache arrays images ;
8 IN: ui.text.core-text
9
10 SINGLETON: core-text-renderer
11
12 M: core-text-renderer string-dim
13     [ " " string-dim { 0 1 } v* ]
14     [ cached-line dim>> ]
15     if-empty ;
16
17 M: core-text-renderer flush-layout-cache
18     cached-lines get purge-cache ;
19
20 M: core-text-renderer string>image ( font string -- image loc )
21     cached-line [ line>image ] [ loc>> ] bi ;
22
23 M: core-text-renderer x>offset ( x font string -- n )
24     [ 2drop 0 ] [
25         cached-line line>>
26         swap 0 <CGPoint> CTLineGetStringIndexForPosition
27     ] if-empty ;
28
29 M: core-text-renderer offset>x ( n font string -- x )
30     cached-line line>> swap f
31     CTLineGetOffsetForStringIndex ;
32
33 M: core-text-renderer font-metrics ( font -- metrics )
34     cache-font-metrics ;
35
36 M: core-text-renderer line-metrics ( font string -- metrics )
37     [ " " line-metrics clone 0 >>width ]
38     [ cached-line metrics>> ]
39     if-empty ;
40
41 core-text-renderer font-renderer set-global