开发者

Example of using embedded fonts loaded at runtime Flex 4 runtime loaded modules

am having quite alot of problems trying to use embeded fonts in flex 4. Here is the situation.

I have a main application that fist load the fonts via a URL. This is the font file code:

package{
import flash.display.Sprite;
import flash.text.Font;

public class FontLib extends Sprite
{

    [Embed(source="MyriadPro-Regular.otf", fontWeight= "normal", fontName="Myriad Pro", fontFamily="Myriad Pro",mimeType="application/x-font", embedAsCFF="true")]
    public const myriadFont:Class;

    public function FontLib()
    {
        Font.registerFont(myriadFont);
        var fonts:Array = Font.enumerateFonts(false);
        trace('libsss',fonts); 
    }
}}

That seems to work ok. As the trace shows the embedded font when the font swf is loaded.

[SWF] /assets/FontLib.swf - 89,594 bytes after decompression libsss [object Font],[object FontLib_myriadFont]

Once the font swf is loaded I then load the fist module via a URL using ModuleLoader. In the module I execute the following code on creation complete to see if the fonts are loaded:

protected function bookstoremodule1_creationCompleteHandler(event:FlexEvent):void
        {

            var fonts:Array = Font.enumerateFonts(false);
            trace('bs',fonts); // This shows Verdana as a registered font
        }

Thats loaded module seem to have picked up the font:

load module success: bs [object FontLib_myriadFont]

However when I cannot get it to apply to a spark RichText component. Here is the mxml for it:

<s:RichText fontLookup="embeddedCFF" renderingMode="cff" ai:aa="2" color="#2F4160" columnCount="1" fontFamily="Myriad Pro" fontSize="18.0737" height="20" d:id="4" kerning="on" ta开发者_运维问答bStops="S40.665699005127 S81.3313980102539 S121.997097015381 S162.662796020508" text="Shopping Cart (0)" d:userLabel="Shopping Cart (0)" flm:variant="1" whiteSpaceCollapse="preserve" width="168" x="53" y="12" x.down="54" y.down="13" id="richtext1">
    <s:filters>
        <s:DropShadowFilter blurX="0" blurY="0" color="#FFFFFF" distance="1.41421" quality="2"/>
    </s:filters>
</s:RichText>

The mxml definition is fine when the font is embedded directly in the module. It just stops working when the font is loaded as a swf.

Any ideas? I have tried loads of things but still having no luck :(

Thanks


I unfortunately don't have too much time to have a deep look at this problem but this article might interest you :

http://blogs.adobe.com/aharui/2010/03/flex_and_embedded_fonts.html

It talks about registering fonts and using them in modules

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜