FontSubstitutionSettings class

FontSubstitutionSettings class

Specifies font substitution mechanism settings. To learn more, visit the Working with Fonts documentation article.


Font substitution process consists of several rules which are checked one by one in specific order. If the first rule can’t resolve the font then second rule is checked and so on.

The order of the rules is following:

  1. Font name substitution rule (enabled by default)
  2. Font config substitution rule (disabled by default)
  3. Table substitution rule (enabled by default)
  4. Font info substitution rule (enabled by default)
  5. Default font rule (enabled by default)

Note that font info substitution rule will always resolve the font if FontInfo is available and will override the default font rule. If you want to use the default font rule then you should disable the font info substitution rule.

Note that font config substitution rule will resolve the font in most cases and thus overrides all other rules.


default_font_substitutionSettings related to default font substitution rule.
font_config_substitutionSettings related to font config substitution rule.
font_info_substitutionSettings related to font info substitution rule.
font_name_substitutionSettings related to font name substitution rule.
table_substitutionSettings related to table substitution rule.


Shows how to access a document’s system font source and set font substitutes.

doc = aw.Document()
doc.font_settings = aw.fonts.FontSettings()

# By default, a blank document always contains a system font source.
self.assertEqual(1, len(doc.font_settings.get_fonts_sources()))

system_font_source = doc.font_settings.get_fonts_sources()[0]
self.assertEqual(aw.fonts.FontSourceType.SYSTEM_FONTS, system_font_source.type)
self.assertEqual(0, system_font_source.priority)

if platform.system() == "Windows":
    fonts_path = "C:\\WINDOWS\\Fonts"
    self.assertEqual(fonts_path.lower(), aw.fonts.SystemFontSource.get_system_font_folders()[0].lower())

for system_font_folder in aw.fonts.SystemFontSource.get_system_font_folders():


# Set a font that exists in the Windows Fonts directory as a substitute for one that does not.
doc.font_settings.substitution_settings.font_info_substitution.enabled = True
doc.font_settings.substitution_settings.table_substitution.add_substitutes("Kreon-Regular", ["Calibri"])

self.assertEqual(1, len(list(doc.font_settings.substitution_settings.table_substitution.get_substitutes("Kreon-Regular"))))
self.assertIn("Calibri", list(doc.font_settings.substitution_settings.table_substitution.get_substitutes("Kreon-Regular")))

# Alternatively, we could add a folder font source in which the corresponding folder contains the font.
folder_font_source = aw.fonts.FolderFontSource(FONTS_DIR, False)
doc.font_settings.set_fonts_sources([system_font_source, folder_font_source])
self.assertEqual(2, len(doc.font_settings.get_fonts_sources()))

# Resetting the font sources still leaves us with the system font source as well as our substitutes.

self.assertEqual(1, len(doc.font_settings.get_fonts_sources()))
self.assertEqual(aw.fonts.FontSourceType.SYSTEM_FONTS, doc.font_settings.get_fonts_sources()[0].type)
self.assertEqual(1, len(list(doc.font_settings.substitution_settings.table_substitution.get_substitutes("Kreon-Regular"))))

See Also