Fonts are not displayed correctly

Troubleshooting

Summary

This article shows what to do if special characters are not displayed or text is not rotated.

Description

System fonts may not always display special characters correctly. Another problem with using system fonts appears when text is rotated, e.g. in rotated labels: Rotating text is only available with embedded fonts.

The Adobe Flex documentation explains how to embed fonts in ActionScript: // Flex 3: [Embed(systemFont='serif', fontName='MyEmbeddedSerif', mimeType='application/x-font')] private var Serif:Class; // Flex 4: don't embed as CFF: [Embed(systemFont='serif', fontName='MyEmbeddedSerif', mimeType='application/x-font', embedAsCFF='false')] private var Serif:Class; 'serif' refers to the default serif system font (Times New Roman in Windows). Depending on the system, this font should support a large character set. If 'serif' doesn't work, try embedding and using a different font. The Adobe Flex documentation explains how to embed fonts in ActionScript.

Using this font as default font for all labels is easy. Before creating any labels set the default font:

FontManager.INSTANCE.defaultFont = "MyEmbeddedSerif";

To set the font to the text of one or more specific labels, one has to create a UITextFormat instance and set the font property (by using the fontName) of that instance. var format:UITextFormat = FontManager.INSTANCE.getDefaultTextFormat(); format.font = "MyEmbeddedSerif"; For label text, that text format has to be passed to the label style: graph.defaultNodeLabelStyle = new SimpleLabelStyle(null,format);

To use an embedded font with a server-generated graph, set the fontName attribute of the embedded font to the name, the server side used font is serialized with. Alternatively, it is possible to map the embedded font to the server side font name: FontManager.INSTANCE.mapFont(SERVER_FONT, "MyEmbeddedSerif"); Where SERVER_FONT is the name, the font is serialized with on the server, as String. This line has to be added before the graph is deserialized, i.e. usually before the call to RoundtripHandler.run().

As embedding fonts within an SWF will increase the SWF's size, it is recommended to use embedded fonts only if the text is not displayed correctly with system fonts. Especially the symbolic fonts 'serif' and 'dialog' can add some 100 kB to the SWF.

The size of an embedded font can be reduced by embedding only a range of characters using the unicodeRange attribute in the Embed statement.

One Embed statement embeds only one font with one weight and one style. If one wants to display text with normal and, e.g. bold weight, he has to Embed the font twice: once with normal weight and once with bold weight.

The following example demonstrates how to embed the font system font 'dialog' as font with the name 'Dialog' to be displayed as normal and bold characters. To reduce the size of the SWF only a small subset of characters is embedded.

[Embed(systemFont='dialog', fontName='Dialog', mimeType='application/x-font',
  unicodeRange="U+0020-U+007E,U+00A0-U+00FF")]
private var Dialog:Class;

[Embed(systemFont='dialog', fontWeight='bold', fontName='Dialog', mimeType='application/x-font',
  unicodeRange="U+0020-U+007E,U+00A0-U+00FF")]
private var DialogBold:Class;
If an embedded font is to be displayed in a weight or style which is not embedded, the characters are displayed in plain weight and style. If String which is displayed with an embedded font contains glyphs which are not in that font, these glyphs won't be displayed at all.

Categories this article belongs to:
yFiles FLEX > Displaying and Editing Graphs > Visual Representation of Graph Elements
Applies to:
yFiles FLEX: 1.4, 1.5, 1.6, 1.7, 1.8
Keywords:
font - fonts - embedded fonts - rotated text - RotatingEdgeLabelModel - edge labels