[英]How can I declare GlyphRun object?
I need to draw just a couple of digits.我只需要画几个数字。 Is it enough to define only GlyphRun and FontRenderingEmSize?只定义 GlyphRun 和 FontRenderingEmSize 就足够了吗? If not, please, suggest me, how to draw, for example, string "123" (how to define GlyphRun object for that).如果没有,请建议我如何绘制,例如,字符串“123”(如何为此定义 GlyphRun object)。 I wrote this code:我写了这段代码:
var gr = new GlyphRun();
gr.Characters = new List<char>() { '1', '2' }; //Mistake
gr.FontRenderingEmSize = 20;
var Glyph = new GlyphRunDrawing(Brushes.Black, gr);
I found this old helper class of mine.我找到了我的这个老帮手 class。 Maybe you can make use of it.也许你可以利用它。
public static class GlyphRunText
{
public static GlyphRun Create(
string text, Typeface typeface, double emSize, Point baselineOrigin)
{
GlyphTypeface glyphTypeface;
if (!typeface.TryGetGlyphTypeface(out glyphTypeface))
{
throw new ArgumentException(string.Format(
"{0}: no GlyphTypeface found", typeface.FontFamily));
}
var glyphIndices = new ushort[text.Length];
var advanceWidths = new double[text.Length];
for (int i = 0; i < text.Length; i++)
{
var glyphIndex = glyphTypeface.CharacterToGlyphMap[text[i]];
glyphIndices[i] = glyphIndex;
advanceWidths[i] = glyphTypeface.AdvanceWidths[glyphIndex] * emSize;
}
return new GlyphRun(
glyphTypeface, 0, false, emSize,
glyphIndices, baselineOrigin, advanceWidths,
null, null, null, null, null, null);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.