我正在尝试使用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字形,这是不是错了?或者,有没有另一个过程,这个指头变成了真正的结扎?任何输入都是有帮助的,因为我是新手。谢谢
发布于 2020-07-07 19:48:59
有许多事情需要检查:
https://stackoverflow.com/questions/62766214
复制相似问题