Re: How to get an italic font
Re: How to get an italic font
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