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
FUNCTION: CGRect CTLineGetImageBounds ( CTLineRef line, CGContextRef context )
-SYMBOL: retina?
-
MEMO: make-attributes ( open-font color -- hashtable )
[
kCTForegroundColorAttributeName ,,
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
[ 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>> ;
: 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
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 [
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>
! 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>
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 ;
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 ;