• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSTextView - changing font size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: NSTextView - changing font size
      • From: Jeremy Dronfield <email@hidden>
  • Prev by Date: Re: [Q] NSSplitView
  • Next by Date: Subclassing NSButton, and IB palettes
  • Previous by thread: NSTextView - changing font size
  • Next by thread: Re: NSTextView - changing font size
  • Index(es):
    • Date
    • Thread