Custom Font not found

I am having trouble with a custom font:

  1. I have edited the info.plist file and included it and the font itself in project. (They build correctly into the project).
  2. I have these lines in the App.Open event:
    Dim classPtr as Ptr = NSClassFromString (“UIFont”)

#if Target64Bit
Dim fontsize as Double
Declare function fontWithName lib “Foundation” selector “fontWithName:size:” (id as ptr, Fontname as CFStringRef, Size as double) as Ptr
#elseif Target32Bit
Dim fontsize as single
Declare function fontWithName lib “Foundation” selector “fontWithName:size:” (id as ptr, Fontname as CFStringRef, Size as single) as Ptr

Dim fontfile as xojo.IO.FolderItem = SpecialFolder.GetResource(“HamburgSymbols.ttf”)
Dim myfontname as ptr
fontsize = 20

If fontfile <> Nil And fontfile.Exists Then

myfontname = fontWithName(classPtr, “HamburgSymbols”, fontsize)

if myfontname = nil then
MsgBox(“Cannot find ‘HamburgSymbols’.”)
end if
MsgBox(“Cannot find font with that name.”)
End If

  1. every time, the font file is found (fontfile is not Nil and fontfile Exists) but then assigning myfontname fails and returns nil. I have also tried hardcoding fontsize rather than using a variable, but no difference.

  2. Finally, assuming someone can see what I am doing wrong and myfontname can become a valid ptr to a font, how do I assign that font to an IOSCanvas as a TextFont?

PS Simply doing Dim myfontname as New IOSfont(“HamburgSymbols”,20) after loading the font via the info.plist did not work (generates an invalid font name error) although I have seen a post where someone apparently just did that - cant imagine how.

Hope someone can help!

Did you add the font name in the plist as an array entry?

FYI you can use CGFLOAT instead of single/double and only write one dclar for both 32 and 64 targets.

Yes, I did list the font name as an array entry and the app does find the font (the variable fontfile is correctly initialised) but thats where it stops. I have tried other fonts, the same problem happens. I have checked the PostScript name carefully with FontBook in all cases.

PS thanks for the tip re CGFLOAT

(PS thanks for your brilliant Calendar plug in which I own and use)

Unless you are trying to change the font one something that doesn’t have a TextFont (iOSFont) property, you should be able to do:

label1.TextFont = new iOSFont("HamburgSymbols", 14)

For changing the font of a Table cell it is much more complicated and you need to use:

Declare Function initFont Lib UIKitLib selector "fontWithName:size:" (obj_id As ptr, name As CFStringRef, size As CGFloat) As ptr Dim fontPtr As ptr = initFont(NSClassFromString("UIFont"), "HaburgSymbols", 16.0)

If it helps this is an extract of my PLIST file

[code]<?xml version="1.0" encoding="UTF-8"?>

UIAppFonts /Fonts/SourceSansPro-Regular.ttf /Fonts/Raleway-SemiBold.ttf /Fonts/Raleway-Regular.ttf /Fonts/SourceSansPro-Semibold.ttf [/code]

The CopyFilesScript places the fonts in the “Fonts” subfolder.

Merci Jeremie, you saved my life there - I had written the key as UIAPPFonts instead of UIAppFonts.
You’re a star!

You’re welcome