Getting Warning Callbacks for Fonts Substitution in Aspose.Slides
Contents
[
Hide
]
Aspose.Slides for C++ makes it possible to get warning callbacks for fonts substitution in case the used font is not available on a machine during the rendering process. The warning callbacks are helpful when debugging issues of missing or inaccessible fonts during the rendering process.
Getting Warning Callbacks for Fonts substitution
Aspose.Slides for C++ provides a simple API methods to get the Warning Callbacks during the rendering process. All you need is to follow the steps below to configure the Warning Callbacks on your end:
- Create a custom Callback class to receive the callbacks.
- Set the Warning Callbacks using LoadOptions class.
- Load the presentation file that is using a font for text inside that is unavailable on your target machine.
- Generate the slide thumbnail to see the effect.
class HandleFontsWarnings : public Warnings::IWarningCallback
{
public:
Warnings::ReturnAction Warning(SharedPtr<Warnings::IWarningInfo> warning) override
{
if (warning->get_WarningType() == Warnings::WarningType::CompatibilityIssue)
{
return Warnings::ReturnAction::Continue;
}
// 1 - WarningType.DataLoss
Console::WriteLine(System::ObjectExt::ToString(warning->get_WarningType()));
// "Font will be substituted from X to Y"
Console::WriteLine(warning->get_Description());
return Warnings::ReturnAction::Continue;
}
};
void Run()
{
System::String dataDir = GetDataPath();
// Setting Warning Callbacks
System::SharedPtr<LoadOptions> options = System::MakeObject<LoadOptions>();
options->set_WarningCallback(System::MakeObject<HandleFontsWarnings>());
// Instantiate the presentation
System::SharedPtr<Presentation> presentation = System::MakeObject<Presentation>(dataDir + u"presentation.pptx", options);
// Generating slide thumbnails
for (auto slide : presentation->get_Slides())
{
System::SharedPtr<IImage> image = slide->GetImage();
}
}