How is GlyphIndices property encoded in GlyphRun object?
c#, graphics, wpf, xaml
Solution
Use this code to convert a Unicode code point to a glyph index:
GlyphTypeface glyphTypeface = new GlyphTypeface(new Uri(@"C:\WINDOWS\Fonts\TIMES.TTF"));
const char character = 'и';
ushort glyphIndex;
glyphTypeface.CharacterToGlyphMap.TryGetValue(character, out glyphIndex);
MessageBox.Show("Index = " + glyphIndex);
The sample above returns 610 for the Cyrillic и character.
Problem
I am trying to build a `GlyphRun` object, and I can't seem to understand how `GlyphIndices` property is encoded. For example, the following XAML string creates "hello world". It is obvious that the following rules hold: - 43 -> h - 72 -> e - 79 -> l But what is this coding scheme? I tried ASCII and it doesn't seem to fit. Do you have any idea? ``` <GlyphRunDrawing ForegroundBrush="Black"> <GlyphRunDrawing.GlyphRun> <GlyphRun CaretStops="{x:Null}" ClusterMap="{x:Null}" IsSideways="False" GlyphOffsets="{x:Null}" GlyphIndices="43 72 79 79 82 3 58 82 85 79 71" BaselineOrigin="0,12.29" FontRenderingEmSize="13.333333333333334" DeviceFontName="{x:Null}" AdvanceWidths="9.62666666666667 7.41333333333333 2.96 2.96 7.41333333333333 3.70666666666667 12.5866666666667 7.41333333333333 4.44 2.96 7.41333333333333" BidiLevel="0"> <GlyphRun.GlyphTypeface> <GlyphTypeface FontUri="C:\WINDOWS\Fonts\TIMES.TTF" /> </GlyphRun.GlyphTypeface> </GlyphRun> </GlyphRunDrawing.GlyphRun> </GlyphRunDrawing> ```