Represents a typed collection of WarningInfo objects.
You can use this collection object as the simplest form of IWarningCallback implementation to gather all warnings that Aspose.Words generates during a load or save operation. Create an instance of this class and assign it to the WarningCallback or WarningCallback property.
- See also
- Aspose::Words::WarningInfo
-
Aspose::Words::IWarningCallback
- Examples
Shows how to set the property for finding the closest match for a missing font from the available font sources.
void EnableFontSubstitution()
{
auto doc = MakeObject<Document>(MyDir + u"Missing font.docx");
auto substitutionWarningHandler = MakeObject<ExFontSettings::HandleDocumentSubstitutionWarnings>();
doc->set_WarningCallback(substitutionWarningHandler);
auto fontSettings = MakeObject<FontSettings>();
fontSettings->get_SubstitutionSettings()->get_DefaultFontSubstitution()->set_DefaultFontName(u"Arial");
;
fontSettings->get_SubstitutionSettings()->get_FontInfoSubstitution()->set_Enabled(true);
doc->set_FontSettings(fontSettings);
doc->Save(ArtifactsDir + u"FontSettings.EnableFontSubstitution.pdf");
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<WarningInfo>>> warnings = substitutionWarningHandler->FontWarnings->GetEnumerator();
while (warnings->MoveNext())
{
std::cout << warnings->get_Current()->get_Description() << std::endl;
}
}
ASSERT_EQ(u"Font '28 Days Later' has not been found. Using 'Calibri' font instead. Reason: alternative name from document.",
substitutionWarningHandler->FontWarnings->idx_get(0)->get_Description());
substitutionWarningHandler->FontWarnings->Clear();
ASSERT_EQ(0, substitutionWarningHandler->FontWarnings->get_Count());
}
class HandleDocumentSubstitutionWarnings : public IWarningCallback
{
public:
SharedPtr<WarningInfoCollection> FontWarnings;
void Warning(SharedPtr<WarningInfo> info)
override
{
{
FontWarnings->Warning(info);
}
}
{
}
};