Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed font in a mac bundle

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...

NSMutableAttributedString *recOf; recOf = [[NSMutableAttributedString alloc] initWithString:@"In Recognition of"]; length = [recOf length]; [recOf addAttribute:NSFontAttributeName value:[NSFont fontWithName:@"Edwardian Script ITC" size:50] range:NSMakeRange(0, length)]; [[NSColor blackColor] set]; p.x = (bounds.size.width/2)- (([recOf size].width)/2); p.y = (bounds.size.height/1.7); [recOf drawAtPoint:p]; [recOf  release]; 
like image 643
RW. Avatar asked Mar 15 '10 02:03

RW.


People also ask

How do I embed fonts in Excel for Mac?

Open the workbook in which you want to embed the font. On the File tab, click Options. In the Excel Options dialog box, click Save. In the Save Workbook section, select the Embed fonts in file check box.

How do you group fonts on a Mac?

Create a font collection or library from textChoose Apple menu > System Preferences, click Keyboard , then click Shortcuts. In the list on the left, select Services. In the list on the right, click the arrow next to Text, then select the checkbox for Create Collection From Text or Create Font Library From Text.

How do I add fonts to info plist?

To do this, add the key "Fonts provided by application" to Info. plist (the raw key name is UIAppFonts ). Xcode creates an array value for the key; add the name of the font file as an item of the array. Be sure to include the file extension as part of the name.


1 Answers

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.

like image 198
Rob Keniger Avatar answered Sep 28 '22 03:09

Rob Keniger