Can Flash detect missing embedded fonts and / or replace with available fonts?

Edited Short Version:

Adobe Flash embedFonts list the embedFonts property in TextAreas:

A boolean value indicating whether the font specified in fontFamily is an embedded font. This style must be set true if fontFamily refers to the inline font. Otherwise, the embedded font is not used. If this style is set to true and fontFamily is not referenced for the embedded font, no text is displayed. The default value is false.

Regarding "If this style is set to true and fontFamily does not apply to the embedded font, the text does not appear": how can I detect in ActionScript when this script occurs?

TL DR Original Version:

I have a flash application that downloads external .swf files containing embedded fonts so that these fonts can be used in the main application. We achieve this by using the following ActionScript code for everything that uses custom fonts:

 textBoxName.embedFonts = true; 

However, sometimes the requested font is not available in the external .swf file that is being downloaded - this often happens when someone makes changes to the external .swf and does not include all the fonts that were previously there ...

The reason is not important, it is important that this is inevitable and will happen. When this happens, any text in the font that is not available is not displayed at all. For instance:

  • The main application is configured to use "Myriad". It downloads an external swf file that contains Myriad along with several other fonts
  • After some time, external swf is an update containing a new set of fonts, and Myriad is no longer one of them. But the main application is not updated.
  • Now all the text in the main application that was in "Myriad" is no longer displayed.

Is there any way by default to use a font that is available or to detect that the font is not available and run some ActionScript code?

EDIT: In case that matters, here is the code I use to download fonts from external swf files:

 // Font Loader: var loadedFonts = Array(); var fontPakLoadHandler = new Object(); fontPakLoadHandler.percent = 0; fontPakLoadHandler.onLoadStart = function(target_mc:MovieClip) { if(!SuspendEvents) ExternalInterface.call("fontLoadStart", _root.lcId); } fontPakLoadHandler.onLoadInit = function(target_mc:MovieClip) { if(!SuspendEvents) ExternalInterface.call("fontLoadInit", _root.lcId); } fontPakLoadHandler.onLoadError = function(target_mc:MovieClip, errorCode:String, httpStatus:Number) { if(!SuspendEvents) ExternalInterface.call("fontLoadError", _root.lcId, errorCode, httpStatus); } if(_root.fontPakProgress=='all') { fontPakLoadHandler.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) { fontPakLoadHandler.percent = loadedBytes / totalBytes; if(!SuspendEvents) ExternalInterface.call("fontLoadProgress", _root.lcId, loadedBytes, totalBytes, fontPakLoadHandler.percent); } } else { fontPakLoadHandler.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) { var perc = loadedBytes / totalBytes; if( (fontPakLoadHandler.percent < .75 && perc >= .75) || (fontPakLoadHandler.percent < .50 && perc >= .50) || (fontPakLoadHandler.percent < .25 && perc >= .25)) { if(!SuspendEvents) ExternalInterface.call("fontLoadProgress", _root.lcId, loadedBytes, totalBytes, perc); } fontPakLoadHandler.percent = perc; } } fontPakLoadHandler.onLoadComplete = function(target_mc:MovieClip, httpStatus:Number) { if(!SuspendEvents) ExternalInterface.call("flashReady", _root.lcId, true); //ExternalInterface.call("fontLoadComplete", _root.lcId, httpStatus); } var fontPakLoader = new MovieClipLoader(); fontPakLoader.addListener(fontPakLoadHandler); 
+4
source share
1 answer

Unfortunately, there is no way to list all the available embedded fonts in ActionScript 2, as it is in Font.enumerateFonts () in ActionScript 3. You can only get a list of fonts installed on the user computer via TextField.getFontList ().

However, you can manually specify a list of available font names (possibly in xml) and load it into the main SWF. You can then compare the font names in this list every time you use the built-in font, and replace the default font or even use a replacement map if the one you want is not available.

It's not as elegant as automatically retrieving a complete list from content, but it should do the trick without recompiling the main application.

+2
source

Source: https://habr.com/ru/post/1333075/


All Articles