NSMutableAttributeString, fonts and alignment
NSMutableAttributeString, fonts and alignment
- Subject: NSMutableAttributeString, fonts and alignment
- From: "Simson Garfinkel" <email@hidden>
- Date: Tue, 18 Dec 2001 23:36:17 -0500
Here is a section from NSAttributedString.h:
/* Predefined character attributes for text. If the key is not in the
dictionary, then use the default values as des\
cribed below.
*/
APPKIT_EXTERN NSString *NSFontAttributeName; /* NSFont, default
Helvetica 12 */
APPKIT_EXTERN NSString *NSParagraphStyleAttributeName; /*
NSParagraphStyle, default defaultParagraphStyle */
APPKIT_EXTERN NSString *NSForegroundColorAttributeName; /* NSColor, default
blackColor */
APPKIT_EXTERN NSString *NSUnderlineStyleAttributeName; /* int, default 0:
no underline */
APPKIT_EXTERN NSString *NSSuperscriptAttributeName; /* int, default 0
*/
APPKIT_EXTERN NSString *NSBackgroundColorAttributeName; /* NSColor, default
nil: no background */
APPKIT_EXTERN NSString *NSAttachmentAttributeName; /*
NSTextAttachment, default nil */
APPKIT_EXTERN NSString *NSLigatureAttributeName; /* int, default 1:
default ligatures, 0: no ligatures, 2: a\
ll ligatures */
APPKIT_EXTERN NSString *NSBaselineOffsetAttributeName; /* float, in
points; offset from baseline, default 0 */
APPKIT_EXTERN NSString *NSKernAttributeName; /* float, amount to
modify default kerning, if 0, kerning o\
ff */
APPKIT_EXTERN NSString *NSLinkAttributeName; /* ??? id
<NSTextLink>; link */
What's missing is some way of setting the strings alignment. That appears to
be set through the setAlignment:range: method.
Unfortunately, there appears to be no way to put an Alignment into a
dictionary. (It's not defined). So I have code that looks like this:
- (void)setColor:(NSColor *)aColor
{
[dict setObject:aColor forKey:NSForegroundColorAttributeName];
[text setAttributes:dict range:NSMakeRange(0,[text length])];
[text setAlignment:NSCenterTextAlignment range:NSMakeRange(0,[text
length])]; // bug in appkit
}
I think that this is pretty ugly. I'm sure that I can hard-code the correct
key for alignment, but I don't want to do that. I want to know what the
APPKIT_EXTERN is. Anybody know anything I don't?