Friday, June 25, 2010

Getting Rich (text) with Cocoa

In the next REAL Studio 2010 r3 build that beta testers will soon receive, we've added support for RTF (Rich Text Format) to the TextArea control in Cocoa. The Carbon TextArea control of course already supports RTF so this is really just for compatibility.

I tested the RTF support and what I found interesting was how the text rendering differed from Carbon to Cocoa. Consider the following two examples:

This is RTF rendered in Carbon:

This is RTF rendered in Cocoa:

You can see they are very different. The Cocoa rendered text is more condensed and harder to read. At first, I thought this was a bug. I opened the RTF file using TextEdit (which is a Cocoa application) and discovered that it's not a Cocoa bug, but a Carbon bug! Or to put it another way, the Carbon framework on Mac OS X appears to simply render RTF differently. In my case, I just chose a different font and now it looks great when I run my app under Cocoa.

By the way, the app I'm testing with is the same app I mentioned in the newsletter this month. With RTF now working, there is only one bug that would keep the app from shipping and two minor bugs that would be nice to see fixed before I ship it as a Cocoa app:

  1. The app prints a report and while it does print, the Print dialog doesn't close when it should.

  2. The about box doesn't display. Instead you get a generic Cocoa-created about box. (minor)

  3. The StaticText control renders its text 1 pixel too high (minor - for this app anyway).
It's good to see RTF working. We are making progress. There are still lots of annoying Cocoa bugs to fix but there's also a lot of stuff working well.


miescher said...

how about RTF for the Windows version?
Will it support pictures, bullet points, setting tab positions, margins, highlighting etc. ?

How about a multilingual spellchecker or sample application showing how to use a third party spellchecker via ole?

john m.

Keith DeLong said...

I've looked at post on two Macs running Safari 5. Neither one display the images.

Geoff Perlman said...

Keith - that's odd. I'm looking at it from Safari 5 and I can see the images.

Pharaoh Atem said...

What newsletter? I didn't get one about Cocoa...

Geoff Perlman said...

You can sign up for the monthly newsletter here:

Charles said...

I'm not quite sure whether the Carbon rendering bug is in the RB framework or in Mac OS X.

If it's in the RB framework, does RS plan to fix it?

If it's in Mac OS X, which version, Tiger, Leopard, Snow Leopard?

Would you clarify that, please?

Geoff Perlman said...

If you are referring to the difference between the RTF rendering in Carbon versus Cocoa, I'm not sure if I would call it a bug. But if it IS a bug, it's a bug in the Carbon libraries of Mac OS X and there would be nothing we can do about that. The fix for those that prefer how Cocoa renders text is to wait for us to ship our Cocoa-based platform layer and then recompile your projects with that.

Charles said...

Thanks, Geoff. Has the difference been reported to Apple, and if so, does Apple plan to investigate it?

Geoff Perlman said...

We haven't reported anything to Apple about it because Apple (a) knows there are differences both ways between Carbon and Cocoa and (b) has made it pretty clear that Carbon is deprecated for the most part. Cocoa is the future. That's why we are moving to Cocoa. Apple is unlikely to do much in Carbon at this point.