11

I'm trying out FTGLES to dynamically display text in arbitrary fonts on OpenGL-ES on iOS (cf. my SO question here). That library seems to require direct access to the TTF file to use the font. Using kosher methods, can one directly access -- by path -- the system font files on iOS? I've RTFM'd and couldn't find anything.

Barring that, does anyone know if it is Apple-approved to copy the system fonts into your app (before submission).

Community
  • 1
  • 1
Clay Bridges
  • 11,602
  • 10
  • 68
  • 118
  • Accessing anything outside of your app sandbox, except by official API:s, is grounds for rejection. So no matter whether it's actually possible, I would recommend against it. – Jakob Borg Sep 11 '10 at 22:05
  • Yeah, I was looking for something within bounds. I edited the post to make it clearer. – Clay Bridges Sep 12 '10 at 00:11

3 Answers3

12

My solution was inspired by skia.

Though cannot access system built-in font files directly, we still have an indirect way:

Create a CGFont with your wanted font name, all contents of SFNT table of this CGFont can be accessed by simply calling CGFontCopyTableTags() and CGFontCopyTableForTag().

A ttf/otf font data can then be constructed by using these tables, save the new created font to disk, you can use it in FTGL ES later.

EXphinx
  • 136
  • 2
  • 3
  • 3
    https://gist.github.com/1892760. haven't been fully tested with all built-in fonts, but it works well in all my cases. – EXphinx Feb 23 '12 at 13:34
  • Your code works beautifully, even after all these years, on both macOS and iOS. To others, use `CFStringCreateWithCString` with the [font name](https://github.com/lionhylra/iOS-UIFont-Names) then `CGFontCreateWithFontName` to create the font in memory. – electromaggot Apr 07 '23 at 21:55
8

No, you can't access the system installed TTF files on iOS devices. So you'll have to embed the typefaces you'd like to use.

Disclaimer: I'm not a lawyer, and the acceptability of using Apple supplied system fonts in an iOS app is a legal question about interpreting software licenses, so you may want to seek professional advice.

You wish to embed an Apple supplied font in your app. The definition of "embed" is a bit nebulous, so adding the font to an iOS app may or may not fit within the copyright holder's definition of "embed". Some type houses define "embed" to mean just viewing predetermined content in the included font; other mean viewing and editing content in that font. Displaying content that changes during the running of your app is somewhere between these two cases.

According to the Mac OS X Lion 10.7.2 ELUA:

F. Fonts. Subject to the terms and conditions of this License, you may use the fonts included with the Apple Software to display and print content while running the Apple Software; however, you may only embed fonts in content if that is permitted by the embedding restrictions accompanying the font in question. These embedding restrictions can be found in the Font Book/Preview/Show Font Info panel.

If using the fonts in an iOS app is indeed "embedding", you just need to check the particular fonts you wish to use in Font Book.

In this situation I would find a font or set of fonts where I had explicit permission to include the fonts in the iOS app. I would start by shopping around the various type houses for a licensing scheme that explicitly allowed this use. This may get expensive, so another tack would be to seek out open source typefaces with a license that would allow this use. Or, for a very limited set of characters (e.g. only numbers) I would even consider drawing my own typeface.

Mr. Berna
  • 10,525
  • 1
  • 39
  • 42
  • Thanks for the good answer. It is a shame though... I guess the security benefits of sandboxing outweigh the benefits of giving apps unrestricted access to system resources that could prevent your app being several K or MB bigger. – jheriko Jan 05 '12 at 17:49
0

No. Your app cannot access files outside the sandbox of your app. Period (well, unless it's jailbroken ;). But you can indeed bundle the font file. Now, I see no reason why Apple would reject your app, as it's using a file already available on the device, and you're just including your local file to it. In terms of copyright, Apple already has that permission to use it on their device, so your inclusion of it should be no problem.

I say should because I haven't needed this capability and haven't tested it with a submission of my own, but based on legal instinct and font copyright issues I've seen in the past, I'd expect that it wouldn't be a problem.

Dylan Gattey
  • 1,713
  • 13
  • 34