• 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: "Gerriet M. Denkmann" <email@hidden>
  • Date: Fri, 4 Dec 2009 15:41:01 +0700

On 4 Dec 2009, at 14:44, email@hidden wrote:

> Is there some reason you can't use -[NSFontManager convertFont:toHaveTrait:] ?
No reason at all, except my ignorance of this method.


> 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

This works perfectly. Thank you very much!


Kind regards,

Gerriet.

>
> 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?

_______________________________________________

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

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

  • Prev by Date: Re: A hillegass challenge
  • Next by Date: Re: [iphone] Libxml2 with a wrapper to NSArray
  • Previous by thread: Re: How to get an italic font
  • Next by thread: A hillegass challenge
  • Index(es):
    • Date
    • Thread