首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DrawingContext DrawGlyphRun模糊文本

DrawingContext DrawGlyphRun模糊文本
EN

Stack Overflow用户
提问于 2017-01-04 15:03:03
回答 1查看 746关注 0票数 1

我使用DrawingContext DrawGlyphRun(GlyphRun)函数在画布中使用https://smellegantcode.wordpress.com/2008/07/03/glyphrun-and-so-forth/的解决方案绘制文本。

我在FormattedText上使用它,因为它更快,也用于计算文本宽度。

除了两个问题外,这个方法效果很好:

  1. 文本是模糊的(见下图)。顶部的文本使用GlyphRun显示。底层文本使用FormattedText显示,具有较好的质量。

  1. 不能显示日文或汉字。

字符的问题似乎是GlyphTypeface.CharacterToGlyphMap找不到jp或cn字符,所以我不知道如何准确地处理这些字符。

EN

回答 1

Stack Overflow用户

发布于 2017-03-31 07:38:42

我在做了些调查之后才发现你的问题。

使用公共构造函数创建的GlyphRun使用TextFormattingMode = Ideal创建对象

所有的WPF控件对于其rendring都使用接受TextFormattingMode作为参数的方法/构造函数。

您可以通过反射调用GlyphRun.TryCreate()静态方法:

代码语言:javascript
复制
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属性

代码语言:javascript
复制
internal double GetAdvanceWidth(ushort glyph, TextFormattingMode textFormattingMode, bool isSideways)

使用textFormattingMode = TextFormattingMode.Ideal按索引访问字典时

您可以下载.Net源代码并亲自检查它。

至于您的第二个问题,我认为您使用字符而不是unicode代码点来获取字形索引。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41466938

复制
相关文章

相似问题

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