Skip to main content
Vikram_S
Known Participant
November 10, 2010
Answered

Unable to apply embedded font swf to text in text layout framework

  • November 10, 2010
  • 1 reply
  • 1485 views

Hello,

We have created a swf for a given font (for e.g., Calibri.swf) which contains all the styles (Regular, Italic, Bold, BoldItalic).

We have created a xml which lists the name of the font and the corresponding swf file path. The names from the xml are loaded into a combo box in the application.

When we try to apply the selected font to a text in the text layout framework, it does not apply the same. It sets the font to default "Times" font.

Following is a snippet of code to apply the font to the text:

private function selectFont(fontXML:XML):void {               
                var path:String = fontXML.@source;
                var myEvent:IEventDispatcher = styleManager.loadStyleDeclarations(FlexGlobals.topLevelApplication.url.substring(0,FlexGlobals.topLevelApplication.url.lastIndexOf("/"))+"/"+path);
                myEvent.addEventListener(StyleEvent.COMPLETE, function(event:StyleEvent):void{
                    var editManager:EditManager = textFlow.interactionManager as EditManager;
                    var itextLayout:TextLayoutFormat = new TextLayoutFormat();
                    itextLayout.fontSize = 20;
                    var fontName:String = fontXML.@name;
                    Alert.show(fontName);
                    itextLayout.fontFamily = fontName;   
                    Alert.show( "itext = " + itextLayout.fontFamily);
                    editManager.applyFormat(itextLayout,itextLayout,itextLayout);
                    var flowLeafElement:FlowElement = textFlow.findLeaf(editManager.anchorPosition) as FlowElement;
                    editManager.changeStyleName(fontName,flowLeafElement);
                });
            }

Can anyone please let us know what is missing in the implementation?

Thanks in advance.

Vikram

This topic has been closed for replies.
Correct answer robin_briggs

Did you set the fontLookup in ITextLayoutFormat? It should be set to look for the font as an embedded font. I think by default it will consider it as a device font.

- robin

1 reply

Adobe Employee
November 10, 2010

Please read Alex's blog post - I think this will give some guidance on how Flex's font embedding and registration system is working.

Is the TextFlow something you've created or did it come from a RichEditableText?  Depending on if the font is registered or if its only known to the sub-swf you may need to set a swfContext on the textFlow.flowComposer.   What this helps with is making sure calls into the player are made in the context of the SWF that actually knows about the font.

In your code the call to changeStyleName is setting the styleName property on flowLeafElement to fontName.  That's not going to have anything to do with getting the fonts to work.  Unless that's intentional you don't need that.

Hope that helps,

Richard

Participating Frequently
December 1, 2010

My recommendation: unless you really care about ISWFContext implementations and the application domain issues, ignore Alex's post about embedded fonts.

It is a nice discussion about the inner workings of the domain and security of how this works but it is imho broken and is an insane concept to require an ISWFContext to just use an embedded font. It also breaks runtime CSS loading that has fonts embedded in it because the Flex compiler (last I checked) was also busted – it doesn't include the function necessary to create within context the font embed so that it may be applied. You can't create an ISWFContext with a compiled CSS file.

These issues were introduced in the last Flex SDK beta before FB4 was released in final form. There are multiple bugs logged against the issue of applying loaded font files to TLF text (in short, SWFContext is broken and you have to override GlobalSettings.resolveFontLookupFunction to return embedded or null, all the time).

Here's some more details to get you started - with links to at least one of the SDK bugs that were filed:

http://forums.adobe.com/message/2656152

For example:

import flashx.textLayout.elements.GlobalSettings;

import flash.text.engine.FontLookup;

GlobalSettings.resolveFontLookupFunction = function makeValid():String { return FontLookup.EMBEDDED_CFF };

And you may need to do this after your font is loaded:

yourTextBlock.textFlow.invalidateAllFormats();

Disclaimer: I haven't seen the latest Flex SDK release to see if this was fixed. I have an AIR application with native process that builds embedded font SWF files for use and stub code for FB4 usage but haven't updated to the latest SDK yet to see if it's working properly.


Anyhow, your best bet is to look at the Flash Builder forums. I think this is/was a Flex team issue, not TLF.

robin_briggsCorrect answer
Adobe Employee
December 1, 2010

Did you set the fontLookup in ITextLayoutFormat? It should be set to look for the font as an embedded font. I think by default it will consider it as a device font.

- robin