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

Re: Getting font info


  • Subject: Re: Getting font info
  • From: Aki Inoue <email@hidden>
  • Date: Fri, 31 May 2002 13:26:22 -0700

Doug already answered the "getting NSAttributedString from NSTextView" part.

This is an additional info.

You can check the "boldness" or any other font traits using NSFontManager.

([[NSFontManager sharedFontManager] traitsOfFont:yourFontObject] & NSBoldFontMask)

Aki

On 2002.5.31, at 12:43 午後, Peter Schols wrote:

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.
_______________________________________________
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.

References: 
 >Getting font info (From: Peter Schols <email@hidden>)

  • Prev by Date: Is there a Cocoa or Unix way to find all applications?
  • Next by Date: Objective C array
  • Previous by thread: Re: Getting font info
  • Next by thread: Re: Getting font info
  • Index(es):
    • Date
    • Thread