4

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. Here is the pic

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. enter image description here

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

Karl
  • 665
  • 4
  • 19
  • What sort of UI control is that? Looks to me like it's performing some sort of auto-fill behaviour which would obviously negate the font size... – Droppy Jun 14 '16 at 06:54
  • [YYLabel](https://github.com/ibireme/YYText) @Droppy, but when we try this with a `UILabel`, it's behave the same. – Karl Jun 14 '16 at 08:07
  • OK... so as to the rest of my question... what attributes are you setting that would cause it to auto-fill height or whatever? – Droppy Jun 14 '16 at 08:09
  • I have edit the question and attach a pic use two `UILabel` to illustrate the difference,@Droppy – Karl Jun 14 '16 at 08:26
  • Yeah you're still avoiding the issue however. That label has some functionality relating to auto-sizing and until you reveal what attributes you are using, no-one can answer your question. `UILabel` also has auto-sizing behaviour. – Droppy Jun 14 '16 at 08:28
  • What do you mean auto-sizing, it's just a `instrinsicContentSize` of the label?@Droppy – Karl Jun 14 '16 at 09:56

1 Answers1

1

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:

enter image description here

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!

Community
  • 1
  • 1
ian m
  • 504
  • 3
  • 7
  • So when layout a line, a render engine will use the letter's cell height? What 's this cell height mean in the font? – Karl Jun 23 '16 at 06:26
  • What tool do you use to compare the two font? – Karl Jun 23 '16 at 06:28
  • Most render engines (including all browsers I'm aware of) calculate the glpyh's cell height as the distance from the descender line to the ascender line (the lowercase "f" in my Zapfino example extends the length of it). – ian m Jun 24 '16 at 19:53
  • And I used Photoshop to create my example. – ian m Jun 24 '16 at 19:54