]> gitweb.factorcode.org Git - factor.git/commitdiff
core-text: remove retina? flag in favor of gl-scale-factor
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 3 Jan 2022 20:32:03 +0000 (12:32 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 3 Jan 2022 20:32:03 +0000 (12:32 -0800)
basis/core-text/core-text.factor
basis/ui/backend/cocoa/views/views.factor
basis/ui/text/core-text/core-text.factor

index df5d724536b02f44273164148cc196b951da8bfd..d94d850ab5e678e96d283a96148594f80fc77af6 100644 (file)
@@ -5,7 +5,7 @@ assocs cache classes colors combinators core-foundation
 core-foundation.attributed-strings core-foundation.strings
 core-graphics core-graphics.types core-text.fonts destructors
 fonts init io.encodings.string io.encodings.utf16n kernel make
-math math.functions math.order math.vectors namespaces
+math math.functions math.order math.vectors namespaces opengl
 sequences strings ;
 IN: core-text
 
@@ -32,8 +32,6 @@ FUNCTION: double CTLineGetTypographicBounds ( CTLineRef line, CGFloat* ascent, C
 
 FUNCTION: CGRect CTLineGetImageBounds ( CTLineRef line, CGContextRef context )
 
-SYMBOL: retina?
-
 MEMO: make-attributes ( open-font color -- hashtable )
     [
         kCTForegroundColorAttributeName ,,
@@ -113,10 +111,13 @@ render-loc render-dim render-ext ;
     loc first
     metrics ascent>> dim second loc second + - 1 - 2array ;
 
+: load-2x? ( -- ? )
+    gl-scale-factor get-global [ 1.0 > ] [ f ] if* ;
+
 :: <line> ( font string -- line )
     [
         line new-disposable
-        font retina? get-global [ cache-font@2x ] [ cache-font ] if :> open-font
+        font load-2x? [ cache-font@2x ] [ cache-font ] if :> open-font
         string open-font font foreground>> <CTLine> |CFRelease :> line
         open-font line compute-line-metrics
         [ >>metrics ] [ metrics>dim >>dim ] bi
@@ -159,7 +160,7 @@ render-loc render-dim render-ext ;
             [ loc set-text-position ]
             [ [ ctline ] dip CTLineDraw ]
         } cleave
-    ] make-bitmap-image retina? get-global >>2x? ;
+    ] make-bitmap-image load-2x? >>2x? ;
 
 : line>image ( line -- image )
     dup image>> [ render >>image ] unless image>> ;
@@ -171,4 +172,4 @@ SYMBOL: cached-lines
 : cached-line ( font string -- line )
     cached-lines get-global [ <line> ] 2cache ;
 
-[ <cache-assoc> cached-lines set-global f retina? set-global ] "core-text" add-startup-hook
+[ <cache-assoc> cached-lines set-global ] "core-text" add-startup-hook
index b6663cf5cb3bcd1152d81d41a3bf2c82c43ddad2..10968c9d06cb9e6e0ba17afad350e60e3c2f214c 100644 (file)
@@ -278,20 +278,12 @@ PRIVATE>
 
     METHOD: void prepareOpenGL [
 
-        self SEL: setWantsBestResolutionOpenGLSurface:
-        -> respondsToSelector: c-bool> [
+        self -> backingScaleFactor
+        [ 1.0 > ] keep f ? gl-scale-factor set-global
 
-            self 1 { void { id SEL char } } ?-> setWantsBestResolutionOpenGLSurface:
+        cached-lines get-global clear-assoc
 
-            self { double { id SEL } } ?-> backingScaleFactor
-
-            dup 1.0 > [
-                gl-scale-factor set-global t retina? set-global
-                cached-lines get-global clear-assoc
-            ] [ drop ] if
-
-            self -> update
-        ] when
+        self -> update
     ] ;
 
     METHOD: void reshape [
@@ -706,14 +698,8 @@ PRIVATE>
 
     METHOD: void windowDidChangeBackingProperties: id notification
     [
-
-        notification -> object dup SEL: backingScaleFactor
-        -> respondsToSelector: c-bool> [
-            { double { id SEL } } ?-> backingScaleFactor
-
-            [ [ 1.0 > ] keep f ? gl-scale-factor set-global ]
-            [ 1.0 > retina? set-global ] bi
-        ] [ drop ] if
+        notification -> object -> backingScaleFactor
+        [ 1.0 > ] keep f ? gl-scale-factor set-global
     ] ;
 ;CLASS>
 
index fe7351adc62424002662173f002db5c13fa63bf1..f8e93690b9403d7c31da4c3072b4b9b320904ccb 100644 (file)
@@ -2,31 +2,26 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors cache core-graphics.types core-text
 core-text.fonts io.encodings.string io.encodings.utf16n kernel
-math math.vectors namespaces sequences ui.text ui.text.private ;
+math math.vectors namespaces opengl sequences ui.text
+ui.text.private ;
 IN: ui.text.core-text
 SINGLETON: core-text-renderer
 
 <PRIVATE
 
-: unscale ( m -- n )
-    retina? get-global [ 2.0 / ] when ; inline
-
-: scale ( m -- n )
-    retina? get-global [ 2.0 * ] when ; inline
-
 : scale-dim ( dim -- dim' )
-    retina? get-global [ [ 2.0 / ] map ] when ; inline
+    gl-scale-factor get-global [ [ gl-unscale ] map ] when ; inline
 
 : scale-metrics ( metrics -- metrics' )
-    retina? get-global [
+    gl-scale-factor get-global [
         clone
-            [ 2.0 / ] change-width
-            [ 2.0 / ] change-ascent
-            [ 2.0 / ] change-descent
-            [ 2.0 / ] change-height
-            [ 2.0 / ] change-leading
-            [ 2.0 / ] change-cap-height
-            [ 2.0 / ] change-x-height
+            [ gl-unscale ] change-width
+            [ gl-unscale ] change-ascent
+            [ gl-unscale ] change-descent
+            [ gl-unscale ] change-height
+            [ gl-unscale ] change-leading
+            [ gl-unscale ] change-cap-height
+            [ gl-unscale ] change-x-height
     ] when ; inline
 
 PRIVATE>
@@ -46,7 +41,7 @@ M:: core-text-renderer x>offset ( x font string -- n )
     x font string
     [ 2drop 0 ] [
         cached-line line>>
-        swap scale 0 <CGPoint> CTLineGetStringIndexForPosition
+        swap gl-scale 0 <CGPoint> CTLineGetStringIndexForPosition
         2 * 0 swap string utf16n encode subseq
         utf16n decode length
     ] if-empty ;
@@ -55,7 +50,7 @@ M:: core-text-renderer offset>x ( n font string -- x )
     font string cached-line line>>
     0 n string subseq utf16n encode length 2 /i
     f
-    CTLineGetOffsetForStringIndex unscale ;
+    CTLineGetOffsetForStringIndex gl-unscale ;
 
 M: core-text-renderer font-metrics
     cache-font-metrics ;