I am trying to get the proper glyphs for a given string with DirectWrite. I am trying to enable the OpenType features for testing, in this case font ligature substitutions. I am using a font that contains the OpenType 'liga' tag has a separate glyph for 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]
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? Or is there another process where this indice becomes the true ligature? Any input is helpful as I am new to this. Thanks