On Apr 8, 2010, at 7:02 AM, vincent habchi wrote:

> Hi there,
> 
> I've been fiddling with NSAttributedString lately, and the way to display 
> them through Core Text. In the docs, I've read that NSAttributedString and 
> CFAttributedStringRef were supposed to be "toll free" bridged; I assumed that 
> meant that one could be used in lieu of the other with (or maybe even 
> without) a simple cast.
> 
> But I found this is not true. Specifically, I was getting strange errors like 
> "CFSet[Stroke|Fill]ColorFromColor : invalid context 0x0" each time I printed 
> my NSAttributedString by CTLineDraw(), although I had a perfectly valid 
> context. The glyph were drawn, but always in black, while I was attempting to 
> get another color via the NSForegroundColorAttributeName. At the end, I had 
> to replace the pair (NSColor, NSForeground…) by a (CGColorRef, 
> kCTForeground…), and now it works.
> 
> Is that supposed to be a "normal" behavior, did I misunderstand the meaning 
> of "toll free", or is it a bug?

NSAttributedString and CFAttributedStringRef "the data structure" are toll free 
bridged, but that just means that the objects themselves can be interchanged.  
The problem is that, like an NSDictionary, they can store arbitrary objects 
that may not be toll free bridged - in this case, NSColor and CGColorRef are 
not interchangeable, nor are the keys NSForegroundColor and 
kCTForegroundColorAttributeName documented as the same.

So CTLineDraw expects to have the color specified as a CGColorRef in 
kCTForegroundColorAttributeName, while drawString: expects to have the color 
specified as an NSColor in NSForegroundColor.



Glenn Andreas                      [email protected] 
The most merciful thing in the world ... is the inability of the human mind to 
correlate all its contents - HPL

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to