我正在编写一个 Mac 应用程序,它需要能够在运行时使用 Cocoa 创建、加载和使用自定义字体。我已经NSFont
彻底研究了这个类,我能找到的只是加载现有字体和更改简单参数(EG 大小、重量、间距等)的 API。
我需要能够在我的程序运行时从头开始创建自定义字形,最好使用NSBezierPath
,将它们组合成一个NSFont
对象或类似的东西,并使用这种字体将文本绘制到屏幕上。
这可能吗?我想字体创建应用程序必须使用它。如果可能,它是如何完成的?
我正在编写一个 Mac 应用程序,它需要能够在运行时使用 Cocoa 创建、加载和使用自定义字体。我已经NSFont
彻底研究了这个类,我能找到的只是加载现有字体和更改简单参数(EG 大小、重量、间距等)的 API。
我需要能够在我的程序运行时从头开始创建自定义字形,最好使用NSBezierPath
,将它们组合成一个NSFont
对象或类似的东西,并使用这种字体将文本绘制到屏幕上。
这可能吗?我想字体创建应用程序必须使用它。如果可能,它是如何完成的?
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.