【问题标题】:How get available OpenType features for given font in Directwrite?如何在 Directwrite 中为给定字体获取可用的 OpenType 功能?
【发布时间】:2019-04-02 21:13:54
【问题描述】:

我构建了一个文本编辑器并使用DirectWrite,我想让用户选择在选定的文本上启用OpenType features,但并非每种字体都具有所有功能,而且许多字体根本没有。我的问题是如何知道使用 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++ 中提供的答案/示例。

【问题讨论】:

    标签: c# c++ directx sharpdx directwrite


    【解决方案1】:

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

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

    所以这里是:IDWriteTextAnalyzer2::GetTypographicFeatures

    使用 IDWriteTextAnalyzer2 接口 - 可以找到 here。使用“返回可用于脚本或字体的 OpenType 功能的完整列表”的GetTypographicFeatures

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2022-06-14
      • 2019-09-06
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      • 2010-11-15
      • 2019-06-12
      相关资源
      最近更新 更多