GlyphIndices属性如何在GlyphRun对象中编码?

And*_*ein 3 c# wpf graphics xaml

我正在尝试构建一个GlyphRun对象,我似乎无法理解GlyphIndices属性是如何编码的.

例如,以下 XAML字符串创建"hello world".很明显,以下规则适用:

  • 43 - > h
  • 72 - > e
  • 79 - > l

但这个编码方案是什么?我试过ASCII,它似乎不合适.

你有什么主意吗?


<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>
Run Code Online (Sandbox Code Playgroud)

小智 5

使用此代码将Unicode代码点转换为字形索引:

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);
Run Code Online (Sandbox Code Playgroud)

上面的示例为西里尔字符返回610.