首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何声明GlyphRun对象?

如何声明GlyphRun对象?
EN

Stack Overflow用户
提问于 2022-07-24 19:55:48
回答 1查看 58关注 0票数 -1

我只需要画几个数字。仅仅定义GlyphRun和FontRenderingEmSize就足够了吗?如果没有,请建议我如何绘制字符串"123“(如何定义GlyphRun对象)。我写了这段代码:

代码语言:javascript
复制
var gr = new GlyphRun();
gr.Characters = new List<char>() { '1', '2' }; //Mistake
gr.FontRenderingEmSize = 20;
var Glyph = new GlyphRunDrawing(Brushes.Black, gr);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-25 07:20:32

我找到了我的一个老帮手班。也许你可以利用它。

代码语言:javascript
复制
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);
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73101580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档