Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the CoreText equivalent to AppKit's NSObliquenessAttributeName?

I'm drawing some text in Mac/iOS cross-platform code using CoreText. I may be using fonts that do not have a real "Italic" version installed in the OS for all users, but they need to be aware that the text is italic even then.

With AppKit's NSAttributedString -drawAtPoint:, I can use NSObliquenessAttributeName to make the text slanted (and thus look italic -- well, oblique). CoreText doesn't seem to have an equivalent for this attribute. At least I found none in CTStringAttributes.h (not that there's any documentation even years after CoreText was released).

Does anyone know how I can get oblique text with CoreText on iOS?

like image 936
uliwitness Avatar asked Dec 27 '22 05:12

uliwitness


1 Answers

I’d try using the affine transform argument to CTFontCreateWithName() with a shear matrix. For instance

CGAffineTransform matrix = { 1, 0, 0.5, 1, 0, 0 };
CTFontRef myFont = CTFontCreateWithName(CFSTR("Helvetica"), 48, &matrix);

That will create quite an extreme skew (assuming I got it right), but you get the idea.

Update:

In fact, the documentation appears to imply that this is the right way to do things.

like image 176
al45tair Avatar answered Apr 26 '23 04:04

al45tair