Hello,
Is there any way to know that a font was substituted to its mapped font provided through IFontSubstRuleCollection
using below code:
slidesFontSettings = new FontSubstRuleCollection();
IFontSubstRule fontSubstituteRule = new FontSubstRule(new FontData(entry.getKey()), new FontData(entry.getValue()), FontSubstCondition.WhenInaccessible);
slidesFontSettings.add(fontSubstituteRule);
Can we know that a the given font was substituted?
@aakanksha76
To determine if a font was substituted when using the IFontSubstRuleCollection
in Aspose.Slides, you can utilize the GetSubstitutions
method from the FontsManager
class. This method provides information about the fonts that will be replaced during the rendering process.
Here’s how you can implement this:
- Set up your font substitution rules using the
IFontSubstRuleCollection
.
- Load your presentation.
- Call the
GetSubstitutions
method to retrieve a collection of font substitution information.
Here’s a sample code snippet demonstrating this process:
using Aspose.Slides;
using Aspose.Slides.FontsManager;
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// Create a font substitution rule collection
FontSubstRuleCollection slidesFontSettings = new FontSubstRuleCollection();
// Example substitution map
Dictionary<string, string> substituteFontMap = new Dictionary<string, string>
{
{ "OriginalFont", "SubstitutedFont" }
};
// Add font substitution rules
foreach (var entry in substituteFontMap)
{
IFontSubstRule fontSubstituteRule = new FontSubstRule(new FontData(entry.Key),
new FontData(entry.Value), FontSubstCondition.WhenInaccessible);
slidesFontSettings.Add(fontSubstituteRule);
}
// Load the presentation
using (Presentation presentation = new Presentation("example.pptx"))
{
// Apply font settings
presentation.FontsManager.SetFontSubstitutionRules(slidesFontSettings);
// Get font substitutions
IEnumerable<FontSubstitutionInfo> substitutions = presentation.FontsManager.GetSubstitutions();
// Display the substitutions
foreach (FontSubstitutionInfo substitution in substitutions)
{
Console.WriteLine($"Original Font: {substitution.OriginalFontName} -> Substituted Font: {substitution.SubstitutedFontName}");
}
}
}
}
In this example, after setting up your font substitution rules and loading the presentation, you can call GetSubstitutions()
to retrieve a list of any fonts that were substituted. Each FontSubstitutionInfo
object in the returned collection contains the original font name and the name of the font that was substituted in its place. This allows you to confirm whether a substitution occurred and to log or handle it as needed.
For more detailed information, you can refer to the official Aspose documentation on font substitutions and getting warning callbacks for font substitutions.
Sources:
[1]: GetSubstitutions | Aspose.Slides for .NET API Reference
[2]: Getting Warning Callbacks for Fonts Substitution in Aspose.Slides
Hi,
Can we also know the Font-size of the Substitution font that will be used in place of original font?
@aakanksha76,
I need some time to answer your questions. I will get back to you as soon as possible.
@aakanksha76,
Thank you for your patience. Unfortunately, I was unable to meet your requirements with Aspose.Slides.
We have opened the following new ticket(s) in our internal issue tracking system and will consider your requirements according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESJAVA-39681
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@aakanksha76,
Our developers have thoroughly studied your requirements.
Because the replacement was initiated by the user, no notification is displayed. A notification for FontSubstRule will, however, be shown if the substituted font cannot be found.
An example:
FontData sourceFont = new FontData("Raven Script");
FontData targetFont = new FontData("Raven Script TEST");
FontSubstRule substRule = new FontSubstRule(
sourceFont, targetFont, FontSubstCondition.WhenInaccessible);
presentation.getFontsManager().getFontSubstRuleList().add(substRule);
Since “Raven Script TEST” is missing, this font will be automatically replaced:
Font will be substituted from Raven Script TEST to {Calibri,Cambria Math,MS Gothic,Gulim,Arial Unicode,SimSun,Segoe UI Symbol}
Getting Warning Callbacks for Fonts Substitution in Aspose.Slides|Aspose.Slides Documentation
IWarningCallback | Aspose.Slides for Java API Reference
If your concern is text size, replacing the font doesn’t change it, since text size is tied to each text portion rather than to the font itself.
If you are asking about the font file’s size, Aspose.Slides doesn’t provide that information.
Okay,
thank you for the explanation.
@aakanksha76,
Thank you for using Aspose.Slides for Java.