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:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<FontSettings> fontSettings = System::MakeObject<FontSettings>(); | |
System::SharedPtr<TableSubstitutionRule> substitutionRule = fontSettings->get_SubstitutionSettings()->get_TableSubstitution(); | |
// If "UnknownFont1" font family is not available then substitute it by "Comic Sans MS". | |
substitutionRule->AddSubstitutes(u"UnknownFont1", System::MakeArray<System::String>({ u"Comic Sans MS" })); | |
System::SharedPtr<LoadOptions> lo = System::MakeObject<LoadOptions>(); | |
lo->set_FontSettings(fontSettings); | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"MyDocument.docx", lo); |
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:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<FontSettings> fontSettings = System::MakeObject<FontSettings>()->get_DefaultInstance(); | |
fontSettings->SetFontsSources(System::MakeArray<System::SharedPtr<FontSourceBase>>( | |
{ | |
System::MakeObject<SystemFontSource>(), | |
System::MakeObject<FolderFontSource>(u"/home/user/MyFonts", true) | |
})); |
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.