7 Replies Latest reply on Aug 3, 2011 9:24 PM by cloudguitar

    setFormatOfRange applies wrong font

    cloudguitar

      Hi all,

       

      I am having an issue changing the font for text in a RichEditableText to an embedded font. I am using Flex 4.1, and my code looks more or less like this (simplified):

       

      <fx:Style>
           @namespace s "library://ns.adobe.com/flex/spark";
           @namespace mx "library://ns.adobe.com/flex/mx";
           
           @font-face { 
                src: url("assets/txt/BlackCasper.ttf"); 
                fontFamily: BlackCasper; 
                embedAsCFF: true; 
           }
      </fx:Style>
      
      <fx:Script>
           <![CDATA[
           import mx.events.FlexEvent;
      
              public function setFont() : void {
                var newTlf : TextLayoutFormat = new TextLayoutFormat;
                newTlf.fontFamily = "BlackCasper";
                text.setFormatOfRange(newTlf);
           }
      
           ]]>
      </fx:Script>
      
      <s:RichEditableText id="text"
                top="5" bottom="5" left="5" right="5"
                selectionHighlighting="{TextSelectionHighlighting.ALWAYS}"
                fontSize="70" editable="false" selectable="false"
                />
      
      

       

      Polling Font.enumerateFonts in setFont lists "BlackCasper" correctly, so the font seems properly embedded. Also, if I set text.setStyle("fontFamily","BlackCasper"), the font is set correctly for the entire RichEditableText. However, if I call my function setFont, the selected text changes to a standard system font, instead of changing to the embedded font. I tried using a string that was not listed by Font.enumerateFonts(true) as fontFamily, and the selection changes to the same system font that it changes to if I use "BlackCasper". Finally, if I use a system font as fontFamily, then the selection changes (correctly) to the specified system font. From these observations, it would appear to me that a font family for an embedded font is not recognized by setFormatOfRange, which instead uses a default. Does anyone has any suggestions on how to fix this?

       

      Thanks in advance!