Re: Fonts in TableView
Re: Fonts in TableView
- Subject: Re: Fonts in TableView
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Mon, 07 Nov 2016 17:27:20 +0700
> On 7 Nov 2016, at 16:43, Alastair Houghton <email@hidden> wrote:
>
> On 6 Nov 2016, at 06:18, Quincey Morris <email@hidden> 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@hidden)
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:
This email sent to email@hidden