我正在尝试使用 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 字形是不正确的吗?或者是否有另一个过程使这个索引成为真正的连字?任何输入都是有帮助的,因为我是新手。谢谢