Advertisement
Guest User

Flex (v4.1) TLF (v.1.1) not showing embeded font

a guest
Jan 27th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MXML 4.07 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3.                xmlns:s="library://ns.adobe.com/flex/spark"
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
  5.                preinitialize="preinitializeHandler(event)"
  6.                initialize="initializeHandler(event)"
  7.                creationComplete="creationCompleteHandler(event)">
  8.    
  9.     <fx:Style>
  10.         @namespace s "library://ns.adobe.com/flex/spark";
  11.         @namespace mx "library://ns.adobe.com/flex/mx";
  12.        
  13.         @font-face {
  14.             src:url("../assets/fonts/wedtxtn.ttf");
  15.             fontFamily: "CSSFont";
  16.             cff: true;
  17.         }      
  18.     </fx:Style>
  19.    
  20.    
  21.     <fx:Script>
  22.         <![CDATA[
  23.             import flash.text.engine.CFFHinting;
  24.             import flash.text.engine.ElementFormat;
  25.             import flash.text.engine.FontDescription;
  26.             import flash.text.engine.FontLookup;
  27.             import flash.text.engine.RenderingMode;
  28.             import flash.text.engine.TextBlock;
  29.             import flash.text.engine.TextElement;
  30.             import flash.text.engine.TextLine;
  31.            
  32.             import flashx.textLayout.compose.ISWFContext;
  33.             import flashx.textLayout.container.ContainerController;
  34.             import flashx.textLayout.container.ScrollPolicy;
  35.             import flashx.textLayout.container.TextContainerManager;
  36.             import flashx.textLayout.conversion.TextConverter;
  37.             import flashx.textLayout.elements.GlobalSettings;
  38.             import flashx.textLayout.elements.ParagraphElement;
  39.             import flashx.textLayout.elements.SpanElement;
  40.             import flashx.textLayout.elements.TextFlow;
  41.             import flashx.textLayout.formats.ITextLayoutFormat;
  42.            
  43.             import mx.controls.Text;
  44.             import mx.events.FlexEvent;
  45.            
  46.             import spark.core.SpriteVisualElement;
  47.            
  48.            
  49.            
  50.             protected function preinitializeHandler(event:FlexEvent):void
  51.             {
  52.                 GlobalSettings.fontMapperFunction = fontMapperFunction;
  53.             }
  54.            
  55.            
  56.             private function fontMapperFunction(fd:FontDescription):FontDescription
  57.             {
  58.                 return fd;
  59.             }
  60.            
  61.            
  62.            
  63.             protected function initializeHandler(event:FlexEvent):void
  64.             {
  65.                 var fonts:Array = Font.enumerateFonts(false);
  66.                
  67.                 trace("Embeded Fonts:");
  68.                 for each(var font:Font in fonts) {
  69.                     trace(font.fontName+" ("+font.fontStyle+") "+font.fontType);
  70.                 }
  71.                
  72.             }
  73.  
  74.  
  75.             protected function creationCompleteHandler(event:FlexEvent):void
  76.             {
  77.                
  78.                 var element:SpriteVisualElement = new SpriteVisualElement;
  79.                     element.verticalCenter = 0;
  80.                     element.horizontalCenter = 0;
  81.                
  82.                 // Create Text using TLF
  83.                 var span:SpanElement = new SpanElement();
  84.                     span.text = "Hello World!";
  85.                     span.fontLookup = FontLookup.EMBEDDED_CFF;
  86.                     span.renderingMode = RenderingMode.CFF;
  87.                     span.fontFamily = "CSSFont";
  88.                
  89.                 var p:ParagraphElement = new ParagraphElement();
  90.                     p.addChild(span);
  91.                
  92.                 var tf:TextFlow = new TextFlow();
  93.                     tf.addChild(p);
  94.                     tf.fontLookup = FontLookup.EMBEDDED_CFF;
  95.                     tf.renderingMode = RenderingMode.CFF;
  96.                     tf.fontFamily = "CSSFont";
  97.                
  98.                
  99.                 var textContent:Sprite = new Sprite;
  100.                     textContent.y = -50;
  101.                 element.addChild(textContent);
  102.                
  103.                 var textController:ContainerController = new ContainerController(textContent);
  104.                     textController.verticalScrollPolicy = ScrollPolicy.OFF;
  105.                     textController.horizontalScrollPolicy = ScrollPolicy.OFF;
  106.                
  107.                 tf.flowComposer.addController(textController);
  108.                 tf.flowComposer.updateAllControllers();
  109.                
  110.                
  111.                
  112.                 // Create text using FTE               
  113.                 var fontDescription:FontDescription = new FontDescription("CSSFont");
  114.                     fontDescription.fontLookup = FontLookup.EMBEDDED_CFF;
  115.                     fontDescription.renderingMode = RenderingMode.CFF;
  116.                
  117.                 var format:ElementFormat = new ElementFormat(fontDescription,25);
  118.                
  119.                 var textElement:TextElement = new TextElement("Hello World", format);
  120.                    
  121.                 var textBlock:TextBlock = new TextBlock(textElement);
  122.                
  123.                 var tl:TextLine = textBlock.createTextLine();
  124.                     tl.y = 50;
  125.                
  126.                 element.addChild(tl);
  127.                
  128.                 addElement(element);
  129.             }
  130.  
  131.  
  132.  
  133.         ]]>
  134.     </fx:Script>
  135.    
  136.     <s:Label x="10" y="10" text="Font is working on components" fontFamily="CSSFont" fontSize="22" />  
  137. </s:Application>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement