• 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: How to get an italic font
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get an italic font


  • Subject: Re: How to get an italic font
  • From: "email@hidden" <email@hidden>
  • Date: Thu, 3 Dec 2009 23:44:08 -0800

Is there some reason you can't use -[NSFontManager convertFont:toHaveTrait:] ?

It "returns a font whose traits are the same as those of the given font, except that the traits are changed to include the single specified trait."


So something like:

NSFont* myFont = [your code here];
NSFont* myItalicFont = [[NSFontManager sharedFontManager] convertFont:myFont toHaveTrait:NSItalicFontMask];


_murat


On Dec 3, 2009, at 11:15 PM, Gerriet M. Denkmann wrote:

> I want an italic font corresponding to an existing font.
>
> I tried:
>
> 	NSFontDescriptor *fd1 = [ NSFontDescriptor fontDescriptorWithName: @"Times" size: textFontSize ];
> 	NSLog(@"%s text NSFontDescriptor %@",__FUNCTION__, fd1);
> 	//	   NSFontNameAttribute = Times;  NSFontSizeAttribute = 16;
>
> 	fontText = [ NSFont fontWithDescriptor: fd1 size: textFontSize ];
> 	NSLog(@"%s text NSFont %@",__FUNCTION__, fontText);
> 	//	"Times-Roman 16.00 pt. P [] (0x1190e0f90) fobj=0x1190e0590, spc=4.00"
>
> So far so good.
>
> Now I try to make the italic variant:
> 	NSFontSymbolicTraits symbolicTraits = NSFontItalicTrait;
> 	NSFontDescriptor *fdi = [ fd1 fontDescriptorWithSymbolicTraits: symbolicTraits ];
> 	NSLog(@"%s italic NSFontDescriptor %@",__FUNCTION__, fdi);
> 	//	   NSCTFontTraitsAttribute = { NSCTFontSymbolicTrait = 1; }; NSFontSizeAttribute = 16;
> Note: NSFontNameAttribute has disappeared
> The  documentation says: "Returns a new font descriptor that is the same as the receiver but with the specified symbolic traits taking precedence over the existing ones."
>
> 	italicText = [ NSFont fontWithDescriptor: fdi size: textFontSize ];
> 	NSLog(@"%s italic NSFont %@",__FUNCTION__, italicText);
> 	//	"LucidaGrande 16.00 pt. P [] (0x1190e0f90) fobj=0x10046adb0, spc=5.06"
>
> This is comple nonsense: Lucida Grande is not italic and does not have an italic variant (only normal and bold).
>
> I would have expected something like Times-Italic.
>
> So: how to get an italic variant to a given font without hardcoding font names?
>
>
> Kind regards,
>
> Gerriet.
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please 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

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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

  • Follow-Ups:
    • Re: How to get an italic font
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >How to get an italic font (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: A hillegass challenge
  • Next by Date: Re: A hillegass challenge
  • Previous by thread: How to get an italic font
  • Next by thread: Re: How to get an italic font
  • Index(es):
    • Date
    • Thread