     {
         [ >>width ]
         [ >>ascent ]
-        [ >>descent ]
+        [ dup 0 < [ -1 * ] when >>descent ]
         [ >>leading ]
     } spread ; inline
 

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 ;
IN: core-text

TYPEDEF: void* CTLineRef

    bi-curry* bi ;

: selection-rect ( dim line selection -- rect )
    [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> ;

