diff --git a/basis/core-text/core-text.factor b/basis/core-text/core-text.factor index 014956aba2..d409bd9b0f 100644 --- a/basis/core-text/core-text.factor +++ b/basis/core-text/core-text.factor @@ -47,7 +47,10 @@ ERROR: not-a-string object ; CTLineCreateWithAttributedString ] with-destructors ; -TUPLE: line < disposable line metrics image loc dim ; +TUPLE: line < disposable line metrics image loc dim render-info ; + +TUPLE: render-info font string loc dim ; +C: render-info : typographic-bounds ( line -- width ascent descent leading ) { CGFloat CGFloat CGFloat } @@ -126,22 +129,34 @@ TUPLE: line < disposable line metrics image loc dim ; line >>line - metrics >>metrics + font string loc dim >>render-info - dim [ - { - [ font dim fill-background ] - [ loc dim line string fill-selection-background ] - [ loc set-text-position ] - [ [ line ] dip CTLineDraw ] - } cleave - ] make-bitmap-image >>image + metrics >>metrics metrics loc dim line-loc >>loc metrics metrics>dim >>dim ] with-destructors ; +:: render ( line -- line image ) + line line>> :> ctline + line render-info>> string>> :> string + line render-info>> font>> :> font + line render-info>> loc>> :> loc + line render-info>> dim>> :> dim + + line dim [ + { + [ font dim fill-background ] + [ loc dim ctline string fill-selection-background ] + [ loc set-text-position ] + [ [ ctline ] dip CTLineDraw ] + } cleave + ] make-bitmap-image ; + +: line>image ( line -- image ) + dup image>> [ render >>image ] unless image>> ; + M: line dispose* line>> CFRelease ; SYMBOL: cached-lines diff --git a/basis/ui/text/core-text/core-text.factor b/basis/ui/text/core-text/core-text.factor index db8e43cde5..e864c828e8 100644 --- a/basis/ui/text/core-text/core-text.factor +++ b/basis/ui/text/core-text/core-text.factor @@ -18,7 +18,7 @@ M: core-text-renderer flush-layout-cache cached-lines get purge-cache ; M: core-text-renderer string>image ( font string -- image loc ) - cached-line [ image>> ] [ loc>> ] bi ; + cached-line [ line>image ] [ loc>> ] bi ; M: core-text-renderer x>offset ( x font string -- n ) [ 2drop 0 ] [ @@ -38,4 +38,4 @@ M: core-text-renderer line-metrics ( font string -- metrics ) [ cached-line metrics>> ] if-empty ; -core-text-renderer font-renderer set-global \ No newline at end of file +core-text-renderer font-renderer set-global