What exactly is UIFont's point size?

mattjgalloway picture mattjgalloway · Aug 2, 2012 · Viewed 22k times · Source

I am struggling to understand exactly what the point size in UIFont means. It's not pixels and it doesn't appear to be the standard definition of point which is that they relate to 1/72th inch.

I worked out the pixel size using -[NSString sizeWithFont:] of fonts at various sizes and got the following:

| Point Size | Pixel Size |
| ---------- | ---------- |
| 10.0       | 13.0       |
| 20.0       | 24.0       |
| 30.0       | 36.0       |
| 40.0       | 47.0       |
| 50.0       | 59.0       |
| 72.0       | 84.0       |
| 99.0       | 115.0      |
| 100.0      | 116.0      |

(I did [@"A" sizeWithFont:[UIFont systemFontOfSize:theSize]])

And looking at the 72.0 point size, that is not 1-inch since this is on a device with a DPI of 163, so 1-inch would be 163.0 pixels, right?

Can anyone explain what a "point" in UIFont terms is then? i.e. is my method above wrong and really if I used something else I'd see something about the font is 163 pixels at 72 point? Or is it purely that a point is defined from something else?

Answer

hooleyhoop picture hooleyhoop · Aug 2, 2012

A font has an internal coordinate system, think of it as a unit square, within which a glyph's vector coordinates are specified at whatever arbitrary size accommodates all the glyphs in the font +- any amount of margin the font designer chooses.

At 72.0 points the font's unit square is one inch. Glyph x of font y has an arbitrary size in relation to this inch square. Thus a font designer can make a font that appears large or small in relation to other fonts. This is part of the font's 'character'.

So, drawing an 'A' at 72 points tells you that it will be twice as high as an 'A' drawn at 36 points in the same font - and absolutely nothing else about what the actual bitmap size will be.

ie For a given font the only way to determine the relationship between point size and pixels is to measure it.