diff --git a/basis/cocoa/application/application-docs.factor b/basis/cocoa/application/application-docs.factor index 60a0232a2c..a2c711c3ea 100644 --- a/basis/cocoa/application/application-docs.factor +++ b/basis/cocoa/application/application-docs.factor @@ -8,12 +8,6 @@ HELP: { CF>string } related-words -HELP: -{ $values { "seq" "a sequence of " { $link alien } " instances" } { "alien" alien } } -{ $description "Allocates an autoreleased " { $snippet "CFArray" } "." } ; - -{ } related-words - HELP: with-autorelease-pool { $values { "quot" quotation } } { $description "Sets up a new " { $snippet "NSAutoreleasePool" } ", calls the quotation and frees the pool." } ; diff --git a/basis/cocoa/application/application.factor b/basis/cocoa/application/application.factor index ab2b6375a9..9437051dad 100644 --- a/basis/cocoa/application/application.factor +++ b/basis/cocoa/application/application.factor @@ -1,27 +1,17 @@ ! Copyright (C) 2006, 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.syntax io kernel namespaces core-foundation -core-foundation.arrays core-foundation.data core-foundation.strings cocoa.messages cocoa cocoa.classes cocoa.runtime sequences threads init summary kernel.private assocs ; IN: cocoa.application : ( str -- alien ) -> autorelease ; -: ( seq -- alien ) -> autorelease ; -: ( number -- alien ) -> autorelease ; -: ( byte-array -- alien ) -> autorelease ; -: ( assoc -- alien ) - NSMutableDictionary over assoc-size -> dictionaryWithCapacity: - [ - [ - spin -> setObject:forKey: - ] curry assoc-each - ] keep ; -: NSApplicationDelegateReplySuccess 0 ; -: NSApplicationDelegateReplyCancel 1 ; -: NSApplicationDelegateReplyFailure 2 ; +C-ENUM: +NSApplicationDelegateReplySuccess +NSApplicationDelegateReplyCancel +NSApplicationDelegateReplyFailure ; : with-autorelease-pool ( quot -- ) NSAutoreleasePool -> new slip -> release ; inline @@ -45,7 +35,8 @@ FUNCTION: void NSBeep ( ) ; [ NSNotificationCenter -> defaultCenter ] dip -> removeObserver: ; -: cocoa-app ( quot -- ) [ call NSApp -> run ] with-cocoa ; inline +: cocoa-app ( quot -- ) + [ call NSApp -> run ] with-cocoa ; inline : install-delegate ( receiver delegate -- ) -> alloc -> init -> setDelegate: ; diff --git a/basis/cocoa/pasteboard/pasteboard.factor b/basis/cocoa/pasteboard/pasteboard.factor index 888f5452e2..ef2f828a14 100644 --- a/basis/cocoa/pasteboard/pasteboard.factor +++ b/basis/cocoa/pasteboard/pasteboard.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2006, 2008 Slava Pestov. +! Copyright (C) 2006, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien.accessors arrays kernel cocoa.messages cocoa.classes cocoa.application sequences cocoa core-foundation @@ -15,7 +15,7 @@ IN: cocoa.pasteboard dup [ CF>string ] when ; : set-pasteboard-types ( seq pasteboard -- ) - swap f -> declareTypes:owner: drop ; + swap -> autorelease f -> declareTypes:owner: drop ; : set-pasteboard-string ( str pasteboard -- ) NSStringPboardType diff --git a/basis/cocoa/plists/plists.factor b/basis/cocoa/plists/plists.factor index cf68f9864a..d751c90b2b 100644 --- a/basis/cocoa/plists/plists.factor +++ b/basis/cocoa/plists/plists.factor @@ -1,42 +1,29 @@ -! Copyright (C) 2007, 2008 Slava Pestov. +! Copyright (C) 2007, 2009 Slava Pestov. +! Copyright (C) 2008 Joe Groff. ! See http://factorcode.org/license.txt for BSD license. -USING: strings arrays hashtables assocs sequences +USING: strings arrays hashtables assocs sequences fry macros cocoa.messages cocoa.classes cocoa.application cocoa kernel namespaces io.backend math cocoa.enumeration byte-arrays -combinators alien.c-types core-foundation core-foundation.data ; +combinators alien.c-types words core-foundation +core-foundation.data core-foundation.utilities ; IN: cocoa.plists -GENERIC: >plist ( value -- plist ) - -M: number >plist - ; -M: t >plist - ; -M: f >plist - ; -M: string >plist - ; -M: byte-array >plist - ; -M: hashtable >plist - [ [ >plist ] bi@ ] assoc-map ; -M: sequence >plist - [ >plist ] map ; +: >plist ( value -- plist ) >cf -> autorelease ; : write-plist ( assoc path -- ) - [ >plist ] [ normalize-path ] bi* 0 - -> writeToFile:atomically: + [ >plist ] [ normalize-path ] bi* 0 -> writeToFile:atomically: [ "write-plist failed" throw ] unless ; DEFER: plist> +) ( NSString -- string ) -> UTF8String ; : (plist-NSNumber>) ( NSNumber -- number ) dup -> doubleValue dup >integer = - [ -> longLongValue ] - [ -> doubleValue ] if ; + [ -> longLongValue ] [ -> doubleValue ] if ; : (plist-NSData>) ( NSData -- byte-array ) dup -> length [ -> getBytes: ] keep ; @@ -48,21 +35,26 @@ DEFER: plist> dup [ [ -> valueForKey: ] keep swap [ plist> ] bi@ 2array ] with NSFastEnumeration-map >hashtable ; -: plist> ( plist -- value ) - { - { [ dup NSString -> isKindOfClass: c-bool> ] [ (plist-NSString>) ] } - { [ dup NSNumber -> isKindOfClass: c-bool> ] [ (plist-NSNumber>) ] } - { [ dup NSData -> isKindOfClass: c-bool> ] [ (plist-NSData>) ] } - { [ dup NSArray -> isKindOfClass: c-bool> ] [ (plist-NSArray>) ] } - { [ dup NSDictionary -> isKindOfClass: c-bool> ] [ (plist-NSDictionary>) ] } - [ ] - } cond ; - : (read-plist) ( NSData -- id ) NSPropertyListSerialization swap kCFPropertyListImmutable f f [ -> propertyListFromData:mutabilityOption:format:errorDescription: ] keep *void* [ -> release "read-plist failed" throw ] when* ; +MACRO: objc-class-case ( alist -- quot ) + [ [ '[ dup _ execute -> isKindOfClass: c-bool> ] ] dip ] assoc-map '[ _ cond ] ; + +PRIVATE> + +: plist> ( plist -- value ) + { + { NSString [ (plist-NSString>) ] } + { NSNumber [ (plist-NSNumber>) ] } + { NSData [ (plist-NSData>) ] } + { NSArray [ (plist-NSArray>) ] } + { NSDictionary [ (plist-NSDictionary>) ] } + { NSObject [ ] } + } objc-class-case ; + : read-plist ( path -- assoc ) normalize-path NSData swap -> dataWithContentsOfFile: diff --git a/basis/core-foundation/attributed-strings/attributed-strings.factor b/basis/core-foundation/attributed-strings/attributed-strings.factor index 16acfdd74e..07633b1f78 100644 --- a/basis/core-foundation/attributed-strings/attributed-strings.factor +++ b/basis/core-foundation/attributed-strings/attributed-strings.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.syntax kernel core-foundation -core-foundation.strings core-foundation.dictionaries ; +USING: alien.syntax kernel destructors core-foundation +core-foundation.utilities ; IN: core-foundation.attributed-strings TYPEDEF: void* CFAttributedStringRef @@ -13,7 +13,7 @@ FUNCTION: CFAttributedStringRef CFAttributedStringCreate ( ) ; : ( string alist -- alien ) - [ ] [ ] bi* - [ [ kCFAllocatorDefault ] 2dip CFAttributedStringCreate ] - [ [ CFRelease ] bi@ ] - 2bi ; \ No newline at end of file + [ + [ >cf &CFRelease ] bi@ + [ kCFAllocatorDefault ] 2dip CFAttributedStringCreate + ] with-destructors ; \ No newline at end of file diff --git a/basis/core-foundation/data/data.factor b/basis/core-foundation/data/data.factor index a26204b001..c708eacecc 100644 --- a/basis/core-foundation/data/data.factor +++ b/basis/core-foundation/data/data.factor @@ -1,55 +1,20 @@ ! Copyright (C) 2008 Joe Groff. ! See http://factorcode.org/license.txt for BSD license. -USING: alien.syntax alien.c-types sequences kernel math ; +USING: alien.c-types alien.syntax core-foundation.numbers kernel math +sequences core-foundation.numbers ; IN: core-foundation.data TYPEDEF: void* CFDataRef -TYPEDEF: void* CFNumberRef TYPEDEF: void* CFSetRef -TYPEDEF: int CFNumberType -CONSTANT: kCFNumberSInt8Type 1 -CONSTANT: kCFNumberSInt16Type 2 -CONSTANT: kCFNumberSInt32Type 3 -CONSTANT: kCFNumberSInt64Type 4 -CONSTANT: kCFNumberFloat32Type 5 -CONSTANT: kCFNumberFloat64Type 6 -CONSTANT: kCFNumberCharType 7 -CONSTANT: kCFNumberShortType 8 -CONSTANT: kCFNumberIntType 9 -CONSTANT: kCFNumberLongType 10 -CONSTANT: kCFNumberLongLongType 11 -CONSTANT: kCFNumberFloatType 12 -CONSTANT: kCFNumberDoubleType 13 -CONSTANT: kCFNumberCFIndexType 14 -CONSTANT: kCFNumberNSIntegerType 15 -CONSTANT: kCFNumberCGFloatType 16 -CONSTANT: kCFNumberMaxType 16 - TYPEDEF: int CFPropertyListMutabilityOptions CONSTANT: kCFPropertyListImmutable 0 CONSTANT: kCFPropertyListMutableContainers 1 CONSTANT: kCFPropertyListMutableContainersAndLeaves 2 -FUNCTION: CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType theType, void* valuePtr ) ; - FUNCTION: CFDataRef CFDataCreate ( CFAllocatorRef allocator, uchar* bytes, CFIndex length ) ; FUNCTION: CFTypeID CFGetTypeID ( CFTypeRef cf ) ; -GENERIC: ( number -- alien ) - -M: integer - [ f kCFNumberLongLongType ] dip CFNumberCreate ; - -M: float - [ f kCFNumberDoubleType ] dip CFNumberCreate ; - -M: t - drop f kCFNumberIntType 1 CFNumberCreate ; - -M: f - drop f kCFNumberIntType 0 CFNumberCreate ; - : ( byte-array -- alien ) - [ f ] dip dup length CFDataCreate ; + [ f ] dip dup length CFDataCreate ; \ No newline at end of file diff --git a/basis/core-foundation/numbers/authors.txt b/basis/core-foundation/numbers/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/basis/core-foundation/numbers/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/basis/core-foundation/numbers/numbers-tests.factor b/basis/core-foundation/numbers/numbers-tests.factor new file mode 100644 index 0000000000..1c50f2dcb2 --- /dev/null +++ b/basis/core-foundation/numbers/numbers-tests.factor @@ -0,0 +1,4 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test core-foundation.numbers ; +IN: core-foundation.numbers.tests diff --git a/basis/core-foundation/numbers/numbers.factor b/basis/core-foundation/numbers/numbers.factor new file mode 100644 index 0000000000..f01f522d61 --- /dev/null +++ b/basis/core-foundation/numbers/numbers.factor @@ -0,0 +1,42 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: alien.c-types alien.syntax kernel math core-foundation ; +IN: core-foundation.numbers + +TYPEDEF: void* CFNumberRef + +TYPEDEF: int CFNumberType +CONSTANT: kCFNumberSInt8Type 1 +CONSTANT: kCFNumberSInt16Type 2 +CONSTANT: kCFNumberSInt32Type 3 +CONSTANT: kCFNumberSInt64Type 4 +CONSTANT: kCFNumberFloat32Type 5 +CONSTANT: kCFNumberFloat64Type 6 +CONSTANT: kCFNumberCharType 7 +CONSTANT: kCFNumberShortType 8 +CONSTANT: kCFNumberIntType 9 +CONSTANT: kCFNumberLongType 10 +CONSTANT: kCFNumberLongLongType 11 +CONSTANT: kCFNumberFloatType 12 +CONSTANT: kCFNumberDoubleType 13 +CONSTANT: kCFNumberCFIndexType 14 +CONSTANT: kCFNumberNSIntegerType 15 +CONSTANT: kCFNumberCGFloatType 16 +CONSTANT: kCFNumberMaxType 16 + +FUNCTION: CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType theType, void* valuePtr ) ; + +GENERIC: ( number -- alien ) + +M: integer + [ f kCFNumberLongLongType ] dip CFNumberCreate ; + +M: float + [ f kCFNumberDoubleType ] dip CFNumberCreate ; + +M: t + drop f kCFNumberIntType 1 CFNumberCreate ; + +M: f + drop f kCFNumberIntType 0 CFNumberCreate ; + diff --git a/basis/core-foundation/numbers/tags.txt b/basis/core-foundation/numbers/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/core-foundation/numbers/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/core-foundation/utilities/authors.txt b/basis/core-foundation/utilities/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/basis/core-foundation/utilities/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/basis/core-foundation/utilities/tags.txt b/basis/core-foundation/utilities/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/core-foundation/utilities/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/core-foundation/utilities/utilities-tests.factor b/basis/core-foundation/utilities/utilities-tests.factor new file mode 100644 index 0000000000..fb3deb2ca5 --- /dev/null +++ b/basis/core-foundation/utilities/utilities-tests.factor @@ -0,0 +1,4 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test core-foundation.utilities ; +IN: core-foundation.utilities.tests diff --git a/basis/core-foundation/utilities/utilities.factor b/basis/core-foundation/utilities/utilities.factor new file mode 100644 index 0000000000..3dd760f7c4 --- /dev/null +++ b/basis/core-foundation/utilities/utilities.factor @@ -0,0 +1,21 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: math assocs kernel sequences byte-arrays strings +hashtables alien destructors +core-foundation.numbers core-foundation.strings +core-foundation.arrays core-foundation.dictionaries +core-foundation.data core-foundation ; +IN: core-foundation.utilities + +GENERIC: (>cf) ( obj -- cf ) + +M: number (>cf) ; +M: t (>cf) ; +M: f (>cf) ; +M: string (>cf) ; +M: byte-array (>cf) ; +M: hashtable (>cf) [ [ (>cf) &CFRelease ] bi@ ] assoc-map ; +M: sequence (>cf) [ (>cf) &CFRelease ] map ; +M: alien (>cf) CFRetain ; + +: >cf ( obj -- cf ) [ (>cf) ] with-destructors ; \ No newline at end of file diff --git a/basis/core-graphics/core-graphics.factor b/basis/core-graphics/core-graphics.factor index 5c9fa03e76..52f7c4439a 100644 --- a/basis/core-graphics/core-graphics.factor +++ b/basis/core-graphics/core-graphics.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien.c-types alien.destructors alien.syntax -destructors fry kernel math sequences +destructors fry kernel math sequences libc core-graphics.types ; IN: core-graphics @@ -69,15 +69,25 @@ FUNCTION: void CGContextSetTextPosition ( FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pname, GLint* params ) ; -: ( data dim -- context ) - [ - [ first2 8 ] keep first 4 * - CGColorSpaceCreateDeviceRGB &CGColorSpaceRelease - kCGImageAlphaPremultipliedLast CGBitmapContextCreate - ] with-destructors ; +FUNCTION: void* CGBitmapContextGetData ( CGContextRef c ) ; + + ( dim -- context ) + [ product "uint" malloc-array &free ] [ first2 8 ] [ first 4 * ] tri + CGColorSpaceCreateDeviceRGB &CGColorSpaceRelease + kCGImageAlphaPremultipliedLast CGBitmapContextCreate + [ "CGBitmapContextCreate failed" throw ] unless* ; + +: bitmap-data ( bitmap dim -- data ) + [ CGBitmapContextGetData ] + [ product "uint" heap-size * ] bi* + memory>byte-array ; + +PRIVATE> : with-bitmap-context ( dim quot -- data ) - '[ - [ product "uint" ] keep - [ &CGContextRelease @ ] [ drop ] 2bi + [ + [ [ &CGContextRelease ] keep ] dip + [ nip call ] [ drop bitmap-data ] 3bi ] with-destructors ; inline diff --git a/basis/core-text/core-text-tests.factor b/basis/core-text/core-text-tests.factor index 3d9e6e4dd7..aa3c835e8f 100644 --- a/basis/core-text/core-text-tests.factor +++ b/basis/core-text/core-text-tests.factor @@ -3,11 +3,11 @@ USING: tools.test core-text core-foundation core-foundation.dictionaries destructors arrays kernel generalizations math accessors -combinators ; +combinators hashtables ; IN: core-text.tests : test-font ( -- object ) - "Helvetica" 12 ; + "Helvetica" kCTFontNameAttribute associate ; [ ] [ test-font CFRelease ] unit-test diff --git a/basis/core-text/core-text.factor b/basis/core-text/core-text.factor index 309decf4aa..0544e29c42 100644 --- a/basis/core-text/core-text.factor +++ b/basis/core-text/core-text.factor @@ -1,28 +1,16 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays alien alien.c-types alien.syntax kernel destructors words -parser accessors fry words hashtables sequences memoize -assocs math math.functions locals init +USING: arrays alien alien.c-types alien.syntax kernel +destructors words parser accessors fry words hashtables +sequences memoize assocs math math.functions locals init core-foundation core-foundation.strings -core-foundation.attributed-strings +core-foundation.attributed-strings core-foundation.utilities core-graphics core-graphics.types ; IN: core-text TYPEDEF: void* CTLineRef TYPEDEF: void* CTFontRef - -FUNCTION: CTFontRef CTFontCreateWithName ( - CFStringRef name, - CGFloat size, - CGAffineTransform* matrix -) ; - -: ( name size -- font ) - [ - [ &CFRelease ] dip f CTFontCreateWithName - ] with-destructors ; - -MEMO: cached-font ( name size -- font ) ; +TYPEDEF: void* CTFontDescriptorRef << @@ -33,6 +21,52 @@ MEMO: cached-font ( name size -- font ) ; >> +C-GLOBAL: kCTFontSymbolicTrait +C-GLOBAL: kCTFontWeightTrait +C-GLOBAL: kCTFontWidthTrait +C-GLOBAL: kCTFontSlantTrait + +C-GLOBAL: kCTFontNameAttribute +C-GLOBAL: kCTFontDisplayNameAttribute +C-GLOBAL: kCTFontFamilyNameAttribute +C-GLOBAL: kCTFontStyleNameAttribute +C-GLOBAL: kCTFontTraitsAttribute +C-GLOBAL: kCTFontVariationAttribute +C-GLOBAL: kCTFontSizeAttribute +C-GLOBAL: kCTFontMatrixAttribute +C-GLOBAL: kCTFontCascadeListAttribute +C-GLOBAL: kCTFontCharacterSetAttribute +C-GLOBAL: kCTFontLanguagesAttribute +C-GLOBAL: kCTFontBaselineAdjustAttribute +C-GLOBAL: kCTFontMacintoshEncodingsAttribute +C-GLOBAL: kCTFontFeaturesAttribute +C-GLOBAL: kCTFontFeatureSettingsAttribute +C-GLOBAL: kCTFontFixedAdvanceAttribute +C-GLOBAL: kCTFontOrientationAttribute + +FUNCTION: CTFontDescriptorRef CTFontDescriptorCreateWithAttributes ( + CFDictionaryRef attributes +) ; + +FUNCTION: CTFontRef CTFontCreateWithName ( + CFStringRef name, + CGFloat size, + CGAffineTransform* matrix +) ; + +FUNCTION: CTFontRef CTFontCreateWithFontDescriptor ( + CTFontDescriptorRef descriptor, + CGFloat size, + CGAffineTransform* matrix +) ; + +: ( attrs -- font ) + [ + >cf &CFRelease + CTFontDescriptorCreateWithAttributes &CFRelease + 0.0 f CTFontCreateWithFontDescriptor + ] with-destructors ; + C-GLOBAL: kCTFontAttributeName C-GLOBAL: kCTKernAttributeName C-GLOBAL: kCTLigatureAttributeName @@ -114,7 +148,4 @@ PRIVATE> : cached-line ( string font -- line ) (cached-line) 0 >>age ; -[ - \ cached-font reset-memoized - \ (cached-line) reset-memoized -] "core-text" add-init-hook \ No newline at end of file +[ \ (cached-line) reset-memoized ] "core-text" add-init-hook \ No newline at end of file diff --git a/basis/ui/cocoa/text/text.factor b/basis/ui/cocoa/text/text.factor index 4e8d2aec70..c3472bc6c1 100644 --- a/basis/ui/cocoa/text/text.factor +++ b/basis/ui/cocoa/text/text.factor @@ -1,7 +1,10 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: assocs accessors alien core-graphics.types core-text kernel -namespaces sequences ui.gadgets.worlds ui.render opengl opengl.gl ; +hashtables namespaces sequences ui.gadgets.worlds ui.render +opengl opengl.gl destructors combinators combinators.smart +core-foundation core-foundation.dictionaries core-foundation.numbers +core-foundation.strings io.styles memoize ; IN: ui.cocoa.text SINGLETON: core-text-renderer @@ -13,13 +16,46 @@ CONSTANT: font-names { "serif" "Times" } } -USING: classes.algebra unicode.case.private ; +: (bold) ( -- ) 1.0 kCTFontWeightTrait set ; -: font-name/size ( font -- name size ) - [ first font-names at-default ] [ third ] bi ; +: (italic) ( -- ) 1.0 kCTFontSlantTrait set ; + +: font-traits ( style -- dictionary ) + [ + { + { plain [ ] } + { bold [ (bold) ] } + { italic [ (italic) ] } + { bold-italic [ (bold) (italic) ] } + } case + ] H{ } make-assoc ; + +: font-name-attr ( name -- ) + font-names at-default kCTFontNameAttribute set ; + +: font-traits-attr ( style -- ) + font-traits kCTFontTraitsAttribute set ; + +: font-size-attr ( size -- ) + kCTFontSizeAttribute set ; + +: font-attrs ( font -- dictionary ) + [ + [ + [ + [ font-name-attr ] + [ font-traits-attr ] + [ font-size-attr ] + tri* + ] input ; M: core-text-renderer open-font - dup alien? [ font-name/size cached-font ] unless ; + dup alien? [ cache-font ] unless ; : string-dim ( open-font string -- dim ) swap cached-line dim>> ; @@ -30,11 +66,13 @@ M: core-text-renderer string-width ( open-font string -- w ) M: core-text-renderer string-height ( open-font string -- h ) [ " " ] when-empty string-dim second ; -TUPLE: line-texture line texture age ; +TUPLE: line-texture line texture age disposed ; : ( line -- texture ) dup [ dim>> ] [ bitmap>> ] bi GL_RGBA make-texture - 0 \ line-texture boa ; + 0 f \ line-texture boa ; + +M: line-texture dispose* texture>> delete-texture ; : line-texture ( string open-font -- texture ) world get fonts>> [ cached-line ] 2cache ; @@ -55,6 +93,9 @@ M: core-text-renderer draw-string ( font string loc -- ) [ swap open-font line-texture draw-line-texture ] with-translation ; M: core-text-renderer x>offset ( x font string -- n ) - swap cached-line swap 0 CTLineGetStringIndexForPosition ; + swap open-font cached-line line>> swap 0 CTLineGetStringIndexForPosition ; + +M: core-text-renderer free-fonts ( fonts -- ) + values dispose-each ; core-text-renderer font-renderer set-global \ No newline at end of file diff --git a/basis/ui/freetype/freetype.factor b/basis/ui/freetype/freetype.factor index 06cdc71209..c62c3e6485 100644 --- a/basis/ui/freetype/freetype.factor +++ b/basis/ui/freetype/freetype.factor @@ -41,8 +41,7 @@ M: font hashcode* drop font hashcode* ; ] bind ; M: freetype-renderer free-fonts ( world -- ) - [ handle>> select-gl-context ] - [ fonts>> [ nip second free-sprites ] assoc-each ] bi ; + values [ second free-sprites ] each ; : ttf-name ( font style -- name ) 2array H{ diff --git a/basis/ui/ui.factor b/basis/ui/ui.factor index 5b270cdf9e..357f2cea97 100644 --- a/basis/ui/ui.factor +++ b/basis/ui/ui.factor @@ -60,9 +60,12 @@ M: world graft* [ f >>handle drop ] tri ; : (ungraft-world) ( world -- ) - [ free-fonts ] - [ hand-clicked close-global ] - [ hand-gadget close-global ] tri ; + { + [ handle>> select-gl-context ] + [ fonts>> free-fonts ] + [ hand-clicked close-global ] + [ hand-gadget close-global ] + } cleave ; M: world ungraft* [ (ungraft-world) ]