簡體   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