]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/core-text/core-text.factor
io.encodings.utf16: add a utf16n word for native utf16 type.
[factor.git] / basis / core-text / core-text.factor
index 98b6c4a189eaf2ac2e7f38ba2fa07ec127b0bd14..44d55f5fcd398ff1e46196bf6f4166b4768c809b 100644 (file)
@@ -4,8 +4,9 @@ USING: accessors alien.c-types alien.data alien.syntax arrays
 assocs cache colors combinators core-foundation
 core-foundation.attributed-strings core-foundation.strings
 core-graphics core-graphics.types core-text.fonts destructors
-fonts init kernel locals make math math.functions math.order
-math.vectors memoize namespaces sequences strings ;
+fonts init io.encodings.string io.encodings.utf16 kernel locals
+make math math.functions math.order math.vectors memoize
+namespaces sequences strings ;
 IN: core-text
 
 TYPEDEF: void* CTLineRef
@@ -88,7 +89,9 @@ render-loc render-dim ;
     bi-curry* bi ;
 
 : selection-rect ( dim line selection -- rect )
-    [ start>> ] [ end>> ] bi
+    [let [ start>> ] [ end>> ] [ string>> ] tri :> ( start end string )
+     start end [ 0 swap string subseq utf16n encode length 2 / >integer ] bi@
+    ]
     [ f CTLineGetOffsetForStringIndex round ] bi-curry@ bi
     [ drop nip 0 ] [ swap - swap second ] 3bi <CGRect> ;