The default line height used by the Cocoa Text System is based on various 
layout time configurations.  So, the differences you're seeing is coming from 
the differences in layout context.

The settings are all encapsulated in NSLayoutManager; hence, the method 
-[NSLayoutManager defaultLineHeightForFont:] gives you the information used by 
the layout context.

Aki

On 2011/03/28, at 12:06, Quincey Morris wrote:

> On Mar 28, 2011, at 09:45, Thomas Clément wrote:
> 
>>> NSFont *font = [NSFont fontWithName:@"Menlo" size:11.0];
>>> [@"Hello World" sizeWithAttributes:[NSDictionary 
>>> dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]];
>> 
>> This returns a height of 17.0. However when using this font (Menlo 11.0) in 
>> TextEdit (plain text document), I'm seeing a line height of 13.0.
>> 
>> Monaco 10.0 returns a height of 14.0 which is also what I'm seeing in 
>> TextEdit.
>> Helvetica 12.0 returns a height of 15.0 but I'm seeing 14.0 in TextEdit.
>> 
>> Why these differences?
> 
> 'sizeWithAttributes:' returns the bounding box, in points, of the glyphs 
> representing the characters in the string you passed.
> 
>> How do I get programmatically the value I'm seeing in TextEdit?
> 
> There's no absolute typographic standard for the inter-baseline distance, but 
> it's almost always derived from font metrics, not from glyph bounding boxes. 
> Here are some of the possibilities:
> 
> -- The font size multiplied by a standard factor, like 120%. This is (or used 
> to be, at least) what apps like Adobe Illustrator used to use, because it 
> doesn't depend on the specific font metrics, and therefore the line spacing 
> of a line doesn't depend on what fonts are on it, only on their sizes.
> 
> -- The font's ascender + descender + "leading". These are metrics built into 
> the font itself, independent of the actual glyph bounds. This is probably 
> what TextEdit is using. (What Apple calls "leading" is really called "extra 
> leading" in the typographic world. Typographically, leading *is* the 
> inter-baseline distance: the whole thing.) IIRC, changing fonts in TextEdit 
> can affect the inter-baseline distance on a line-by-line basis.
> 
> -- The glyph bounding box, either of the particular line, or of all the 
> characters in the font. You'd only use this if you can't tolerate glyph 
> images overlapping, ever.
> 
> -- Any weird calculation that someone thought was a good idea at the time.
> 
> There's no right answer, unfortunately.
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/aki%40apple.com
> 
> This email sent to [email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to