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 (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/mlist0987%40gmail.com > > This email sent to mlist0...@gmail.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com