Re: Questiong on NSString sizeWithAttributes
Re: Questiong on NSString sizeWithAttributes
- Subject: Re: Questiong on NSString sizeWithAttributes
- From: Ed Voas <email@hidden>
- Date: Tue, 08 Nov 2005 14:27:27 -0800
Nope. Pretty straightforward stuff. I distilled it to this and it still
happens:
NSFont* font = [NSFont fontWithName:@"Arial Bold" size:12];
NSDictionary* fontAttrs;
NSColor* fontColor = [NSColor colorWithDeviceRed:0 green:0
blue:0 alpha:1.0];
NSMutableParagraphStyle* lineStyle;
NSString* text = [[NSString alloc] initWithString:@"Allow"];
lineStyle = [[NSMutableParagraphStyle alloc] init];
[lineStyle setLineBreakMode:NSLineBreakByClipping];
fontAttrs =
[[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:
font,
fontColor,
lineStyle,
nil]
forKeys:
[NSArray arrayWithObjects:
NSFontAttributeName,
NSForegroundColorAttributeName,
NSParagraphStyleAttributeName,
nil]] copy];
NSSize extent = [text sizeWithAttributes:fontAttrs];
Even if the font is merely "Arial" it still yields a height of 18, which
seems wrong.
Ken Victor wrote:
are you getting your attributes from an NSAttributedString and if so,
do you have any tab characters in your string, and if so, are the
heights of those tab characters being set to something other than what
you would expect?
just some thoughts...
ken
On 8 nov. 05, at 17:54, Ed Voas wrote:
Hi,
I'm seeing something strange, and maybe I'm doing something wrong. I
have two text objects I'm trying to draw and need to position them
exactly. Both are being drawn in Arial Bold. One is 16pt and the other
is 12.
When I ask for the 16pt height via sizeWithAttributes, I'm told it has
a height of 18. Seems reasonable given the font ascent/descent. But
when I ask for the 12 point type height, I get... 18. This time, it's
not so cool. In theory I should be getting a height of about 13 or 14.
This is causing me to position my text (in this specific case) 4
pixels off from where it should be. The font reports the line height
to be 14 for the 12 point text, btw, which sounds right. Yet
sizeWithAttributes reports 18.
I use the height to build my rectangle for my view. But we specify our
text items via baseline. So when given a value of 20, say, I normally
get the text ascent, subtract that and get the top and then add the
height for the bottom (this is in top-left-speak, even in bottom left
the same ideas apply). If I draw the text with a background color I
get 4 pixels of color where none should (in my mind) appear.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden