Sweet, thanks Norman. I’d seen that link before but focused on font metrics which doesn’t bound. boundingRect gives the actual bounds, duh. Here’s my test code fwiw, looks like all NSFont functionality is in MacOSLib. Time to update my class
[code]//Property
pic As Picture
//PushButton
Sub Action()
const CocoaLib = “Cocoa”
declare function NSClassFromString lib CocoaLib (aClassName as CFStringRef) as Ptr
declare function fontWithName lib CocoaLib selector “fontWithName:size:” _
(cls As Ptr, fontName As CFStringRef, fontSize As single) As Ptr
declare function glyphWithName lib CocoaLib selector “glyphWithName:” _
(inst as Ptr, glyphName as CFStringRef) as UInt32
declare function boundingRectForGlyph lib CocoaLib selector “boundingRectForGlyph:” _
(inst as Ptr, glyph as UInt32) as NSRect
dim testFont As String = “Zapfino” //fldFont.Text
dim testSize As integer = 150 //Val(fldSize.Text)
dim testLetter As String = “q” //fldLetter.Text
dim fontClass As Ptr = NSClassFromString(“NSFont”)
dim aFont As Ptr = fontWithName(fontClass, testFont, testSize)
dim glyph As UInt32 = glyphWithName(aFont, testLetter)
dim rect As NSRect = boundingRectForGlyph(aFont, glyph)
dim p As new Picture(500, 500, 32)
p.Graphics.ForeColor = &c000000
p.Graphics.TextFont = testFont
p.Graphics.TextSize = testSize
p.Graphics.DrawString testLetter, 200, 200
p.Graphics.ForeColor = &cFF000080
p.Graphics.DrawRect 200+rect.x, 200-rect.y-rect.h, rect.w, rect.h
pic = p
display.Invalidate
End Sub
//Canvas “display”
Sub Paint(g As Graphics, areas() As REALbasic.Rect)
if pic <> nil then g.DrawPicture pic, 0, 0
End Sub
//Structure
NSRect
x As single
y As single
w As single
h As single
[/code]