Using a CFF embedded font with an MX Label control in Flex 4
The following example shows how you can use a CFF embedded font with a Halo Label control and Spark Label control by setting the textFieldClass style on the MX Label control to the mx.core.UIFTETextField class.
The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.
For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/06/14/using-a-cff-embedded-font-with-a-halo-label-control-in-flex-4/ --> <s:Application name="MX_Label_textFieldClass_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 mx "library://ns.adobe.com/flex/mx"; @namespace s "library://ns.adobe.com/flex/spark"; @font-face { src: url("fonts/base02.ttf"); fontFamily: Base02Embedded; embedAsCFF: true; } mx|Label, s|Label { fontFamily: Base02Embedded; fontSize: 16; } </fx:Style> <s:VGroup horizontalCenter="0" verticalCenter="0"> <mx:Label id="hLbl" text="The quick brown fox jumps over the lazy dog. [mx|Label]" textFieldClass="mx.core.UIFTETextField" width="100%" /> <s:Label id="sLbl" text="The quick brown fox jumps over the lazy dog. [s|Label]" width="100%" /> </s:VGroup> </s:Application>
View source is enabled in the following example.
You can also set the textFieldClass style using an external .CSS file or <Style/> block, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/06/14/using-a-cff-embedded-font-with-a-halo-label-control-in-flex-4/ --> <s:Application name="MX_Label_textFieldClass_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 mx "library://ns.adobe.com/flex/mx"; @namespace s "library://ns.adobe.com/flex/spark"; @font-face { src: url("fonts/base02.ttf"); fontFamily: Base02Embedded; embedAsCFF: true; } mx|Label { fontFamily: Base02Embedded; fontSize: 16; textFieldClass: ClassReference("mx.core.UIFTETextField"); } s|Label { fontFamily: Base02Embedded; fontSize: 16; } </fx:Style> <s:VGroup horizontalCenter="0" verticalCenter="0"> <mx:Label id="hLbl" text="The quick brown fox jumps over the lazy dog. [mx|Label]" width="100%" /> <s:Label id="sLbl" text="The quick brown fox jumps over the lazy dog. [s|Label]" width="100%" /> </s:VGroup> </s:Application>
Base 02 font by www.stereo-type.net.
This entry is based on a beta version of the Flex 4 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 4 SDK.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
11 Responses to Using a CFF embedded font with an MX Label control in Flex 4
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Will we be able to use the same css on a datagrid? I noticed the datagrid component also has the textFieldClass attribute. Applying similar css, as in your example, makes the text in the datagrid disappear.
NBiehl,
I haven’t tried this with the Halo DataGrid yet. Can you please file a bug at http://bugs.adobe.com/flex/ and include a simple test case and myself or somebody else can take a look at it.
Thanks,
Peter
Is there any reason why you would not want to automatically set the textFieldClass to the new TLF one? It seems like you would always want to do it in the stylesheet for all Labels (and Text too?) so that you can forget about the difference in the rest of the app.
I’d probably recommend using the new UITLFTextField class wherever possible. Although I’m semi-certain that they do not work with all Halo controls, so you may not be able to set the
textFieldClassstyle globally.Peter
Hi,
I don’t manage to embed font in TLF.
Here is my development environment :
– Vista
– Flex Builder 3
– SDK 4 (all last build tested)
– using TLF
– using halo (mx:Application)
I have an XML text file (Text Layout Format, not HTML) imported at runtime (TexTConverter.importToFlow).
In this xml I set theses options :
I embed the font by using an external CSS file :
Labels, TextInputs etc are using the embedded font but not the TLF, which display text in Times New Roman…
Note 1 :
I also tested to embed the font in AS :
With or without “Font.registerFont(TahomaFont);” => don’t change anything.
Note 2 :
When I generate a SWF Font with CS4 (by using SDK3 then SDK4) and use it like that :
I have a compilation error : le paramètre de transcodage embedAsCFF n’est pas pris en charge par
flex2.compiler.media.MovieTranscoder
If I dont set the option “embedAsCFF”, the font is embedded and works fine, except for TLF of course…
Note 3 :
If I don’t set the font fontLookup option in the XML text file, it works nice, the TLF use Tahoma but the font used is not
the embedded Tahoma font (I have differents results on Linux and Vista, just for TLF texts).
Note 4 :
I am sure to compile with SDK 4, I even tried different SDK.
Note 5 :
I can’t turn my application into a Spark Application. The fact is that I have only seen TLF examples with a Spark
Application, maybe it’s not possible to embed font in TLF with a Halo App ?
Note 6 :
I also tried to import TextFlow with a Configuration (for overriding options in the initial format, with CFF etc) : do
nothing.
Please help… I read Adobe TLF forum, many blog… and found nothing !!
What’s wrong with this code ??
Thanks
Yannick
@Yannick,
The following example works for me with mx:Application, s:Label, s:Button, s:TextInput, and s:RichEditableText controls and CFF fonts:
But this may depend on how complex your TextFlow is, and whether you’re trying to mix embedded and device fonts, and whether you’re trying to use a CFF embedd font with MX controls vs Spark controls, etc.
Peter
This is probably slightly closer to your setup, but I still don’t think I can reproduce the issue you’re describing:
And the tFlow.txt file is as follows:
Peter
[COMMENT PART 1 (due to spam protection...)]
Hi Peter,
TY for answer. If I change your application into a Spark application (s:App) : it works nice, font is embedded, same result on Linux & Vista. But, always with s:App, if I load the
textFlow from a XML, it doesn’t work.
Moreover, I can’t compile your example as it, because of namespaces.
Case 1 : compile, no runtime error, but embedded font not work if xml loaded
AS : with “addChild” function
Case 2 : compile, no runtime error, but embedded font not work if xml loaded
AS : with “addElement” function
Case 3 : don’t compile
Error : can’t resolve mx:Application into a component
[COMMENT PART 2 (due to spam protection...)]
I googled many hours a few weeks ago and found nothing.
The fact is I can run samples applications with TLF, which is in SDK4, so I am sure to use SDK4.
– I especialy take a look here
– different SDK4 build tested…
– putting the globalplayers.swc of SDK4 in external in the Fx project…
I never understood why I could’nt use mx:Application ! Maybe this is a part of the solution for embedded font in TLF (?)
So now, my sample code
The XML loaded :
[COMMENT PART 3 (due to spam protection...)]
The Application (I give the Spark App sample, even if I _must_ use an mx:Application)
=> given in another comment because my comment is too long…
@namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/mx"; @font-face{ src: url("C:/Windows/fonts/tahomabd.ttf"); font-family: "TahomaCFF"; font-weight: bold; embedAsCFF: true; } @font-face{ src: url("C:/Windows/fonts/tahoma.ttf"); font-family: "TahomaCFF"; embedAsCFF: true; } global { font-family: "TahomaCFF"; font-lookup: embeddedCFF; font-size: 24; }In all cases, the label is ok, with the global embedded font defined.
[COMMENT PART 4 (due to spam protection...)]
Note 1 : I also tried to override FontMananger priority in a config file, but don’t change anything :
flash.fonts.JREFontManager
flash.fonts.AFEFontManager
flash.fonts.BatikFontManager
Note 2 : In fact, I have two problems :
– I can’t use new namespaces with an mx:Application, I must use 2006 namespace.
– I tested both “library://ns.adobe.com/flex/mx” and “library://ns.adobe.com/flex/halo”
– When I use Spark App, I lose completion and syntax coloration, so it is totaly unproductive
– I can’t embed font in TLF
Note 3 : When I display embedded font (Font.enumerateFonts(false)) With all embedded fonts I tested, isFontCompatible is always false ! (see sample)
Thanks for your help !
Yannick
It looks like you’re using an old version of the Flex 4 SDK. Please update to a newer nightly version of Flex 4+ from http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4 and try again.
Also, it may work better if you try downloading the Flash Builder 4 beta instead of using Flex Builder 3.
Peter
Hi again !
1) Sorry about my previous comment, I put my mxml code into “code” tag but it seems it didn’t work…
2) Not without having really strange behaviours, I can now use “mx:Application” with the new namespaces by using a recent SDK4 build.
3) Your sample works :) But you use , I didn’t… (in fact I “couldn’t”). Since I can use Spark component like R.E.T, it will be The Deliverance !! (I hope)
The remaining problems are :
– no code-hints and colors in files using new namespaces
– html-template must be generated by hand for Flex Application (this is not really a problem)
I followed the official Adobe tutorial to correct code-hints but I still have little problems, but not really important. (colors sometimes disappears, etc)
Thanks Peter for yours replies, it will normaly correct my problem of embedded font with TLF, I will try to use some Spark component from now :)
Yannick
ps: I’am pretty sure there are some bugs during compilation when you create a Flex Project using SDK3 and then you change it to SDK4. Since I have started with a new workspace with the SDK4 directly set a default for creating new project, I didn’t see any problems.
Hi,
I have found the real problem : -theme=${flexlib}/themes/Halo/halo.swc
When you add this line to the compiler, the fonts in the TLF aren’t embedded anymore ! OFC, this is not the case in your sample… (with Spark components only).
Yannick