繁体   English   中英

DirectWrite 连字替换功能

[英]DirectWrite ligature substitution feature

我正在尝试使用 DirectWrite 获取给定字符串的正确字形。 我正在尝试启用 OpenType 功能进行测试,在这种情况下是字体连字替换。 我正在使用一种包含 OpenType 'liga' 标签的字体,它有一个单独的 ll 字形。

这是我的代码:

        text = 'Hello'

        analyze = IDWriteTextAnalyzer()
        self.font.write_factory.CreateTextAnalyzer(byref(analyze))

        tags = [DWRITE_FONT_FEATURE_TAG_STANDARD_LIGATURES]

        num_feature = len(tags)
        if num_feature:
            typo_features = DWRITE_TYPOGRAPHIC_FEATURES()
            typo_features.featureCount = num_feature

            typo_features.features = (DWRITE_FONT_FEATURE * num_feature)()
            for i in range(num_feature):
                typo_features.features[i] = DWRITE_FONT_FEATURE(tags[i], 1)

            feature_range = (UINT32 * num_feature)(len(text))
        else:
            typo_features = None
            feature_range = None

        max_count = int(3 * len(text) / 2 + 16)

        length = len(text)
        clusters = (UINT16 * length)()
        text_props = (DWRITE_SHAPING_TEXT_PROPERTIES * length)()
        indices = (UINT16 * max_count)()
        glyph_props = (DWRITE_SHAPING_GLYPH_PROPERTIES * max_count)()
        actual_count = UINT32()

        analyze.GetGlyphs(text,
                          len(text),
                          self.font.font_face,
                          False,  # sideways
                          False,  # righttoleft
                          script,  # scriptAnalysis
                          None,  # localName
                          None,  # numberSub
                          typo_features,  # typo features
                          feature_range,  # feature range
                          1,  # count
                          max_count,
                          clusters, # cluster map
                          text_props, # text props
                          indices, # glyph indices
                          glyph_props, #glyph pops
                          byref(actual_count)#glyph count
                          )

但是,在检查返回值时,它总共有 5 个字形,并且在字形索引中没有显示连字索引,只有原始的两个 l: [43, 72, 79, 79, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

我不确定我是否理解正确。 我认为它将用字符串中的两个 l 代替 ll 字形是不正确的吗? 或者是否有另一个过程使这个索引成为真正的连字? 任何输入都是有帮助的,因为我是新手。 谢谢

有很多事情需要检查:

  • 字体如何定义“liga”,预期使用哪种脚本/语言对,使用哪种查找方式;
  • 尝试使用具有相同字体的 IDirectWriteTextLayout 的简单测试程序,看看您是否默认获得此连字。 如果这样做,则意味着默认启用“liga”,您无需将其指定为用户功能;
  • 首先检查您在更传统的环境中测试代码,例如 C/C++。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM