Font Substitution
Contents
[
Hide
]
Aspose.Slides allows you to set rules for fonts that determines what must be done in certain conditions (for example, when a font cannot be accessed) this way:
- Load the relevant presentation.
- Load the font that will be replaced.
- Load the new font.
- Add a rule for the replacement.
- Add the rule to the presentation font replacement rule collection.
- Generate the slide image to observe the effect.
This C++ code demonstrates the font substitution process:
// The path to the documents directory.
const String outPath = u"../out/RuleBasedFontsReplacement_out.pptx";
const String templatePath = u"../templates/DefaultFonts.pptx";
// Loads a presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);
// Defines the font that will be replaced and the new font
SharedPtr<IFontData> sourceFont = MakeObject<FontData>(u"SomeRareFont");
SharedPtr<IFontData> destFont = MakeObject<FontData>(u"Arial");
// Adds a font rule for font replacement
SharedPtr<FontSubstRule> fontSubstRule = MakeObject<FontSubstRule>(sourceFont, destFont, FontSubstCondition::WhenInaccessible);
// Adds the rule to font substitute rules collection
SharedPtr<FontSubstRuleCollection> fontSubstRuleCollection = MakeObject<FontSubstRuleCollection>();
fontSubstRuleCollection->Add(fontSubstRule);
// Adds the font rule collection to the rule list
pres->get_FontsManager()->set_FontSubstRuleList ( fontSubstRuleCollection);
// Saves PPTX to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);