• 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
Getting font info
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Getting font info


  • Subject: Getting font info
  • From: Peter Schols <email@hidden>
  • Date: Fri, 31 May 2002 21:43:55 +0200

Hi,

I'm looking for the easiest way to know whether a selected piece of text in an NSTextView is bold or not.

I have tried the following:

Putting the selected text from the textfield in an NSAttributedString:
[as initWithRTF: [textView RTFFromRange:[textView selectedRange]] documentAttributes:NULL];

Getting an NSDictionary from the FontAttributes of the attributed string
dict = [as fontAttributesInRange:NSMakeRange(0,1)];

And finally, reading the font attribute and checking it for the "Bold" string.

This works fine, but there must be an easier way. The only thing I need is a button that toggles the selected text Bold / Regular. Making the selection bold is no problem (using the [fontManager addFontTrait:sender]; method) but in order to be able to get the toggle behaviour, I need to know whether the selection is bold or not.

Help, tips or sample code are very appreciated!

Thanks in advance!

peter
_______________________________________________
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: Getting font info
      • From: Aki Inoue <email@hidden>
    • Re: Getting font info
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Socket data incoming event?
  • Next by Date: Paul Carvill/UK/Elateral is out of the office.
  • Previous by thread: Re: Socket data incoming event?
  • Next by thread: Re: Getting font info
  • Index(es):
    • Date
    • Thread