Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
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.
Fonts are parsed in several steps:
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.
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();
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:
Q: How can I share a single FontSettings instance across multiple documents to improve loading performance?
A: Create one FontSettings object, configure it (e.g., add font sources), and assign it to each Document via Document::set_FontSettings. Because the instance maintains its own cache, subsequent documents will reuse the already‑resolved fonts, reducing the time spent on font parsing.
Q: How do I access and modify the default FontSettings instance in C++?
A: The default instance can be obtained with FontSettings::get_DefaultInstance(). You can then call methods such as AddFontSource or SetSubstitutionSettings on the returned object, and all documents that rely on the default instance will automatically use the updated configuration.
Q: How can I add a custom folder as a font source for FontSettings?
A: Use System::SharedPtr<FolderFontSource> folderSource = System::MakeObject<FolderFontSource>(u"/path/to/fonts", true); and then add it to the settings with fontSettings->AddFontSource(folderSource);. Setting the second parameter to true enables recursive search of sub‑folders.
Q: Is there a way to clear the internal font cache if I change font sources at runtime?
A: Yes. Call fontSettings->ClearCache(); after modifying the font sources. This forces Aspose.Words to re‑scan the sources the next time a document requests a font, ensuring the new fonts are taken into account.
Q: How does FontSettings affect font substitution, and can I control which fonts are used as substitutes?
A: FontSettings performs substitution based on the resolved font’s full name, family name, style, etc. You can customize substitution rules via fontSettings->get_SubstitutionSettings()->AddSubstitutes(u"Arial", System::MakeArray<System::String>({ u"Helvetica", u"FreeSans" }));. This tells Aspose.Words to prefer the listed fonts when the original font is unavailable.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.