]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/core-text/core-text.factor
Updating code to use with-out-parameters
[factor.git] / basis / core-text / core-text.factor
index de3b5ac715caecf4d238ffcd913ed08407624d97..4de8b2c06a4fd3ef0df9b1dd5473420134e5b93d 100644 (file)
@@ -1,23 +1,24 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays alien alien.c-types alien.syntax kernel destructors
-accessors fry words hashtables strings sequences memoize assocs math
-math.vectors math.rectangles math.functions locals init namespaces
-combinators fonts colors cache core-foundation core-foundation.strings
+USING: arrays alien alien.c-types alien.data alien.syntax kernel
+destructors accessors fry words hashtables strings sequences
+memoize assocs math math.order math.vectors math.rectangles
+math.functions locals init namespaces combinators fonts colors
+cache core-foundation core-foundation.strings
 core-foundation.attributed-strings core-foundation.utilities
-core-graphics core-graphics.types core-text.fonts core-text.utilities ;
+core-graphics core-graphics.types core-text.fonts ;
 IN: core-text
 
 TYPEDEF: void* CTLineRef
 
-C-GLOBAL: kCTFontAttributeName
-C-GLOBAL: kCTKernAttributeName
-C-GLOBAL: kCTLigatureAttributeName
-C-GLOBAL: kCTForegroundColorAttributeName
-C-GLOBAL: kCTParagraphStyleAttributeName
-C-GLOBAL: kCTUnderlineStyleAttributeName
-C-GLOBAL: kCTVerticalFormsAttributeName
-C-GLOBAL: kCTGlyphInfoAttributeName
+C-GLOBAL: CFStringRef kCTFontAttributeName
+C-GLOBAL: CFStringRef kCTKernAttributeName
+C-GLOBAL: CFStringRef kCTLigatureAttributeName
+C-GLOBAL: CFStringRef kCTForegroundColorAttributeName
+C-GLOBAL: CFStringRef kCTParagraphStyleAttributeName
+C-GLOBAL: CFStringRef kCTUnderlineStyleAttributeName
+C-GLOBAL: CFStringRef kCTVerticalFormsAttributeName
+C-GLOBAL: CFStringRef kCTGlyphInfoAttributeName
 
 FUNCTION: CTLineRef CTLineCreateWithAttributedString ( CFAttributedStringRef string ) ;
 
@@ -46,11 +47,11 @@ ERROR: not-a-string object ;
         CTLineCreateWithAttributedString
     ] with-destructors ;
 
-TUPLE: line line metrics image loc dim disposed ;
+TUPLE: line < disposable line metrics image loc dim ;
 
 : typographic-bounds ( line -- width ascent descent leading )
-    0 <CGFloat> 0 <CGFloat> 0 <CGFloat>
-    [ CTLineGetTypographicBounds ] 3keep [ *CGFloat ] tri@ ; inline
+    { CGFloat CGFloat CGFloat }
+    [ CTLineGetTypographicBounds ] [ ] with-out-parameters ; inline
 
 : store-typographic-bounds ( metrics width ascent descent leading -- metrics )
     {
@@ -109,30 +110,36 @@ TUPLE: line line metrics image loc dim disposed ;
 
 :: <line> ( font string -- line )
     [
-        [let* | open-font [ font cache-font ]
-                line [ string open-font font foreground>> <CTLine> |CFRelease ]
-
-                rect [ line line-rect ]
-                (loc) [ rect CGRect-origin CGPoint>loc ]
-                (dim) [ rect CGRect-size CGSize>dim ]
-                (ext) [ (loc) (dim) v+ ]
-                loc [ (loc) [ floor ] map ]
-                ext [ (loc) (dim) [ + ceiling ] 2map ]
-                dim [ ext loc [ - >integer ] 2map ]
-                metrics [ open-font line compute-line-metrics ] |
-            line metrics
-            dim [
-                {
-                    [ font dim fill-background ]
-                    [ loc dim line string fill-selection-background ]
-                    [ loc set-text-position ]
-                    [ [ line ] dip CTLineDraw ]
-                } cleave
-            ] make-bitmap-image
-            metrics loc dim line-loc
-            metrics metrics>dim
-        ]
-        f line boa
+        line new-disposable
+
+        font cache-font :> open-font
+        string open-font font foreground>> <CTLine> |CFRelease :> line
+
+        line line-rect :> rect
+        rect origin>> CGPoint>loc :> (loc)
+        rect size>> CGSize>dim :> (dim)
+        (loc) (dim) v+ :> (ext)
+        (loc) [ floor ] map :> loc
+        (loc) (dim) [ + ceiling ] 2map :> ext
+        ext loc [ - >integer 1 max ] 2map :> dim
+        open-font line compute-line-metrics :> metrics
+
+        line >>line
+
+        metrics >>metrics
+
+        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 loc dim line-loc >>loc
+
+        metrics metrics>dim >>dim
     ] with-destructors ;
 
 M: line dispose* line>> CFRelease ;
@@ -142,4 +149,4 @@ SYMBOL: cached-lines
 : cached-line ( font string -- line )
     cached-lines get [ <line> ] 2cache ;
 
-[ <cache-assoc> cached-lines set-global ] "core-text" add-init-hook
\ No newline at end of file
+[ <cache-assoc> cached-lines set-global ] "core-text" add-startup-hook