Re: Simple way to find out baseline for NSAttributedString?
Re: Simple way to find out baseline for NSAttributedString?
- Subject: Re: Simple way to find out baseline for NSAttributedString?
- From: email@hidden
- Date: Thu, 4 Sep 2003 13:09:43 -0700
Thanks! Especially for the ASCII graphics -- that's always a
nontrivial task.
It seems to work -- When I calculate the "size" of the string, it seems
to be using the generic font heights, rather than the actual sizes of
the characters. So "mom" and "mommy" both render with the same height
box, even though the descender isn't there in "mom."
Code snippet, for posterity:
int length = [text length]; // text is an NSAttributedString
NSRange range = NSMakeRange(0,0);
float maxDescender = 0.0; // will be a negative number!
while(NSMaxRange(range) < length) // Loop through styles of string
{
NSDictionary *attributes = [text attributesAtIndex:NSMaxRange(range)
effectiveRange:&range];
NSFont *font = [attributes objectForKey:NSFontAttributeName];
if (nil != font)
{
float thisDescender = [font descender];
if (thisDescender < maxDescender)
{
maxDescender = thisDescender; // Save the largest descender
}
}
}
NSSize size = [text size];
NSLog(@"Size: Width %f, Height %f, Max Descender %f", size.width,
size.height, maxDescender);
As you said, Superscript/Subscript is another matter. But this ought
to be a good start.
Dan
--
Dan Wood
Karelia Software, LLC
email@hidden
http://www.karelia.com/
Watson for Mac OS X:
http://www.karelia.com/watson/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.