exists-forall
exists-forall

Reputation: 4258

How to create custom font at runtime using NSFont

I'm writing a Mac application that needs to be able to create, load, and use custom fonts at runtime using Cocoa. I've researched the NSFont class thoroughly, and all I can find is API's to load existing fonts and change simple parameters (E.G. size, weight, spacing, etc.).

I need to be able to create custom glyphs from scratch while my program is running, preferably using NSBezierPath, combine them into an NSFont object or something similar, and draw text to the screen using this font.

Is this possible? I'd imagine that font-creation applications must use this. If it is possible, how is it done?

Upvotes: 2

Views: 967

Answers (1)

Rob Keniger
Rob Keniger

Reputation: 46020

There is no API in Mac OS X that will allow you to directly build a font using drawing commands.

Unfortunately, you will have to do this from scratch, building a TrueType or Postscript font file by writing the font data out into the appropriate file format and then loading the font from that file using NSFont or one of the other font APIs.

You might get some hints by looking at the FontForge source, although it's not a Cocoa app so may be only of limited usefulness.

Upvotes: 1

Related Questions