CTFontManagerIsSupportedFontFile

I am making an app where users will be able to add their own fonts.

I am trying to use Core Text CTFontManagerIsSupportedFontFile to check the validity of a font file prior to install it, to avoid messing up the system.

Problem is, it crashes. I am applying the very same approach as I do for CTFontManagerRegisterFontsForURL which works perfectly and pass the same URL, so I was expecting it to work fairly easily.

[code] const kCTFontManagerScopeNone = 0
const kCTFontManagerScopeProcess = 1
const kCTFontManagerScopeUser = 2
const kCTFontManagerScopeSession = 3
dim f as FolderItem = specialfolder.GetResource(“Calebasse.ttf”)

if f <> nil then

declare function CFURLCreateWithString lib "CoreFoundation" ( allocator as Ptr, URLString as CFStringRef, BaseURL as Ptr ) as Ptr

dim cfstr as CFStringRef = f.URLPath

Dim CFUrlRef as Ptr = CFURLCreateWithString( nil, cfstr,nil )

declare function CTFontManagerIsSupportedFontFile lib "CoreText" (fontURL as Ptr ) as boolean

if CTFontManagerIsSupportedFontFile( CFURLRef) then
  msgbox "OK"
  else
  msgbox "Yuk"
end if
[/code]

Here is what I get in the simulator console :

Jan 24 22:36:19 Mitchs-iMac com.apple.CoreSimulator.SimDevice.0B3D6660-CD33-44C2-B62D-212CCB95EAB4.launchd_sim[2751] (UIKitApplication:com.matchsoftware.fontname[0xc2fa][3166]): Service exited due to signal: Trace/BPT trap: 5 Jan 24 22:36:19 Mitchs-iMac.local SpringBoard[2763]: Application 'UIKitApplication:com.matchsoftware.fontname[0xc2fa]' crashed. Jan 24 22:36:19 Mitchs-iMac assertiond[2767]: assertion failed: 14B25 12B411: assertiond + 13690 [F3233EFE-D6AB-32E3-BB3E-2CC6D0333C88]: 0x1 Jan 24 22:36:19 Mitchs-iMac.local assertiond[2767]: notify_suspend_pid() failed with error 7 Jan 24 22:36:19 Mitchs-iMac assertiond[2767]: assertion failed: 14B25 12B411: assertiond + 13690 [F3233EFE-D6AB-32E3-BB3E-2CC6D0333C88]: 0x1

There is a mystery, though. In the iOS and Mac developer library, it shows now :

[quote]Validating Font Files
1 Objective-C symbol hidden[/quote]

When a few months back, it said :

[quote]CTFontManagerIsSupportedFontFile
Determines whether the referenced font data (usually by file URL) is supported on the current platform.[/quote]

[quote]bool CTFontManagerIsSupportedFont(CFURLRef fontURL);
Parameters
fontURL
A URL referring to font data.[/quote]

[quote]Return Value
Returns true if the URL refers to a valid font that can be used on the current platform; false otherwise.[/quote]

So has Apple simply removed that function altogether, or is there something I do not see ?

I know this is fairly specialized stuff, but any help will be appreciated.

[quote=161999:@Michel Bujardet] declare function CTFontManagerIsSupportedFontFile lib “CoreText” (fontURL as Ptr ) as boolean
[/quote]
The function is called CTFontManagerIsSupportedFont, not CTFontManagerIsSupportedFontFile. Spot the difference…

On the older Mac Developer Library it was CTFontManagerIsSupportedFontFile, but indeed the documentation I copied from another source is CTFontManagerIsSupportedFont. At any rate, it crashes just the same :frowning:

The error message in the simulator console is the same :
Service exited due to signal: Trace/BPT trap: 5

I tried to google it to no avail.

Starting to wonder if the function is still there. If I use a pure fantasy function name, I get the same error. Maybe Apple has simply removed it.

It is there. Apple docs are very reliable.

No it is not there anymore. All what I posted used to be there until recently, now all is there is

[quote]Validating Font Files
1 Objective-C symbol hidden[/quote]

https://developer.apple.com/library/ios/documentation/Carbon/Reference/CoreText_FontManager_Ref/

No mention of deprecation, no explanation, but the details about the method are gone.

I still see all of the info:

[code]??CTFontManagerIsSupportedFontFile???
Determines whether the referenced font data (usually by file URL) is supported on the current platform. ??

Declaration?
OBJECTIVE-C?
bool CTFontManagerIsSupportedFont( CFURLRef fontURL );

???Parameters
• fontURL | A URL referring to font data. ??

Return Value?

Returns true if the URL refers to a valid font that can be used on the current platform; false otherwise. ?[/code]
I think the issue is that you have objective-c stuff hidden since you clicked on the language as Swift only. If you click on “both”, it will appear again with all of the information.

[quote=162027:@Jason King]I still see all of the info:

[code]??CTFontManagerIsSupportedFontFile???
Determines whether the referenced font data (usually by file URL) is supported on the current platform. ??

Declaration?
OBJECTIVE-C?
bool CTFontManagerIsSupportedFont( CFURLRef fontURL );

???Parameters
• fontURL | A URL referring to font data. ??

Return Value?

Returns true if the URL refers to a valid font that can be used on the current platform; false otherwise. ?[/code]
I think the issue is that you have objective-c stuff hidden since you clicked on the language as Swift only. If you click on “both”, it will appear again with all of the information.[/quote]

Right you are, Jason. My bad. Now I see it.

… But it still crashes :frowning:

The strangest part is, the very same code on OSX with lib Cocoa works perfectly. CTFontManagerRegisterFontsForURL works the same on both platforms, fortunately. Guess I will have to rely on its error message. I just hope some old or ill formed font files will not crash the app.

It is not the first time I bump into iOS odd behavior as compared to what the reference says. CTFontManagerRegisterFontsForURL with scope kCTFontManagerScopeUser which should make the font available for subsequent sessions does not work in iOS as described, but is honored in Mac OS X.