[futurebasic] Re: [FB] Font height

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2006 : Group Archive : Group : All Groups

From: Bernie <fb.list@...>
Date: Wed, 29 Mar 2006 20:21:04 +0100
tedd asked:

> What's the function call (or whatever) you use to detect font height?


To get info on a specified font (rather than the current graphics  
port font), you could use fn FetchFontInfo(). Also, I wonder if  
GetThemeTextDimensions is a suitable alternative?

'----------
#define FMFontFamily as SInt16
toolbox fn FMGetFontFamilyFromName( Str255 iName ) = FMFontFamily
toolbox fn FetchFontInfo( SInt16 fontID, SInt16 fontSize, ¬
SInt16 fontStyle, FontInfo *info ) = OSStatus
toolbox fn GetThemeTextDimensions( CFStringRef inString, ¬
SInt16 inFont, SInt16 inState, Boolean inBool, point *outPoint, ¬
short *outBaseline ) = OSStatus

dim as FontInfo    info
dim as point     @ dims
dim as SInt16    @ baseline
dim as short       fontHeight
dim as OSStatus    ignore

window 1
text fn FMGetFontFamilyFromName( "Lucida Grande" ), 11


// FetchFontInfo
ignore = fn FetchFontInfo( ¬
fn FMGetFontFamilyFromName( "Lucida Grande" ), 11, 0, @info )
fontHeight = info.ascent + info.descent + info.leading
print fontHeight


// GetThemeTextDims
ignore = fn GetThemeTextDimensions( fn CFSTR( " " ), ¬
_kThemeCurrentPortFont, _kThemeStateUnavailable, _false, ¬
@dims, @baseline )
print dims.v%


do
HandleEvents
until 0
'----------

BTW, as of OS X 10.4, both GetFontInfo and FetchFontInfo are deprecated.


Bernie