Question

My question is about ligature in Glyphs. There is this example in msdn:

<!-- "Open file" with "fi" ligature -->
<Glyphs
FontUri             = "C:\WINDOWS\Fonts\TIMES.TTF"
FontRenderingEmSize = "36"
StyleSimulations    = "BoldSimulation"
UnicodeString       = "Open file"
Indices             = ";;;;;(2:1)191"
Fill                = "SlateGray"
OriginX             = "400"
OriginY             = "150"
/>

I couldn't find any detailed document in explaining what's going on in the Indices property. When I try to create a Glyphs with Persian characters, lets say "من", I get

م‌ن

Instead of

من

So the question is: How can I implement character ligature in Glyphs?
By the way, I know that I can use FormattedText or TextFormatter.FormatLine(...) method, But I like to know if there is any way to do this in Glyphs or GlyphRun.

No correct solution

OTHER TIPS

The syntax of the Indices property is explained in the Remarks section of the Glyphs.Indices documentation in MSDN.

Each glyph specification has the following form.

[GlyphIndex][,[Advance][,[uOffset][,[vOffset][,[Flags]]]]]

The [] around each field means that is is optional. Hence all fields are optional, meaning that a glyph index specification may be totally empty.

The value ";;;;;(2:1)191" in the example consists of six such specifications, separated by semicolons, where the first five of them are empty. In case a glyph index specification is empty, WPF retrieves the actual glyph index from the GlyphTypeface.CharacterToGlyphMap property.

The documentation also says

The specification of the first glyph in the cluster is preceded by a specification of how many glyphs and how many code points combine to form the cluster.

This is what the prefix (2:1) means. It specifies that two characters from the source string are replaced by one glyph. And of course that glyph has the index 191.

The glyph index itself is just the index of that particular glyph in the chosen font. In the example, it is the fi ligature glyph (a single glyph) at index position 191 in the font Times.ttf.

In your persian character example, it all depends on the font you are using. You have to investigate it in order to find the appropriate replacement glyph for those two characters. It may also be sufficient to just replace the second glyph by some other, in which case you could omit the (2:1) specification and just write the appropriate glyph index.


UPDATE: A very simple tool to inspect all the glyphs in a font file may be written like this:

<ListBox ItemsSource="{Binding GlyphItems}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Glyphs FontUri="{Binding FontUri}" Indices="{Binding Indices}"
                        FontRenderingEmSize="36" OriginX="10" OriginY="36"
                        Fill="Black"/>
                <TextBlock Grid.Column="1" VerticalAlignment="Center"
                           Text="{Binding Indices, StringFormat=Index {0}}"/>
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Code:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        GlyphItems = new List<object>();

        var font = @"C:\WINDOWS\Fonts\TIMES.TTF";

        for (int i = 0; i < new GlyphTypeface(new Uri(font)).GlyphCount; i++)
        {
            GlyphItems.Add(new { FontUri = font, Indices = i.ToString() });
        }

        DataContext = this;
    }

    public List<object> GlyphItems { get; set; }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top