• 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: Simple way to find out baseline for NSAttributedString?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Simple way to find out baseline for NSAttributedString? (From: "Alastair J.Houghton" <email@hidden>)

  • Prev by Date: Re: Simple way to find out baseline for NSAttributedString?
  • Next by Date: Re: Hiding an NSControl
  • Previous by thread: Re: Simple way to find out baseline for NSAttributedString?
  • Next by thread: [ANN] SM2DGraphView updated to v1.1
  • Index(es):
    • Date
    • Thread