Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 903
EightyEight Avatar asked Dec 03 '25 22:12

EightyEight


1 Answers

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.

like image 64
Peter Hosey Avatar answered Dec 05 '25 12:12

Peter Hosey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!