macosfontscore-graphicsquartz-graphicsfont-size

Font sizes in Core Graphics


I'm trying to render a bit of text using Core Graphics APIs and I'm running into some conceptual difficulties.

I'm trying to specify font size using CGContextSetFontSize. The size parameter is in something called "text space units". What is that? How does it map to "em" units?

Thanks


Solution

  • I'm trying to specify font size using CGContextSetFontSize. The size parameter is in something called "text space units". What is that? How does it map to "em" units?

    To answer your second question first, 1 em (following the CSS definition) will equal the amount you specify there.

    Core Graphics' “text space” is derived from user space. There's an additional transformation matrix, the text matrix, which transforms user space into text space. See CGContextSetTextMatrix, How Quartz 2D Draws Text, and Drawing Text.

    By default, the text matrix is the identity matrix, so text space = user space.