c# - 如何在 Directwrite 中获取给定字体的可用 OpenType 功能?

标签 c# c++ directx sharpdx directwrite

我构建了一个文本编辑器并使用 DirectWrite,我想为用户提供在所选文本上启用 OpenType 功能 的选项,但并非每种字体都具有功能和许多字体根本没有。我的问题是如何知道使用 DirectWrite 的给定字体有哪些 OpenType 功能可用?

我已经尝试了下面的代码,但是 res 总是 == S_OK 即使是字体也缺少这个特性:

DWRITE_FONT_FEATURE fontFeature = { DWRITE_FONT_FEATURE_TAG_STYLISTIC_SET_7, 1 };
HRESULT res = pTypography->AddFontFeature(fontFeature);      // res == S_OK
res = g_pFancyTextLayout->SetTypography(pTypography, range); // res == S_OK

更新:

我已经用 SharpDx 尝试了以下代码,但是 list 总是空的,即使是 Gabriola 字体:

    public static FontFeatureTag[] GetOpenTypeFeatures(FontFace fontFace)
    {
        var list = new List<FontFeatureTag>();

        foreach (FontFeatureTag tag in System.Enum.GetValues(typeof(FontFeatureTag)))
        {
            if (fontFace.TryGetFontTable((int)tag, out DataPointer dataPointer, out IntPtr intPtr))
            {
                list.Add(tag);
            }
        }

        return list.ToArray();
    }

我正在使用 SharpDX 编写 C# 应用程序,但是我可以理解 C++ 中提供的答案/示例。

最佳答案

在深入搜索 Microsoft 关于 DirectWirte 的文档后,我设法通过使用 TextAnalyzer2 找到了预期的接口(interface)。

请注意,DirectWrite 为每个新的 TextAnalyzer 添加了新功能和成员。它从 TextAnalyzer 开始,然后是 TextAnalyzer1 和 TextAnalyzer2。 [您会在 DirectWrite 的其他接口(interface)上发现相同的演变]。

所以这里是:IDWriteTextAnalyzer2::GetTypographicFeatures

Use the IDWriteTextAnalyzer2 interface - can be found here. Using the GetTypographicFeatures that"Returns a complete list of OpenType features available for a script or font".

关于c# - 如何在 Directwrite 中获取给定字体的可用 OpenType 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53053966/

相关文章:

c# - 将 C# 代码翻译成 AST?

javascript - 编码 UI - C# - ExecuteScript - 计数未正确返回值

c++ - 使用智能指针设计两个相互引用的类

c++ - 使用 delphi 调用 dll - pcshll32.dll

c++ - Direct 2D 在内存中留下指针吗?

c# - 使用 Windows 服务执行的子进程中的 DirectX

c# - 如何从 .NET 发布到 Facebook 页面墙

javascript - 如何使用 javascript 更改 href 属性?

c++ - 我的基地在哪里创建?

2d - Skia vs Cairo vs Direct2D,哪个功能最丰富?