Font Manipulation and Performance Issues

All available font manipulation mechanisms are contained in the FontSettings class. This class is responsible for fetching fonts within defined font sources as well as for the Font Substitution process, as described below.

Parsing the Resolved Fonts

Fonts are parsed in several steps:

  1. Obtaining info for font, resolving from all available fonts.
  2. Parsing the resolved fonts to get available glyphs and metrics (horizontal and vertical).
  3. Parsing the resolved fonts for embedding and subsetting.

When Aspose.Words encounters a font in the document for the first time, it attempts to obtain basic font information, such as the font full name, family name, version, style, from the font files located in each font source. After all the fonts are retrieved, Aspose.Words uses these details to find the required font data or a suitable replacement for the requested font.

Performance Issue When Replacing Fonts

Since the procedure described above is time-consuming, it may negatively affect application performance at its first launch. However, each instance of FontSettings has its own cache, which could reduce the processing time of subsequent documents. For example, you can share an instance of the FontSettings class between different documents, which allows you to speed up the loading of the documents. The following example demonstrates this:

In the case when FontSettings is not defined explicitly, Aspose.Words uses the default FontSettings instance. This instance is also automatically shared among documents, and can be extracted as follows:

C++

System::SharedPtr<FontSettings> fontSettings = System::MakeObject<FontSettings>()->get_DefaultInstance();

Using the Default FontSettings Instance

If you are sure that all processing documents require the same font settings, then it is recommended to set up and utilize the default FontSettings instance. Suppose that you need to use the same font sources for all your documents. In this case, you can just amend the default instance as follows: