简体   繁体   中英

What does font size really mean in ios?

Seems font size doesn't determine anything.

Here is two line, one use font zapfino , another use system font . They both has size 30, but the line height or other font metrics is really different. 这是照片

This pic is draw with YYLabel which use coretext layout and draw the text, use this framework we can easily see the border of one glyph.

Below is another pic which use two UILabel with different font and preview it in StroyBoard . 在此输入图像描述

So what does font size mean in coretext when layout one line?

From the Wiki page for point (typography) :

When a point size of a font is specified, the font is scaled so that its em square has a side length of that particular length in points. Although the letters of a font usually fit within the font's em square, there is not necessarily any size relationship between the two, so the point size does not necessarily correspond to any measurement of the size of the letters[.]

So in all digital fonts, the font-size doesn't really correlate with anything except an imaginary square the font designer chose to design their glyphs on top of. So sometimes this will correlate with the width of the capital M, but not always. And Zapfino , the font you mentioned, is one of the more audacious examples of totally overshooting its boundary boxes. Here it is next to Helvetica, at the same point size:

在此输入图像描述

Although they have a similar X-height, Zapfino's cap-height, ascenders, and descenders are so large that each letter's cell height in most rendering engines, including CoreText, will be more than twice that of Helvetica. It's simply how the font was designed. You'll either need to manually fit your font-size depending on which typeface you use, or try a programmatic approach like this one .

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM