直接写入连字替换功能



我正在尝试使用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++(中测试代码。

相关内容

  • 没有找到相关文章

最新更新