Prevent prompt to download font referenced in WebView in macOS application

445 views Asked by At

In a Cocoa app, I have a WebView view object that can display content that it outside my direct control. I've noticed that on pages referencing some unusual fonts (either for use on the page or just as part of a tracking package that tests for the presence of fonts on the system), macOS Sierra (10.12) now prompts to download missing fonts (sample image below).

Is there a way to intercept these missing fonts, and either prevent the download prompt or provide an alternate font? I've looked through the Apple documentation on font management and font APIs (like NSFontManager) and have not seen a lot of information about these new download prompts.

Update: I believe that this has to do with the automatic activation functionality in CoreText, based on the WebKit source and strategically replacing some CTFontCreate functions.

For example, the following will result in a "download" dialog:

let _ = CTFontCreateWithName("Osaka" as CFString, 12.0, nil)

But adding an option to prevent auto activation avoids the "download" dialog:

let _ = CTFontCreateWithNameAndOptions("Osaka" as CFString, 12.0, nil, CTFontOptions.preventAutoActivation)

In theory, CTFontManagerSetAutoActivationSetting should provide a way to disable auto activation without directly modifying the WebKit code, but my attempts to disable it for the current bundle did not seem to have an effect. I tried disabling auto activation for the current bundle, globally and with a nil bundle identifier, and none of these changes disabled the download dialog.

There is not a lot of documentation about auto activation, and many references to it have been removed (e.g., the Font Book no longer has an option regarding auto activation). It could be that the above problem with CTFontManagerSetAutoActivationSetting are simply bugs in 10.12 that warrant filing a Radar.

Font download prompt

0

There are 0 answers