Symbol fonts in iOS

I am wanting to use symbol glyphs from a variety of TTF fonts , but in an iOS app.
I can get them (more or less…) in desktop, and include them in a PDF using MBS plugins and ‘embed’ instructions.

The iOS examples which come with Xojo have 2 font samples
One lists available fonts
One purports to have a variety of fonts in labels, but so far it only seems to work for me with the very specific couple of fonts in the example.

If I try to use any of the ‘dings’ style fonts, I dont get symbols, it just shows letters as a fallback.
I need to bundle some TTF fonts and make them available to my iOS app.

Does anyone know how to do that?
(SF Symbols might do if I can embed them in a PDF as a vector glyph)

Currently away from my computer, I can share a more detailed explanation later.

The fonts need to be defined in the app’s plist file.
You can then call them with
Var f as new Font("FontName")

Edit:

The plist entries look like this

<key>UIAppFonts</key>
	<array>
		<string>/Fonts/SourceSansPro-Regular.ttf</string>
		<string>/Fonts/Raleway-SemiBold.ttf</string>
		<string>/Fonts/Raleway-Regular.ttf</string>
		<string>/Fonts/SourceSansPro-Semibold.ttf</string>
		<string>/Fonts/Raleway-ExtraBold.ttf</string>
	</array>

The fonts are copied to a Fonts folder with a copy files build step.

2 Likes

Thanks for this @Jeremie_L Jeremie.

I only just saw the reply - I did not get a notification about the editted version.

I confess I don’t know what to do with the variable f after the line
Var f as new Font(“FontName”)

I’m used to g.textfont = ??? syntax
Does f simply mean the app will be aware of Fontname afterwards, or is there some special syntax to make use of f in a graphics or PDF context?

Hi @Jeff_Tullin

Maybe you can find useful this blog post, specially the section titled “Using Fonts Not Installed in the Operating System” when it is about using them on a PDF document / Graphic context.

The fonts are being copied to the app’s folder as per the blog post.
The plist exists as specified.

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
<key>Fonts provided by application</key> 
<array> 
<string>CS4.ttf</string> 
<string>CS5.ttf</string> 
</array> 
</dict> 
</plist>

These lines fail with "invalid argument " (invalid font name)

font1 = new font("CS4",10)
font2 =  new font("CS5",10)

font1 = new font("CS4.ttf",10)
font2 =  new font("CS5.ttf",10)

That key is not right. You need to create the plist in Xcode and enter that text. When you save, the correct one will be created. Keys are typically all one word and start with NS or UI.

In this case, the key should be (as Jérémie stated above):

UIAppFonts

The key is not right?

It came from the Xojo Blog: - does that need correcting?

I’ll see if I can work out how to do it ‘the other way’

@Javier_Menendez — you should update that blog post, the plist is incorrect.

Uops! Yeah, somehow that key (more properly, text) slipped in. Fixed already, sorry for the inconvenience! Anyway, the post is about how to use these user fonts on PDF, if it helps.

Oddly, I don’t see any examples of 'how to use these user fonts on PDF’
other than ‘set a property and your fonts should be embedded’

baby steps … lets get the font showing up.
I have only used DynaPDFMBS so far… maybe in this instance I might benefit from using Xojo’s implementation, but I have a lot of Dyna format code I just want to port, while changing as little as possible.

Font now appears for use in the app.
I can apply it to a label, but not a segmented control for some reason. (No Textfont property)
Baby steps.

Hi @Jeff_Tullin

In order to use them with PDFDocument (once the .plist has been added to the project, and the fonts to the Fonts Resource folder):

Var d As New PDFDocument
d.EmbeddedFonts = True

Var f As FolderItem = SpecialFolder.Resource("Fonts")

If f <> Nil Then
  d.AddFonts(f)
End If

Then, for example (in this case is using the “Honey” font, added to the project using the same technique):

Var g As Graphics = d.graphics
v = New Font("HoneyIStoleYourJumper",35)
g.Font = v
g.DrawText("Apple Farm", 120, 70)
1 Like