Completely/Correctly disable font substitution?

Hi,

I’m trying to completely disable the font substitution logic when converting from Word to HTML where elements, specifically EMF images, are converted to SVG.

Since we’re not rendering the elements to raster images, we’d like to ensure the font name is not changed if it doesn’t happen to exist on our server. This would allow converting a Word document to HTML and still display it correctly (as long as the font exists on the user’s machine) with EMFs written out as SVGs.

I’ve tried setting the following font settings for both load and save options, but it always ends up using “Fanwood” ($Layout / FontSubstitution: $Font 'Courier New' has not been found. Using 'Fanwood' font instead. Reason: first available font.):

fontSettings.SubstitutionSettings.DefaultFontSubstitution.Enabled = false;
fontSettings.SubstitutionSettings.FontConfigSubstitution.Enabled = false;
fontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = false;
fontSettings.SubstitutionSettings.FontNameSubstitution.Enabled = false;
fontSettings.SubstitutionSettings.TableSubstitution.Enabled = false;

I also tried forcing AltName in FontInfo, but that did not change the logic:

fontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = true;

var fontInfos = destination.FontInfos;
foreach (var fontInfo in fontInfos) {
    fontInfo.AltName = fontInfo.Name;
}

This is important as our clients often have custom Word templates with corporate defined/puchased fonts which we don’t have access to, but need to convert these documents to HTML (and the fonts exist on our client’s machines, so they would display correctly for them).

Thanks,

//TB

@tomibigpi There are Html (flow format) and HtmlFixed (fixed page format). Aspose.Words does not substitute fonts upon conversion between flow formats so I suspect you are converting to HtmlFixed format. I am afraid, it is not possible to disable font substitution in this case. Upon converting to fixed page formats Aspose.Words needs to measure text and other document items to properly place elements on the page, the process is called Page Layout. The fonts are required to be present when page layout is built to measure and layout text elements.

No, actually we’re not using the fixed format:

HtmlVersion = HtmlVersion.Html5,
SaveFormat = Aspose.Words.SaveFormat.Html,

And related:

MetafileFormat = HtmlMetafileFormat.Svg,

The issue I’m looking at is specifically related to EMFs that get written as SVG elements into the document. They will have their font replaced if it doesn’t exist on the server.

//TB

@tomibigpi Could you please attach your document with EMF file here for testing? I will further investigate the issue and provide you more information.

I’ll need to create a new sample file since the files I can’t share the specific files or any pieces of them. I’ll try to create that sample today. Thanks.

1 Like

I’ve attached a Word document with some repro steps included. I also summarized the warnings I see and the code settings below.
EMF-with-standard-Calibri-font.docx (173.6 KB)

Log output:

$DrawingML / MinorFormattingLoss: $DrawingML is not supported in Html format and will be converted to shape.
$Layout / FontSubstitution: $Font 'Calibri Light' has not been found. Using 'Fanwood' font instead. Reason: first available font.
$Layout / FontSubstitution: $Font 'Calibri' has not been found. Using 'Fanwood' font instead. Reason: first available font.
$Layout / FontSubstitution: $Font 'Microsoft Sans Serif' has not been found. Using 'Fanwood' font instead. Reason: first available font.

HtmlSaveOptions from the codebase:

      var result = new HtmlSaveOptions() {
        ExportGeneratorName = false,
        ExportListLabels = ExportListLabels.AsInlineText,
        ExportHeadersFootersMode = ExportHeadersFootersMode.None,
        ExportRoundtripInformation = true,
        ExportShapesAsSvg = true,
        ExportTextBoxAsSvg = true,
        HtmlVersion = HtmlVersion.Html5,
        MetafileFormat = HtmlMetafileFormat.Svg,
        SaveFormat = Aspose.Words.SaveFormat.Html,
        ScaleImageToShapeSize = true,
      };

FontSettings:

      var fontSettings = new Aspose.Words.Fonts.FontSettings();
      fontSettings.SubstitutionSettings.DefaultFontSubstitution.Enabled = false;
      fontSettings.SubstitutionSettings.FontConfigSubstitution.Enabled = false;
      fontSettings.SubstitutionSettings.FontInfoSubstitution.Enabled = false;
      fontSettings.SubstitutionSettings.FontNameSubstitution.Enabled = false;
      fontSettings.SubstitutionSettings.TableSubstitution.Enabled = false;

@tomibigpi Thank you for additional information. I have logged this as a feature request WORDSNET-23639. We will further investigate the issue and provide you more information.
Also, I have detected incorrect behavior when MetafileFormat is set. The problem is logged as WORDSNET-23638 - metafile is rendered as PNG if ExportShapesAsSvg is not set.

1 Like

The issues you have found earlier (filed as WORDSNET-23638) have been fixed in this Aspose.Words for .NET 22.10 update also available on NuGet.