ui.text.core-text: Add patch from issue #1402 by kusumotonorio

clean-linux-x86-64
Doug Coleman 2019-06-22 09:50:13 -05:00
parent 44cbe83984
commit 3df3ad4257
1 changed files with 13 additions and 9 deletions

View File

@ -1,10 +1,9 @@
! Copyright (C) 2009, 2010 Slava Pestov. ! Copyright (C) 2009, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: assocs accessors alien core-graphics.types core-text USING: accessors cache core-graphics.types core-text
core-text.fonts kernel hashtables namespaces sequences ui.text core-text.fonts io.encodings.string io.encodings.utf16n kernel
ui.text.private destructors combinators core-foundation locals math math.vectors namespaces sequences ui.text
core-foundation.strings math math.vectors init colors ui.text.private ;
colors.constants cache arrays images ;
IN: ui.text.core-text IN: ui.text.core-text
SINGLETON: core-text-renderer SINGLETON: core-text-renderer
@ -45,14 +44,19 @@ M: core-text-renderer flush-layout-cache
M: core-text-renderer string>image ( font string -- image loc ) M: core-text-renderer string>image ( font string -- image loc )
cached-line [ line>image ] [ loc>> scale-dim ] bi ; cached-line [ line>image ] [ loc>> scale-dim ] bi ;
M: core-text-renderer x>offset ( x font string -- n ) M:: core-text-renderer x>offset ( x font string -- n )
x font string
[ 2drop 0 ] [ [ 2drop 0 ] [
cached-line line>> cached-line line>>
swap scale 0 <CGPoint> CTLineGetStringIndexForPosition swap scale 0 <CGPoint> CTLineGetStringIndexForPosition
] if-empty ; ] if-empty
2 * 0 swap string utf16n encode subseq
utf16n decode length ;
M: core-text-renderer offset>x ( n font string -- x ) M:: core-text-renderer offset>x ( n font string -- x )
cached-line line>> swap f font string cached-line line>>
0 n string subseq utf16n encode length 2 / >integer
f
CTLineGetOffsetForStringIndex unscale ; CTLineGetOffsetForStringIndex unscale ;
M: core-text-renderer font-metrics ( font -- metrics ) M: core-text-renderer font-metrics ( font -- metrics )