Re: Problem with fonts/traits in attributed strings
Re: Problem with fonts/traits in attributed strings
- Subject: Re: Problem with fonts/traits in attributed strings
- From: Brian Webster <email@hidden>
- Date: Tue, 25 Sep 2001 23:08:20 -0500
On Tuesday, September 25, 2001, at 06:44 PM, Greg Titus wrote:
//get font name, size, range, etc. from data
[attString applyFontTraits:fontTraitMask range:range];
font = [NSFont fontNamed:fontName size:fontSize;
[attString addAttribute:NSFontAttributeName value:font range:range];
When I ran this, the font would be set correctly, but none of
the font traits (bold, italic, etc.) would show up. If I take
out the line that sets the NSFontAttributeName, then the
traits show up correctly, but the font is set to the default.
This behavior is what I would expect. Setting the font
attribute directly is sort of a lower level than applying font
traits because an NSFont object is a particular combination of
family and traits, not the family itself. For instance,
"Helvetica-Bold" is a different font than "Helvetica", so if
your fontName in the above code is "Helvetica", it will undo
any traits in the range.
So something you might try is simply reversing the order here.
Set the font, then apply the traits.
I see. I tried the reverse order, but it didn't help any. But
it's good to know this fact for the future.
Next, I tried removing the applyFontTraits:range: message and
changing the font assignment to:
font = [[NSFontManager sharedFontManager]
fontWithFamily:fontName traits:fontTraitMask weight:5
size:fontSize];
This, on the other hand, I would have expected to work. Are you
certain that your fontTraitMask is correct? If so, are you
certain that you have a font on your system which matches that
family name and traits (you can't italicize Arial Black, for
instance, since there's no italic or oblique version of the
font - at least not built in)?
It looks like this turned out to be the problem. There's no
bold or italic variation of Geneva installed. What got me is
that Script Editor can display bold Geneva text, so I thought it
was installed. Is there any sort of equivalent in Cocoa for
Quickdraw's ability to draw a bold version of a font even if
there isn't an explicitly bold version installed?
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster