How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

前端 未结 3 1874
暗喜
暗喜 2020-12-07 12:02

I\'m trying to draw text using Core Text functions, with a line spacing that\'s as close as possible to what it would be if I used NSTextView.

Take this font as an e

3条回答
  •  感动是毒
    2020-12-07 12:35

    Have you looked to see what the sign of the value returned by CTFontGetDescent() is? A common mistake is to assume that descent values are positive, when in fact they tend to be negative (to reflect the fact that they are a descent below the font baseline).

    As a result, line spacing should probably be set to

    ascent - descent + leading
    

提交回复
热议问题