
Attempting to open this crashes - this, of course, is progress. I have isolated the crash and added it to the unit test which also crashes. This means that when I have the fix I can cast the fix in 'stone'.
This blog is a personal diary of a project to port Cello, an MFC based application, to OSX and Cocoa.

CFRange selectedRange;
CFAttributedString attributedString;
CTParagraphStyleRef paragraphStyle;
// get the underlying string
CFStringRef str = CFAttributedStringGetString(attributedString);
CFIndex parBeginIndex, parEndIndex;
// get the get the bounds of the paragraph
CFStringGetParagraphBounds(str, selectedRange, &parBeginIndex, &parEndIndex, NULL);
// convert it to a CFRange
CFRange paragraphRange = CFRangeMake(parBeginIndex, parEndIndex - parBeginIndex);
// Set the attributes
CFAttributedStringSetAttribute(attributedString, paragraphRange, kCTParagraphStyleAttributeName, paragraphStyle);
CFAttributedStringRef ReadRTF(CFURLRef url)I modified Apple's CoreTextTest sample code to import RTF using the code sinippet above. The resulting CFAttributedString works fine in Core Text except that NSColor is not suported. The console fills with messages:
{
NSData *data = [NSData dataWithContentsOfURL:(NSURL *)url];
NSAttributedString *result = [[NSAttributedString alloc] initWithRTF:data documentAttributes:NULL];
return (CFAttributedStringRef) result;
}
CGContextSetFillColorWithColor: invalid contextThe reason behind this seems to be that cocoa attributed string uses NSColor, Core Text uses CGColor the two objects are not toll free bridged and are not the same. This does no look like a hard thing to fix up after reading, and before writing.
CGContextSetStrokeColorWithColor: invalid context
Converting and then back converting to, demonstrably, the same thing gives some idea of correctness but it does not guarantee that what you have done is correct, it just asserts that these two components are consistent. When I can look at the glyph shapes in the final output format I will be able to check this.
CPTAssert(::CFEqual(origPath, shape.AsPath()));