Get Height of RTF text - failing in El Capitan

I’ve been updating my app to El Capitan (rather late I know) but find there is a problem with determining the height of RTF formatted text.

In Yosemite and prior I was able to use the MacOSLib method shown below - it gave a reasonable approximation of the text height - but in El Capitan it always returns a value of 18.

I have tried 2 variations of MBS code one for plain text, one for rtf. Neither give the correct height in Yosemite (but the result does at least vary) whereas both return 15 in El Capitan.

Good old Xojo code gives the correct(ish) height of plain text in both Yosemite and El Capitan - but cannot return the height of rtf text.

Has anyone noticed similar or have a solution?

By the way, the code is intended to give the height of objects by calculation only and not based on a physical control.

[code] //Xojo - plain text - doesn’t give rtf height but does work in both Yosemite and El Capitan
dim p as new picture(1,1,32)
dim g as graphics = p.Graphics
dim t as integer = g.StringHeight( rtf, width)
return t

//MacOSLib Version - OK in Yosemite, gives constant height of 18 in El Capitan
dim options as integer = NSString.NSStringDrawingUsesLineFragmentOrigin //multiline
options = options + nsString.NSStringDrawingUsesFontLeading
dim size as cocoa.NSSize
size.width = width
size.height = 10
dim nsd as NSData = nsdata.CreateWithString( RTF )
if nsd <> nil then
dim nsa as NSAttributedString = NSAttributedString.CreateFromRTF( nsd )
dim rect as cocoa.NSRect = nsa.BoundingRect(size, options)
return rect.h
else
return 0
end if

//MBS Version 1 - plain text - works in Yosemite, gives constant height of 15 in El Capitan
dim g as new NSGraphicsMBS
dim options as integer = _
g.NSStringDrawingUsesLineFragmentOrigin +_
g.NSStringDrawingUsesFontLeading
dim s as new NSSizeMBS( width, 10)
dim r as NSRectMBS = g.boundingRectWithSize( rtf, s, options)
return r.Height

//MBS version 2- RTF - doesn’t give correct rtf height - works in Yosemite but not El Capitan
dim p as new picture(1,1,32)
dim i as new NSImageMBS§
dim g as new NSGraphicsMBS(i)
dim options as integer = _
g.NSStringDrawingUsesLineFragmentOrigin +_
g.NSStringDrawingUsesFontLeading
dim s as new NSSizeMBS( width, 10)
dim r as NSRectMBS = g.boundingRectWithSize( rtf, s, options)
return r.Height[/code]

Not sure but maybe it’s boundingRectWithSize being deprecated. There’s a new version that takes also a context.
https://forums.developer.apple.com/thread/11936

Ah, I think I’ve found the problem. El Capitan seems to take note of the height of NSSize (which I had set to a nominal 10) and constrains the boundingRect to that size(ish), whereas Yosemite seemed to ignore that constraint.

So setting the height to the height of the current screen - allows me to get a reasonable approximation of the height of the RTF text without constraining it.