diff --git a/basis/ui/text/core-text/core-text.factor b/basis/ui/text/core-text/core-text.factor index 0d720ac0b1..db8e43cde5 100644 --- a/basis/ui/text/core-text/core-text.factor +++ b/basis/ui/text/core-text/core-text.factor @@ -1,11 +1,10 @@ -! Copyright (C) 2009 Slava Pestov. +! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: assocs accessors alien core-graphics.types core-text -core-text.fonts kernel hashtables namespaces sequences -ui.gadgets.worlds ui.text ui.text.private opengl opengl.gl -opengl.textures destructors combinators core-foundation -core-foundation.strings math math.vectors init colors colors.constants -cache arrays images ; +core-text.fonts kernel hashtables namespaces sequences ui.text +ui.text.private destructors combinators core-foundation +core-foundation.strings math math.vectors init colors +colors.constants cache arrays images ; IN: ui.text.core-text SINGLETON: core-text-renderer @@ -18,13 +17,8 @@ M: core-text-renderer string-dim M: core-text-renderer flush-layout-cache cached-lines get purge-cache ; -: rendered-line ( font string -- texture ) - world get world-text-handle [ - cached-line [ image>> ] [ loc>> ] bi - ] 2cache ; - -M: core-text-renderer draw-string ( font string -- ) - rendered-line draw-texture ; +M: core-text-renderer string>image ( font string -- image loc ) + cached-line [ image>> ] [ loc>> ] bi ; M: core-text-renderer x>offset ( x font string -- n ) [ 2drop 0 ] [ diff --git a/basis/ui/text/pango/pango.factor b/basis/ui/text/pango/pango.factor index 92c4fe5c75..39a7b30348 100644 --- a/basis/ui/text/pango/pango.factor +++ b/basis/ui/text/pango/pango.factor @@ -1,8 +1,8 @@ -! Copyright (C) 2009 Slava Pestov. +! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien.c-types assocs cache kernel math math.vectors -namespaces opengl.textures pango.cairo pango.layouts ui.gadgets.worlds -ui.text ui.text.private pango sequences ; +USING: accessors assocs cache kernel math math.vectors +namespaces pango.cairo pango.layouts ui.text ui.text.private +pango sequences ; IN: ui.text.pango SINGLETON: pango-renderer @@ -14,13 +14,8 @@ M: pango-renderer string-dim M: pango-renderer flush-layout-cache cached-layouts get purge-cache ; -: rendered-layout ( font string -- texture ) - world get world-text-handle [ - cached-layout [ image>> ] [ text-position vneg ] bi - ] 2cache ; - -M: pango-renderer draw-string ( font string -- ) - rendered-layout draw-texture ; +M: pango-renderer string>image ( font string -- image loc ) + cached-layout [ image>> ] [ text-position vneg ] bi ; M: pango-renderer x>offset ( x font string -- n ) cached-layout swap x>line-offset ; diff --git a/basis/ui/text/text-docs.factor b/basis/ui/text/text-docs.factor index 8b3b5ad24f..3070b96c76 100644 --- a/basis/ui/text/text-docs.factor +++ b/basis/ui/text/text-docs.factor @@ -48,6 +48,10 @@ HELP: line-metrics { $values { "font" font } { "string" string } { "metrics" line-metrics } } { $contract "Outputs a " { $link metrics } " object with text measurements." } ; +HELP: string>image +{ $values { "font" font } { "string" string } { "image" image } { "loc" "a pair of real numbers" } } +{ $description "Renders a line of text into an image." } ; + ARTICLE: "text-rendering" "Rendering text" "The " { $vocab-link "ui.text" } " vocabulary provides a cross-platform interface to the operating system's native font rendering engine. Currently, it uses Core Text on Mac OS X, Uniscribe on Windows and Pango on X11." { $subsections "fonts" } @@ -64,7 +68,7 @@ ARTICLE: "text-rendering" "Rendering text" offset>x } "Rendering text:" -{ $subsections draw-text } +{ $subsections draw-text string>image } "Low-level text protocol for UI backends:" { $subsections string-width diff --git a/basis/ui/text/text-tests.factor b/basis/ui/text/text-tests.factor index 7ee901dc80..d365168ba1 100644 --- a/basis/ui/text/text-tests.factor +++ b/basis/ui/text/text-tests.factor @@ -1,6 +1,7 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: tools.test ui.text fonts math accessors kernel sequences ; +USING: tools.test ui.text images fonts math arrays accessors kernel +sequences ; IN: ui.text.tests [ t ] [ 0 sans-serif-font "aaa" offset>x zero? ] unit-test @@ -20,3 +21,5 @@ IN: ui.text.tests [ t ] [ sans-serif-font "" text-dim first zero? ] unit-test [ f ] [ sans-serif-font font-metrics height>> zero? ] unit-test + +[ t ] [ serif-font "Hello world" string>image [ image? ] [ pair? ] bi* and ] unit-test diff --git a/basis/ui/text/text.factor b/basis/ui/text/text.factor index 6d5c7e56a6..fa85b997e1 100644 --- a/basis/ui/text/text.factor +++ b/basis/ui/text/text.factor @@ -1,8 +1,8 @@ -! Copyright (C) 2009 Slava Pestov. +! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel arrays sequences math math.order cache opengl -opengl.gl strings fonts colors accessors namespaces -ui.gadgets.worlds ; +USING: kernel arrays assocs sequences math math.order cache +opengl opengl.gl opengl.textures strings fonts colors accessors +namespaces ui.gadgets.worlds ; IN: ui.text image font-renderer ( font string -- image loc ) + +> ] when empty? ; + +: draw-string ( font string -- ) + dup string-empty? [ 2drop ] [ + world get world-text-handle + [ string>image ] 2cache + draw-texture + ] if ; + +PRIVATE> + GENERIC: draw-text ( font text -- ) M: string draw-text draw-string ; diff --git a/basis/ui/text/uniscribe/uniscribe.factor b/basis/ui/text/uniscribe/uniscribe.factor index d5e836044b..b9e5e1f694 100644 --- a/basis/ui/text/uniscribe/uniscribe.factor +++ b/basis/ui/text/uniscribe/uniscribe.factor @@ -1,8 +1,7 @@ -! Copyright (C) 2009 Slava Pestov. +! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs cache kernel math math.vectors sequences fonts -namespaces opengl.textures ui.text ui.text.private ui.gadgets.worlds -windows.uniscribe ; +USING: accessors assocs cache kernel math math.vectors sequences +fonts namespaces ui.text ui.text.private windows.uniscribe ; IN: ui.text.uniscribe SINGLETON: uniscribe-renderer @@ -14,14 +13,8 @@ M: uniscribe-renderer string-dim M: uniscribe-renderer flush-layout-cache cached-script-strings get purge-cache ; -: rendered-script-string ( font string -- texture ) - world get world-text-handle - [ cached-script-string image>> { 0 0 } ] - 2cache ; - -M: uniscribe-renderer draw-string ( font string -- ) - dup dup selection? [ string>> ] when empty? - [ 2drop ] [ rendered-script-string draw-texture ] if ; +M: uniscribe-renderer string>image ( font string -- image loc ) + cached-script-string image>> { 0 0 } ; M: uniscribe-renderer x>offset ( x font string -- n ) [ 2drop 0 ] [