> On 7 Nov 2016, at 16:43, Alastair Houghton <[email protected]>
> wrote:
>
> On 6 Nov 2016, at 06:18, Quincey Morris <[email protected]>
> wrote:
>
>> There is probably no perfect strategy that works for every font. However,
>> for the kinds of design decisions that Apple made when it started doing
>> typography properly (in the early 1990s, the days of the Font Wars between
>> Apple and Microsoft), I recommend you use the following calculation to
>> compute the line height of text:
>>
>> line height = font ascender - font descender + font leading
>>
>> using the 3 values reported by the NSFont. […] Depending on your goals, you
>> might also add some margin above and below the line height (1 or 2 points
>> top and bottom) to prevent your rows from looking cramped.
>
> You might also consider using NSLayoutManager’s -defaultLineHeightForFont:
> method, which does pretty much the above calculation - you can see exactly
> what it does in the following Stack Overflow post.
>
> http://stackoverflow.com/questions/5511830/how-does-line-spacing-work-in-core-text-and-why-is-it-different-from-nslayoutm/5635981#5635981
The only way which works for all fonts without clipping seems to be:
+ (CGFloat)tableRowHeight // for OutlineViews and TableViews
{
if ( fontHeight == 0 )
{
NSTextField *dummyTextField = [ [NSTextField alloc]
initWithFrame: NSMakeRect(0,0,99,99) ];
dummyTextField.font = <the font to be used>
NSSize intrinsicContentSize =
dummyTextField.intrinsicContentSize;
fontHeight = intrinsicContentSize.height;
};
return fontHeight;
}
But this seems rather heavy handed.
I keep thinking that there must be a better way.
Also: the rowHeight looks sometimes a bit high - but still better than having
clipped text lines.
Kind regards,
Gerriet.
_______________________________________________
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]