1 ! Copyright (C) 2009, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs cache kernel math math.vectors sequences
4 fonts namespaces ui.text ui.text.private windows.uniscribe ;
7 SINGLETON: uniscribe-renderer
9 M: uniscribe-renderer string-dim
10 [ " " string-dim { 0 1 } v* ]
11 [ cached-script-string size>> ] if-empty ;
13 M: uniscribe-renderer flush-layout-cache
14 cached-script-strings get-global purge-cache ;
16 M: uniscribe-renderer string>image ( font string -- image loc )
17 cached-script-string script-string>image { 0 0 } ;
19 M: uniscribe-renderer x>offset ( x font string -- n )
21 cached-script-string x>line-offset 0 = [ 1 + ] unless
24 M: uniscribe-renderer offset>x ( n font string -- x )
25 [ 2drop 0 ] [ cached-script-string line-offset>x ] if-empty ;
27 M: uniscribe-renderer font-metrics ( font -- metrics )
28 " " cached-script-string metrics>> clone f >>width ;
30 M: uniscribe-renderer line-metrics ( font string -- metrics )
31 [ " " line-metrics clone 0 >>width ]
32 [ cached-script-string metrics>> 50 >>width 10 >>cap-height 10 >>x-height ]
35 uniscribe-renderer font-renderer set-global