Embed font in a mac bundle

前端 未结 2 864
执笔经年
执笔经年 2020-11-28 22:39

I have a program I am writing. I want to use a fancy font. Can I just embed my font into my bundle and use it from there.

My code...

NSMutableAtt         


        
相关标签:
2条回答
  • 2020-11-28 23:20

    Some people had success using Carbon magic. You should try it out.

    That being said about the example above, ATSFontActivateFromFileSpecification was deprecated in Leopard. Apparently the replacement uses an FSRef directly, which is even better.

    0 讨论(0)
  • 2020-11-28 23:28

    Yes, you can. You should add a Copy Files build phase to your target (right-click your target, then choose Add > New Build Phase > New Copy Files Build Phase).

    Set the destination of the Copy Files build phase to Resources with a path of Fonts. This will make sure the font is copied into a folder named Fonts in your application bundle.

    Add your font file to the new build phase by dragging the font file onto the build phase.

    You then need to add the ATSApplicationFontsPath key to your Info.plist file, with the name of the folder containing your font as its value:

    <key>ATSApplicationFontsPath</key>
    <string>Fonts</string>
    

    You can then use the font in your app as if it were a built-in system font by calling [NSFont fontWithName:@"yourFontName"].

    Of course, you should make sure that you have permission to distribute the font before doing this.

    0 讨论(0)
提交回复
热议问题