经过一些研究,我刚刚发现了你的问题。
使用公共构造函数创建的 GlyphRun 创建对象TextFormattingMode = Ideal
所有用于渲染的 WPF 控件都使用接受 TextFormattingMode 作为参数的方法/构造函数。
GlyphRun.TryCreate()
您可以通过反射调用静态方法:
internal static GlyphRun TryCreate(
GlyphTypeface glyphTypeface,
int bidiLevel,
bool isSideways,
double renderingEmSize,
IList<ushort> glyphIndices,
Point baselineOrigin,
IList<double> advanceWidths,
IList<Point> glyphOffsets,
IList<char> characters,
string deviceFontName,
IList<ushort> clusterMap,
IList<bool> caretStops,
XmlLanguage language,
TextFormattingMode textLayout
)
但是你需要解决的advanceWidths
问题TextFormattingMode = Ideal
。为此,您需要通过反射访问GlyphTypeface
类提供的内部方法。
GlyphTypeface.AdvanceWidths
返回具有这些宽度的字典的属性在内部调用
internal double GetAdvanceWidth(ushort glyph, TextFormattingMode textFormattingMode, bool isSideways)
当您通过索引访问字典时textFormattingMode = TextFormattingMode.Ideal
您可以下载 .Net 源代码并自行检查。
至于你的第二个问题,我认为你使用字符而不是 unicode 代码点来获取字形索引。