RE: Can't get an NSColor attribute from an attributed string, but can get an NSFont attribute.
RE: Can't get an NSColor attribute from an attributed string, but can get an NSFont attribute.
- Subject: RE: Can't get an NSColor attribute from an attributed string, but can get an NSFont attribute.
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Mon, 28 Apr 2003 14:02:27 -0400
Perhaps the color is not in the NSNamedColorSpace. The docs say
colorNameComponent will raise exception otherwise. The color might be in
NSCalibratedRGBColorSpace, for instance. This suggests that you either have
to test the color to make sure it is in the right colorspace, or convert it
to the right colorspace. I haven't test it, but this seems like it would
work:
colorName = [[[attributedStringFromSourceText
attribute:NSForegroundColorAttributeName
atIndex:i
effectiveRange:&letterRange]
colorUsingColorSpaceName:@"NSNamedColorSpace"]
colorNameComponent];
Another idea:
colorName = [[attributedStringFromSourceText
attribute:NSForegroundColorAttributeName
atIndex:i
effectiveRange:&letterRange]
description];
Jonathan
>
-----Original Message-----
>
From: email@hidden
>
[mailto:email@hidden]On Behalf Of Mark Ogilvie
>
Sent: Monday, April 28, 2003 12:19 PM
>
To: email@hidden
>
Subject: Can't get an NSColor attribute from an attributed string, but
>
can get an NSFont attribute.
>
>
>
It's puzzling. I've been working with the NSAttributedString example,
>
and I've been able to get the name of the current NSFont in use by an
>
individual character using this code. i is the current number in a
>
for-loop, range is NSMakeRange (letterCount, 0)
>
>
// get the font that the letter is using
>
fontName = [[attributedStringFromSourceText
>
attribute:NSFontAttributeName
>
>
atIndex:letterCount
>
>
effectiveRange:&letterRange] fontName];
>
>
with fontName returning an NSString and the font being assigned to the
>
NSString fontName variable. Works fine. Even works if I put a string
>
that is initialiazed like this NSString * font = [NSString
>
alloc]initWithString:@"NSFont"]; and put font instead of
>
NSFontAttributedName in the attribute parameter.
>
>
But when I try to do the same to get the color of the individual letter
>
using this
>
>
// get the color that the letter is using
>
colorName = [[attributedStringFromSourceText
>
attribute:NSForegroundColorAttributeName
>
>
atIndex:i
>
effectiveRange:&letterRange]
>
colorNameComponent];
>
>
colorName comes up as invalid in the debugger with a null value when I
>
print out the description.
>
>
NSForegroundColorAttributeName is the attributed identifier in the
>
documentation, and using colorNameComponent should return a string of
>
the colors name. I've tested this with different colors and just
>
leaving the text black, but no luck. What is the difference between
>
the NSFont attribute name and the NSColor attribute name? Does
>
NSForegroundColorAttributeName return an NSColor object that can not be
>
translated into a string by colorNameComponent?
>
>
I've also tried this
>
for(letterCount = 0; letterCount < [attributedStringFromSourceText
>
length]; letterCount++){
>
// get the color that the letter is using
>
colorName = [attributedStringFromSourceText
>
attribute:NSForegroundColorAttributeName
>
atIndex:i
>
>
effectiveRange:&letterRange];
>
color = [colorName colorNameComponent];
>
>
with colorName being created this way
>
NSColor * colorName = [[NSColor alloc] init];
>
and color being an NSString.
>
>
which gets me this run-time error
>
2003-04-28 10:43:38.150 ColorReporterTry2[721] *** -colorNameComponent
>
not defined for the NSColor NSCalibratedRGBColorSpace 0.4 0.8 0.8 1;
>
need to first convert colorspace.
>
>
ColorReporterTry2 has exited with status 0.
>
>
I've checked the documentation, which fills me in on just enough about
>
color spaces and color list to be a little more mystified. Any advice
>
on what I'm doing wrong?
>
>
Thanks
>
Mark
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.