2012-08-02 2 views
0

Я пытаюсь использовать встроенные шрифты (Flex 4.6) в UITextField. До тех пор, пока я использую шрифт, который зарегистрирован в Windows, он работает нормально, но для шрифта, который не зарегистрирован, UITextField по умолчанию использует TimesRoman (или что-то подобное)Flex 4.6: встроенные шрифты не применяются к TextField

Обратите внимание, что когда я проверяю, включен ли этот шрифт , он возвращает True (FlexGlobals.topLevelApplication.systemManager.isFontFaceEmbedded (txtFormatCoda))

Так что же мне не хватает?

В приведенном ниже коде, если я добавлю шрифт Kredit в шрифт Windows, текстовое поле пользовательского интерфейса появится в шрифте Kredit, но если я удалю его из каталога Windows/font, это поле появится в TimesNewRoman (шрифт по умолчанию).

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="onComplete()"> 
    <s:Group id="TextCanvas" x="121" y="97" width="474" height="800"> 
    </s:Group> 
    <fx:Style> 
     @font-face { 
      src: url("fonts/KREDIT1.TTF"); 
      fontFamily: Kredit; 
      embed-as-cff:false; 
      advancedAntiAliasing:true; 
     } 
    </fx:Style> 
    <fx:Script>  
     import mx.core.FlexGlobals; 
     import mx.core.UIComponent; 
     import mx.core.UITextField; 
     import mx.core.UITextFormat; 


     public function onComplete():void{ 
      var txtFldCoda:UITextField = new UITextField(); 
      var txtFormatCoda:UITextFormat = new UITextFormat(this.systemManager); 
      var compCoda:UIComponent = new UIComponent(); 
      compCoda.addChild(txtFldCoda); 
      txtFldCoda.embedFonts=true;   
      txtFldCoda.width=300; 
      txtFormatCoda.size=33; 
      TextCanvas.addElement(compCoda); 
      txtFldCoda.text="Testing Kredit"; 
      txtFormatCoda.font= "Kredit"; 
      txtFormatCoda.color="0x0ff345"; 
      var b2:Boolean = FlexGlobals.topLevelApplication.systemManager.isFontFaceEmbedded(txtFormatCoda); 
      if(b2==false){ 
       trace("not embedded: " + txtFormatCoda.font); 
      } 
      txtFldCoda.defaultTextFormat= txtFormatCoda;//note that setTextFormat must be after setting the text 
      txtFldCoda.setTextFormat(txtFormatCoda);//note that setTextFormat must be after setting the text 
      txtFldCoda.x=0; 
      txtFldCoda.y=100;   
     }  
    </fx:Script> 
</s:Application> 

ответ

0

Ниже кода может помочь вам: - Я заметил одну строку и модифицированный тег стиль ...

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="onComplete()" 
       > 
    <s:Group id="TextCanvas" x="121" y="97" width="474" height="800"> 
    </s:Group> 
    <fx:Style> 
     @namespace s "library://ns.adobe.com/flex/spark"; 
     @namespace mx "library://ns.adobe.com/flex/mx"; 

     @font-face { 
      src: url("fonts/KREDIT1.TTF"); 
      fontFamily: KREDIT1; 
      embed-as-cff: false; 
      advancedAntiAliasing:true; 
     } 

     s|Application 
     { 
      fontFamily:KREDIT1; 
     } 
    </fx:Style> 
    <fx:Script>  
     import mx.core.FlexGlobals; 
     import mx.core.UIComponent; 
     import mx.core.UITextField; 
     import mx.core.UITextFormat; 

     public function onComplete():void{ 
      var txtFldCoda:UITextField = new UITextField(); 
      var txtFormatCoda:UITextFormat = new UITextFormat(this.systemManager); 
      var compCoda:UIComponent = new UIComponent(); 
      compCoda.addChild(txtFldCoda); 
      txtFldCoda.embedFonts=true;   
      txtFldCoda.width=300; 
      txtFormatCoda.size=33; 
      TextCanvas.addElement(compCoda); 
      txtFldCoda.text="Testing Kredit"; 
      //txtFormatCoda.font= "Kredit"; 
      txtFormatCoda.color="0x0ff345"; 
      var b2:Boolean = FlexGlobals.topLevelApplication.systemManager.isFontFaceEmbedded(txtFormatCoda); 
      if(b2==false){ 
       trace("not embedded: " + txtFormatCoda.font); 
      } 
      txtFldCoda.defaultTextFormat= txtFormatCoda;//note that setTextFormat must be after setting the text 
      txtFldCoda.setTextFormat(txtFormatCoda);//note that setTextFormat must be after setting the text 
      txtFldCoda.x=0; 
      txtFldCoda.y=100;   
     }  
    </fx:Script> 
</s:Application> 
+0

Thanks Mahesh Не получилось попробовать ваше решение в следующем виде: –

1

Благодарности Махеш

На самом деле это работало для меня:

var comp:UIComponent = new UIComponent(); 
comp.setStyle('fontFamily', fontName);      

В основном мне приходилось делать setStyle на UIComponent, который является родительским элементом этого UITextField. Я хочу, чтобы Adobe документировала это.

Смежные вопросы