Finding out which fonts are installed on a user’s system
The following example shows how you can use the static Font.enumerateFonts() method in Flex to determine which fonts are installed on a user’s system. The enumerateFonts() method returns an array of Font objects (see the flash.text.Font for more information)
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/10/finding-out-which-fonts-are-installed-on-a-users-system/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.text.Font;
private function init():void {
arr = Font.enumerateFonts(true);
arr.sortOn("fontName", Array.CASEINSENSITIVE);
}
]]>
</mx:Script>
<mx:Array id="arr" />
<mx:String id="str">The quick brown fox jumped over the lazy dog.</mx:String>
<mx:ApplicationControlBar dock="true">
<mx:Label text="String:" />
<mx:TextInput id="textInput" text="{str}" />
<mx:Spacer width="100%" />
<mx:Label text="Number of installed fonts: {arr.length}" />
</mx:ApplicationControlBar>
<mx:DataGrid id="dataGrid" dataProvider="{arr}">
<mx:columns>
<mx:DataGridColumn dataField="fontName"
width="200"
itemRenderer="mx.controls.Label" />
<mx:DataGridColumn dataField="fontStyle" />
<mx:DataGridColumn dataField="fontType" />
</mx:columns>
</mx:DataGrid>
<mx:Label id="lbl"
text="{textInput.text}"
width="{dataGrid.width}"
height="32"
fontFamily="{dataGrid.selectedItem.fontName}"
fontSize="16" />
</mx:Application>
View source is enabled in the following example.
Note that in the previous example, we passed a value of true to the enumerateFonts() method. The enumerateFonts() method takes a single Boolean parameter, enumerateDeviceFonts (default value is false), which controls whether both device and embedded fonts are returned (true) or whether just embedded fonts are returned (false).
If you modified the previous example and embedded a font using the following code, you would see that an additional font “Base02″ appears in the data grid:
<mx:Style>
@font-face{
src: url("./fonts/base02.ttf");
fontFamily: "Base02";
}
</mx:Style>
Also, if you modified the <mx:Script /> tag and passed false to the enumerateFonts() method, only one item would be displayed in the data grid (fontName:”Base02″, fontStyle:”regular”, fontType:”embedded”):
<mx:Script>
<![CDATA[
import flash.text.Font;
private function init():void {
arr = Font.enumerateFonts(false);
arr.sortOn("fontName", Array.CASEINSENSITIVE);
}
]]>
</mx:Script>
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.
8 Responses to Finding out which fonts are installed on a user’s system
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


Question/Issue: (I haven’t tested this in Flex but Flash CS3 doesn’t allow it (for understood reasons).) Can you embed those fonts and do rotations, etc on the textfield? CS3 would show the font properly but doing rotatings was a no-no.
John C. Bland II,
You should be able to rotate embedded font no problem as long as it is embedded properly. In fact, I believe I covered an example of embedding fonts with alpha fades and rotations in a Flash CS3 Quick Start I wrote a while back.
For more information, see http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/ (specifically the last example).
I don’t know that I’ve specifically tried this in Flex (although I do recall posting something on rotating tooltips which probably applies).
Peter
Yes, with pre-embedded fonts…no prob. What I mean is getting the users font list and rotating on those.
John,
I’m not sure how/if that could be done (you’d have to ask on Flexcoders list). Since the embed is done at compile time in Flex and the font is “baked” into the SWF, I don’t know how you could do something similar at run time. But I haven’t really tried this so maybe I’m just overlooking something.
Sorry,
Peter
Yeah, no sweat because I informed the client of that and used embedded fonts and we’re months beyond this stage. When I saw the post I figured I’d ask to see if I was wrong because they were adamant about it being possible. :-D
Nice one Peter, Is there any way of finding out whats the language of the font
like english, french, latin and we can display that in the datagrid…
What abot showing fonts located in a directory? Let’s say I have additional fonts that aren’t currently enabled. I typically use a font management tool to turn them on. But I’d like to create a tool viewing fonts I have to determine if I want to turn it on.
helpful article, now embedded fonts can display in my photoshop panel, but having problem when i tried to assign that font in photoshop text layer.
Please suggest so that my embedded font will also render in photoshop active text layer.
Biran