Setting Default Font as replacement to missing fonts seems not working

I set “FontSettings.DefaultInstance.SubstitutionSettings.DefaultFontSubstitution.DefaultFontName” to “Calibri” but the texts that are using fonts that don’t exists in the system is still using Times New Roman. For example those that uses Gotham Book and Helvetica. I’m using the Nuget package version 22.7.0. Thanks!

I tried to override the Document’s FontSettings using this one as reference but I still get the warning that the font was replaced with Times New Roman despite of using Calibri, Courier New, and Arial. And those fonts are in the directory and can be detected:

var fonts = fontSettings.GetFontsSources().SelectMany(fs => fs.GetAvailableFonts());

I tried to query the fonts through Immediatet Window and I can say that Calibri is in there:

fonts.Where(s => s.FontFamilyName == "Calibri").ElementAt(0)
{Aspose.Words.Fonts.PhysicalFontInfo}
    FilePath: "resources/fonts/calibri.ttf"
    FontFamilyName: "Calibri"
    FullFontName: "Calibri"
    Version: "Version 6.23"

@virgilio.dolosa.rivtech Aspose.Words applies set of fonts substitution rules when fonts specified in the document are not available. DefaultFontSubstitution is not the first rule that is applied. You can disable applying other substitution rules to make only DefaultFontSubstitution to be applied. For example the following code disables table substitution rule:

fontSettings.SubstitutionSettings.TableSubstitution.Enabled = false;

If you implement IWarningCallback, in the warning you can see what font substitution rule has been applied.

I see, so you have a table of fonts and possible substitution for them instead of pointing to a single font only. So if I turn it off for the meantime, it should use the specified font I set?

We are replacing MS Word interop and want this replacement’s result as close as possible. Do you have a cheat-sheet or way to emulate Microsoft Word in substituting fonts? Thanks!

@virgilio.dolosa.rivtech Not only table substitution. If Aspose.Words cannot locate the font specified in the document it applies several substitution rules:

  1. First, Aspose.Words tries to process the font name to get the substitution, particularly it tries to remove suffixes with “-” and “,” separators.
  2. Then Aspose.Words attempts to apply OS font settings, if they are available, by using the FontConfig utility.
  3. The next step uses a simple but powerful mechanism called Table substitution rule.
  4. The FontInfo substitution rule will be applied if the table substitution rule cannot find the font.
  5. DefaultFont substitution rule will be applied in the case when the FontInfo substitution has also failed.

See the documentation for more information.

You do not need to perform additional actions to mimic MS Word behavior. Aspose.Words font substitution rules emulates MS Word behavior.
Also, you can adjust Table substitution rules to fit your needs.

Using Interop, the conversion is using Calibri as substitution to most of the missing fonts. But in Aspose.Word, those fonts were substituted with Times New Roman instead by default.

@virgilio.dolosa.rivtech Could you please attach the problematic document along with current and expected output documents here for testing? We will check the issue and provide you more information.
Also, could you please check whether the behavior is the same on your side if you convert your document using MS Word UI?

I want to but those are company documents.

@virgilio.dolosa.rivtech You can remove or replace sensitive data in your documents or create a dummy document that will allow us to reproduce the problem. Also, please note, it is safe to attach documents in the forum, only you and Aspose staff can download them.

I modified the document and removed some possible sensitive data. You will notice that the first paragraphs in the body are using Gotham Book font.
Welcome Letter - modified.docx (19.1 KB)

@virgilio.dolosa.rivtech I was managed to reproduce your issue with inaccurate font substitution for “Gotham Book” font in Aspose.Words on my side. I have logged it as WORDSNET-24121 in our defect tracking system. We will keep you informed and let you know once it is resolved.