Unable to detect installed TrueType fonts during conversion

Dear Support Team,

I was testing the conversion of multiple document formats to PDF (including DOCX, PPTX, VSDX, and XLSX) using custom fonts installed on my system. According to the documentation, Aspose libraries such as Aspose.Words, Aspose.Diagram, Aspose.Cells, and Aspose.Slides utilize TrueType fonts installed in Windows (typically located in C:\Windows\Fonts).

However, during testing, I encountered an issue with Aspose.Diagram. Despite the custom fonts being installed directly in the C:\Windows\Fonts folder and working fine with the other APIs (e.g., Aspose.Words, Aspose.Cells, and Aspose.Slides), Aspose.Diagram raises a WarningCallback with the following message:

Font substitution warning: Font substitution: Font [Uniform Pro Ivoclar Lgt] has been substituted by Font [Times New Roman]

This happens even though the custom fonts are installed correctly and are accessible by the other Aspose libraries.

Here is the code snippet I used for testing:

private void processDocument(Task task) throws Exception {
    String input = TaskFilesHelper.readLastEntryFromCommands(task, "INPUT");
    String output = TaskFilesHelper.readLastEntryFromCommands(task, "OUTPUT");

    Diagram diagram = new Diagram(input);

    PdfSaveOptions pso = new PdfSaveOptions();
    pso.setWarningCallback(new FontWarningCallback());

    try {
        diagram.save(output, pso);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        diagram.dispose();
    }
}

Could you please let me know if there is a way to resolve this issue without explicitly specifying the font folder using diagram.setFontDirs(*font dirs*)?

Thank you in advance for your assistance!

@grigonaz

It seems you are encountering a font substitution warning when using Aspose.Diagram, even though your custom fonts are installed correctly on your system. This issue can arise when the Aspose.Diagram library is unable to locate or access the specified fonts, leading it to substitute them with a default font like Times New Roman.

To address this issue without explicitly specifying the font directory using diagram.setFontDirs(*font dirs*), you can implement a custom warning callback to handle font substitution warnings. This allows you to log or manage the warnings as needed. Here’s a code snippet that demonstrates how to set up a custom warning callback:

import com.aspose.diagram.Diagram;
import com.aspose.diagram.IWarningCallback;
import com.aspose.diagram.WarningInfo;
import com.aspose.diagram.WarningType;

public class FontWarningCallback implements IWarningCallback {
    @Override
    public void warning(WarningInfo warningInfo) {
        if (warningInfo.getWarningType() == WarningType.FontSubstitution) {
            System.out.println("Font substitution warning: " + warningInfo.getDescription());
        }
    }
}

public class DocumentProcessor {
    public void processDocument(String input, String output) throws Exception {
        Diagram diagram = new Diagram(input);
        
        PdfSaveOptions saveOptions = new PdfSaveOptions();
        saveOptions.setWarningCallback(new FontWarningCallback());

        try {
            diagram.save(output, saveOptions);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            diagram.dispose();
        }
    }
}

In this example, the FontWarningCallback class implements the IWarningCallback interface, allowing you to capture and handle font substitution warnings. You can modify the callback to take additional actions if necessary.

If the issue persists, you may want to ensure that the font files are not only installed but also accessible by the Aspose.Diagram library. Sometimes, permissions or other system settings can affect font accessibility.

For further assistance, you might want to check the official documentation or examples related to handling missing fonts in Aspose.Diagram, which can provide additional insights into resolving font-related issues.

Sources:
[1]: Notification of Missing Fonts (C#)
[2]: Notification of Missing Fonts (Java)

Thank you for your response.

However, as I mentioned in my original ticket, there are no issues with custom fonts when using other Aspose libraries. Therefore, I wanted to ask if this behavior in Aspose.Diagram might be due to a bug, or if there are any additional code settings required to enable the library to detect TrueType fonts installed in the Windows C:\Windows\Fonts folder?

Looking forward to your clarification!

@grigonaz
On the Windows system, we typically check the fonts in the C:\Windows\Fonts directory by default.
Could you please share the sample visio file with the font,we will check it soon.

Please try this code to set font folder

  com.aspose.diagram.FontConfigs.setFontFolder("c:\\windows\\Fonts\\", false);

Thanks.

@grigonaz
When installing fonts on Windows, in addition to the system font directory, they may also be installed in other directories, such as the user font directory.
We plan to default to loading some other common font directories on Windows in the next version 24.12.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): DIAGRAMJAVA-51246

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.

@philip.zhou
Thank you for your prompt response!

I attempted to use the following methods for setting font directories:

com.aspose.diagram.FontConfigs.setFontFolder("C:/Windows/Fonts/", false);

and

String[] fonts = new String[] {"C:/Windows/Fonts/"};
Diagram diagram = new Diagram(input);
diagram.setFontDirs(fonts);

Unfortunately, neither method works, even though the fonts are installed directly in C:\Windows\Fonts\ directly (see screenshot): fonts_screenshot.png (48.1 KB)

However, if I change the folder path in the second method to a custom folder containing these fonts, it works correctly:

String[] fonts = new String[] {"C:\Users\ixtadmin\Desktop\ivo"};
Diagram diagram = new Diagram(input);
diagram.setFontDirs(fonts);

I also mentioned that for other Aspose libraries, fonts installed directly in C:\Windows\Fonts\ work perfectly without any issues, and without the need to manually specify the folder path. It seems that Aspose.Diagram is unable to locate any custom fonts specifically in the C:\Windows\Fonts\ folder.

Could you please help clarify why this might be happening? Thanks!

@grigonaz
Please right-click the font file, check its specific location, and see if it is in C:\Windows\Fonts.

We will default to loading common font directories in the next version.
Thanks.

1 Like

The issues you have found earlier (filed as DIAGRAMJAVA-51246) have been fixed in this update. This message was posted using Bugs notification tool by philip.zhou

1 Like