Re: NSTextView - changing font size
Re: NSTextView - changing font size
- Subject: Re: NSTextView - changing font size
- From: Brian Webster <email@hidden>
- Date: Wed, 10 Jul 2002 15:38:04 -0500
There may be a simpler way to do this, but this should work,
assuming that all the right sizes/styles of your fonts are
installed on the system, of course.
-(void)sizeText
{
NSTextStorage *textStorage = [textView textStorage];
NSRange range, nextRange;
NSFont *oldFont, *newFont;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
range = NSZeroRange;
while(NSMaxRange(range) < [textStorage length])
{
NSDictionary *attributes = [textStorage
attributesAtIndex:NSMaxRange(range) effectiveRange:&range];
oldFont = [attributes objectForKey:NSFontAttributeName];
newFont = [fontManager convertFont:newFont toSize:sizeOption];
[textStorage addAttribute:NSFontAttributeName
value:newFont range:range];
}
}
I typed this code in Mail, so it's probably not quite right, but
I think it gets the idea across. You basically have to set the
font on a per-style run basis, so that each range of characters
will have the same traits as before, but a different size. Oh,
and sending beginEditing and endEditing to the text storage
before and after the loop may give you a performance increase,
since it will only do all its recalculations once that way.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
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.