"exponent" action in NSTextView subclass
"exponent" action in NSTextView subclass
- Subject: "exponent" action in NSTextView subclass
- From: email@hidden
- Date: Wed, 7 Mar 2007 10:05:00 +0100 (CET)
- Importance: Normal
Hello all,
in my NSTextView subclass I'm trying to implement a method (triggered by
a menu item) that both lifts the selected text and makes it smaller.
My code is just below. I encounter two problems :
1) Even though the debugger tells me that the font's size has been reduced
successfully (it is known that NSFontManager lets the font size stay the same
if it is too small to be reduced), what I see in the text view is
characters exactly
the same size (although they are lifted correctly).
2) I tried it the string "1234567", selecting the substring "456". After
the operation
has been completed, I am unable to select any substring of "1234567"
except those
starting with "1" and not going further than "3". If I try selecting the
"7", the text view
selects the "1".
What did I do to make the text view go frantic like this ???
Thanks in advance for any help.
Ewan
-(IBAction) exponent: (id) sender
{
NSRange r=[self selectedRange];
NSAttributedString* s0=[self attributedSubstringFromRange: r];
NSRange fullRange=NSMakeRange(0,[s0 length]);
NSMutableAttributedString* s=[[NSMutableAttributedString alloc]
initWithAttributedString:s0];
[s addAttribute:NSSuperscriptAttributeName value:[NSNumber
numberWithInt:1] range:fullRange ];
NSDictionary* dict=[s0 attributesAtIndex:0 effectiveRange:NULL];
NSFont* oldFont=[dict objectForKey:NSFontAttributeName];
float oldSize=[oldFont pointSize];
float newSize=oldSize/2;
NSFont* newFont=[[NSFontManager sharedFontManager] convertFont: oldFont
toSize:newSize];
[s addAttribute:NSFontNameAttribute value:newFont range:fullRange];
[self insertText:s];
[s release];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden