RTF Data height in TextArea vs Graphics using MBS

I am trying to show the same RTFData in both a textArea and a graphics object but the result is a different height of text in each.

As an example, I have a textarea (ta) and canvas (cnv) side by side, in the ta.textChanged event:

rtfData = Me.RTFDataMBS

and in a cnv.paint event, the somewhat convoluted:

If rtfData = Nil Then Return 
Dim NSA As NSAttributedStringMBS
nsa = NSAttributedStringMBS.attributedStringWithRTF(  rtfdata )

Dim c As CGContextMBS = CGContextMBS.contextWithCGContext(g.Handle(g.HandleTypeCGContextRef) ) 
c.ScaleCTM(1, 1)

Dim nsg As nsGraphicsMBS = NSGraphicsMBS.graphicsContextWithCGContextHandle(c.handle) 
nsg.drawInRect( NSA, New NSRectMBS( 0, 0, Me.width, Me.height) )


Typing multiple lines of text into the textarea results in a different height of the text in the canvas.

Curiously though, using the same NSAttributed string method to get the height of the text, results in the correct height.

Dim nsG As New NSGraphicsMBS
Dim options As Integer = NSGraphicsMBS.NSStringDrawingUsesLineFragmentOrigin + NSGraphicsMBS.NSStringDrawingUsesFontLeading

Dim size As New NSSizeMBS
size.width = ta.width 

Dim nsa As NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithRTF( RTFData )
If nsa <> Nil Then
  Dim rect As NSRectMBS = nsG.boundingRectWithSize( nsa, size, options)
  cnv.height = rect.Height
  ta.height = rect.height
End If

Ah, I think I’ve found part of it. The problem was with textArea.rtfDataMBS. If I use textArea.styledText.rtfData instead it gets the same height with both objects for simple text.

But I still have problems with the position in which the text breaks long lines being inconsistent.