简体   繁体   English

DirectWrite 连字替换功能

[英]DirectWrite ligature substitution feature

I am trying to get the proper glyphs for a given string with DirectWrite.我正在尝试使用 DirectWrite 获取给定字符串的正确字形。 I am trying to enable the OpenType features for testing, in this case font ligature substitutions.我正在尝试启用 OpenType 功能进行测试,在这种情况下是字体连字替换。 I am using a font that contains the OpenType 'liga' tag has a separate glyph for ll.我正在使用一种包含 OpenType 'liga' 标签的字体,它有一个单独的 ll 字形。

Here is my code:这是我的代码:

        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
                          )

However, upon checking the return values it has 5 glyphs total, and the ligature indice is not shown in the glyph indices, just the original two l's: [43, 72, 79, 79, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]但是,在检查返回值时,它总共有 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]

I am not sure if I am understanding it correctly.我不确定我是否理解正确。 Am I incorrect in thinking it would substitute the two l's in the string for the ll glyph?我认为它将用字符串中的两个 l 代替 ll 字形是不正确的吗? Or is there another process where this indice becomes the true ligature?或者是否有另一个过程使这个索引成为真正的连字? Any input is helpful as I am new to this.任何输入都是有帮助的,因为我是新手。 Thanks谢谢

There is a number of things to check:有很多事情需要检查:

  • how 'liga' is defined by the font, which script/language pair is expected for it, what kind of lookup is used;字体如何定义“liga”,预期使用哪种脚本/语言对,使用哪种查找方式;
  • try simple test program using IDirectWriteTextLayout with same font to see if you get this ligature by default.尝试使用具有相同字体的 IDirectWriteTextLayout 的简单测试程序,看看您是否默认获得此连字。 If you do, it means 'liga' is enabled by default and you don't need to specify it as a user feature;如果这样做,则意味着默认启用“liga”,您无需将其指定为用户功能;
  • check you test code in more conventional environment first, like C/C++.首先检查您在更传统的环境中测试代码,例如 C/C++。

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

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