1

I can't figure out how to include a font in my Mac screensaver. I did this following tutorial, Embed font in a mac bundle, but my [NSFont fontWithName:size:] still returns null. I don't really know where to start. Any thoughts, solutions? Thank you

Community
  • 1
  • 1
  • What does "doesn't work" mean? Any progress at all? The answer you linked is correct. – jtbandes Apr 13 '12 at 13:24
  • Are you sure you followed that answer correctly? I followed it and it works. Have you checked that your font gets copied into the Resources/Fonts directory during build? – trojanfoe Apr 13 '12 at 15:04
  • The font file is copied in: nameofthescreensaver.saver/contents/resources/fonts/nameofthefont.otf. In my workspace, it is in: nameoftheproject/nameofthefont.otf. Here is what I did so far: Go the Target > Build Phases > Add build phase > Add copy file. In copy files: Destination = Resources, Subpath = Fonts, and I add my font file. Uncheck copy only when installing. I also have in my info.plist: Key = Application fonts resource path (or ATSApplicationFontsPath), Value = Fonts – user1331656 Apr 13 '12 at 22:16

1 Answers1

2

The example you're following works for an application. The problem is that you're building a screensaver bundle. Those are not applications unto themselves, they are loaded by separate application. Apparently, the ATSApplicationFontsPath key, as its name implies, is only used when loading an application.

You will have to write code to enumerate the font file URLs in your bundle and register them. You can use -[NSBundle URLsForResourcesWithExtension:subdirectory:] and CTFontManagerRegisterFontsForURLs() for that.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154