default_instance property

FontSettings.default_instance property

Static default font settings.

@property
def default_instance(self) -> aspose.words.fonts.FontSettings:
    ...

Remarks

This instance is used by default in a document unless Document.font_settings is specified.

Examples

Shows how to configure the default font settings instance.

# Configure the default font settings instance to use the "Courier New" font
# as a backup substitute when we attempt to use an unknown font.
aw.fonts.FontSettings.default_instance.substitution_settings.default_font_substitution.default_font_name = 'Courier New'
self.assertTrue(aw.fonts.FontSettings.default_instance.substitution_settings.default_font_substitution.enabled)
doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.font.name = 'Non-existent font'
builder.write('Hello world!')
# This document does not have a FontSettings configuration. When we render the document,
# the default FontSettings instance will resolve the missing font.
# Aspose.Words will use "Courier New" to render text that uses the unknown font.
self.assertIsNone(doc.font_settings)
doc.save(file_name=ARTIFACTS_DIR + 'FontSettings.DefaultFontInstance.pdf')

Shows how to use the IWarningCallback interface to monitor font substitution warnings.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.font.name = 'Times New Roman'
builder.writeln('Hello world!')
callback = self.FontSubstitutionWarningCollector()
doc.warning_callback = callback
# Store the current collection of font sources, which will be the default font source for every document
# for which we do not specify a different font source.
original_font_sources = aw.fonts.FontSettings.default_instance.get_fonts_sources()
# For testing purposes, we will set Aspose.Words to look for fonts only in a folder that does not exist.
aw.fonts.FontSettings.default_instance.set_fonts_folder('', False)
# When rendering the document, there will be no place to find the "Times New Roman" font.
# This will cause a font substitution warning, which our callback will detect.
doc.save(file_name=ARTIFACTS_DIR + 'FontSettings.SubstitutionWarning.pdf')
aw.fonts.FontSettings.default_instance.set_fonts_sources(sources=original_font_sources)
self.assertEqual(1, callback.font_substitution_warnings.count)
self.assertTrue(callback.font_substitution_warnings[0].warning_type == aw.WarningType.FONT_SUBSTITUTION)
self.assertTrue(callback.font_substitution_warnings[0].description == "Font 'Times New Roman' has not been found. Using 'Fanwood' font instead. Reason: first available font.")

Shows how to use the IWarningCallback interface to monitor font substitution warnings (FontSubstitutionWarningCollector).

class FontSubstitutionWarningCollector(aw.IWarningCallback):

    def __init__(self):
        self.font_substitution_warnings = aw.WarningInfoCollection()

    def warning(self, info):
        if info.warning_type == aw.WarningType.FONT_SUBSTITUTION:
            self.font_substitution_warnings.warning(info)

See Also