Clean up line-metrics code
parent
ecf3d4f447
commit
f93b2f1c29
|
@ -46,7 +46,7 @@ TUPLE: line font line metrics dim bitmap age refs disposed ;
|
|||
: compute-line-metrics ( line -- line-metrics )
|
||||
0 <CGFloat> 0 <CGFloat> 0 <CGFloat>
|
||||
[ CTLineGetTypographicBounds ] 3keep [ *CGFloat ] tri@
|
||||
line-metrics boa ;
|
||||
metrics boa ;
|
||||
|
||||
: bounds>dim ( bounds -- dim )
|
||||
[ width>> ] [ [ ascent>> ] [ descent>> ] bi + ] bi
|
||||
|
@ -58,16 +58,16 @@ TUPLE: line font line metrics dim bitmap age refs disposed ;
|
|||
[let* | open-font [ font cache-font CFRetain |CFRelease ]
|
||||
line [ string open-font font foreground>> <CTLine> |CFRelease ]
|
||||
metrics [ line compute-line-metrics ]
|
||||
dim [ bounds bounds>dim ] |
|
||||
dim [ metrics bounds>dim ] |
|
||||
dim [
|
||||
{
|
||||
[ font background>> >rgba-components CGContextSetRGBFillColor ]
|
||||
[ 0 0 dim first2 <CGRect> CGContextFillRect ]
|
||||
[ 0 metrics descent>> CGContextSetTextPosition ]
|
||||
[ 0 metrics descent>> ceiling CGContextSetTextPosition ]
|
||||
[ line swap CTLineDraw ]
|
||||
} cleave
|
||||
] with-bitmap-context
|
||||
[ open-font line bounds dim ] dip 0 0 f
|
||||
[ open-font line metrics dim ] dip 0 0 f
|
||||
]
|
||||
line boa
|
||||
] with-destructors ;
|
||||
|
|
|
@ -34,6 +34,8 @@ ARTICLE: "fonts" "Fonts"
|
|||
"Useful constants:"
|
||||
{ $subsection monospace-font }
|
||||
{ $subsection sans-serif-font }
|
||||
{ $subsection serif-font } ;
|
||||
{ $subsection serif-font }
|
||||
"A data type for font metrics. The " { $vocab-link "fonts" } " vocabulary does not provide any means of computing font metrics, it simply defines a common data type that other vocabularies, such as " { $vocab-link "ui.text" } " may use:"
|
||||
{ $subsection metrics } ;
|
||||
|
||||
ABOUT: "fonts"
|
||||
|
|
|
@ -16,6 +16,9 @@ TUPLE: font name size bold? italic? foreground background ;
|
|||
: font-with-background ( font color -- font' )
|
||||
[ clone ] dip >>background ; inline
|
||||
|
||||
: font-with-size ( font size -- font' )
|
||||
[ clone ] dip >>size ; inline
|
||||
|
||||
: reverse-video-font ( font -- font )
|
||||
clone dup
|
||||
[ foreground>> ] [ background>> ] bi
|
||||
|
@ -46,4 +49,4 @@ TUPLE: font name size bold? italic? foreground background ;
|
|||
"monospace" >>name
|
||||
12 >>size ;
|
||||
|
||||
TUPLE: line-metrics width ascent descent leading ;
|
||||
TUPLE: metrics width ascent descent leading ;
|
|
@ -72,7 +72,9 @@ M: core-text-renderer offset>x ( n font string -- x )
|
|||
CTLineGetOffsetForStringIndex ;
|
||||
|
||||
M: core-text-renderer line-metrics ( font string -- metrics )
|
||||
cached-line metrics>> ;
|
||||
[ " " line-metrics clone 0 >>width ]
|
||||
[ cached-line metrics>> ]
|
||||
if-empty ;
|
||||
|
||||
M: core-text-renderer free-fonts ( fonts -- )
|
||||
values dispose-each ;
|
||||
|
|
|
@ -86,10 +86,10 @@ SYMBOL: dpi
|
|||
face-size face-size-y-scale FT_MulFix ;
|
||||
|
||||
: init-ascent ( font face -- font )
|
||||
dup face-y-max swap font-units>pixels >>ascent ; inline
|
||||
[ face-y-max ] keep font-units>pixels >>ascent ; inline
|
||||
|
||||
: init-descent ( font face -- font )
|
||||
dup face-y-min swap font-units>pixels >>descent ; inline
|
||||
[ face-y-min ] keep font-units>pixels >>descent ; inline
|
||||
|
||||
: init-font ( font -- font )
|
||||
dup handle>> init-ascent
|
||||
|
|
|
@ -55,6 +55,7 @@ ARTICLE: "text-rendering" "Rendering text"
|
|||
{ $subsection text-dim }
|
||||
{ $subsection text-width }
|
||||
{ $subsection text-height }
|
||||
{ $subsection line-metrics }
|
||||
"Converting screen locations to string offsets, and vice versa:"
|
||||
{ $subsection x>offset }
|
||||
{ $subsection offset>x }
|
||||
|
|
|
@ -50,7 +50,7 @@ M: sequence text-dim
|
|||
|
||||
: text-height ( font text -- h ) text-dim second ;
|
||||
|
||||
HOOK: text-metrics font-renderer ( font string -- metrics )
|
||||
HOOK: line-metrics font-renderer ( font string -- metrics )
|
||||
|
||||
GENERIC# draw-text 1 ( font text loc -- )
|
||||
|
||||
|
|
Loading…
Reference in New Issue