Setting the kerning level on the TextGraphic object in Flex Gumbo

The following example shows how you can set the kerning on a Flex Gumbo TextGraphic object by setting the kerning style to one of the static constants in the flash.text.engine.Kerning class.

Full code after the jump.

To use the following code, you must have Flash Player 10 and a Flex Gumbo SDK installed in your Flex Builder 3. For more information on downloading and installing the Gumbo SDK into Flex Builder 3, see “Using the beta Gumbo SDK in Flex Builder 3”.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/01/08/setting-the-kerning-level-on-the-textgraphic-object-in-flex-gumbo/ -->
<Application name="TextGraphic_kerning_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <Style>
        @font-face {
            src: url("assets/ArnoPro-Regular.otf");
            fontFamily: EmbeddedArno;
            cff: true;
        }

        TextGraphic {
            fontFamily: EmbeddedArno;
            fontLookup: embeddedCFF;
            fontSize: 64;
        }
    </Style>

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="text:">
                <TextInput id="textInput"
                        text="AVAST YE MATEY, SAIL AWAY"
                        maxChars="30" />
            </FormItem>
            <FormItem label="kerning:">
                <ComboBox id="comboBox"
                        dataProvider="[auto,on,off]" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <VGroup clipContent="true">
        <TextGraphic id="textGr"
                text="{textInput.text}"
                kerning="{comboBox.selectedItem}"
                width="600" />
    </VGroup>

</Application>

You can also set the kerning style in an external .CSS file or <Style> block, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/01/08/setting-the-kerning-level-on-the-textgraphic-object-in-flex-gumbo/ -->
<Application name="TextGraphic_kerning_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <Style>
        @font-face {
            src: url("assets/ArnoPro-Regular.otf");
            fontFamily: EmbeddedArno;
            cff: true;
        }

        TextGraphic {
            fontFamily: EmbeddedArno;
            fontLookup: embeddedCFF;
            fontSize: 64;
            kerning: off;
        }
    </Style>

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="text:">
                <TextInput id="textInput"
                        text="AVAST YE MATEY, SAIL AWAY"
                        maxChars="30" />
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <VGroup clipContent="true">
        <TextGraphic id="textGr"
                text="{textInput.text}"
                width="600" />
    </VGroup>

</Application>

Or, you can set the kerning style using ActionScript, as seen in the following example:

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/01/08/setting-the-kerning-level-on-the-textgraphic-object-in-flex-gumbo/ -->
<Application name="TextGraphic_kerning_test"
        xmlns="http://ns.adobe.com/mxml/2009"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <Style>
        @font-face {
            src: url("assets/ArnoPro-Regular.otf");
            fontFamily: EmbeddedArno;
            cff: true;
        }

        TextGraphic {
            fontFamily: EmbeddedArno;
            fontLookup: embeddedCFF;
            fontSize: 64;
        }
    </Style>

    <Script>
        <![CDATA[
            import flash.text.engine.Kerning;
            import mx.events.ListEvent;

            private function comboBox_change(evt:ListEvent):void {
                textGr.setStyle("kerning", comboBox.selectedItem);
            }
        ]]>
    </Script>

    <ApplicationControlBar dock="true">
        <Form styleName="plain">
            <FormItem label="text:">
                <TextInput id="textInput"
                        text="AVAST YE MATEY, SAIL AWAY"
                        maxChars="30" />
            </FormItem>
            <FormItem label="kerning:">
                <ComboBox id="comboBox"
                        change="comboBox_change(event);">
                    <dataProvider>
                        <Array>
                            <String>{Kerning.AUTO}</String>
                            <String>{Kerning.ON}</String>
                            <String>{Kerning.OFF}</String>
                        </Array>
                    </dataProvider>
                </ComboBox>
            </FormItem>
        </Form>
    </ApplicationControlBar>

    <VGroup clipContent="true">
        <TextGraphic id="textGr"
                text="{textInput.text}"
                width="600" />
    </VGroup>

</Application>

This entry is based on a beta version of the Flex Gumbo SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex Gumbo SDK.

2 thoughts on “Setting the kerning level on the TextGraphic object in Flex Gumbo

    1. @David Salahi,

      Yes, this example is quite old and written on an old beta Flex 4 SDK. Something like the following should work:

       
      <?xml version="1.0" encoding="utf-8"?>
      <s:Application name="Spark_Label_kerning_test"
              xmlns:fx="http://ns.adobe.com/mxml/2009" 
              xmlns:s="library://ns.adobe.com/flex/spark" 
              xmlns:mx="library://ns.adobe.com/flex/mx">
       
          <fx:Style>
              @namespace s "library://ns.adobe.com/flex/spark";
              @namespace mx "library://ns.adobe.com/flex/mx";
       
              @font-face {
                  src: url("C:/Windows/Fonts/Arial.ttf");
                  fontFamily: EmbeddedArno;
                  embedAsCFF: true;
              }
       
              s|Label#textGr {
                  fontFamily: EmbeddedArno;
                  fontLookup: embeddedCFF;
                  fontSize: 64;
              }
          </fx:Style>
       
          <s:controlBarContent>
              <mx:Form styleName="plain">
                  <mx:FormItem label="text:">
                      <s:TextInput id="textInput"
                              text="AVAST YE MATEY, SAIL AWAY"
                              maxChars="30" />
                  </mx:FormItem>
                  <mx:FormItem label="kerning:">
                      <s:DropDownList id="comboBox" selectedItem="auto">
                          <s:dataProvider>
                              <s:ArrayList source="[auto,on,off]" />
                          </s:dataProvider>
                      </s:DropDownList>
                  </mx:FormItem>
              </mx:Form>
          </s:controlBarContent>
       
          <s:Label id="textGr"
                  text="{textInput.text}"
                  kerning="{comboBox.selectedItem}"
                  width="600"
                  horizontalCenter="0" verticalCenter="0" />
       
      </s:Application>

      I’ll try and update the entry above when I get a bit of time.

      Peter

Comments are closed.