Visio to PNG not using fonts (Linux)

We are using aspose Diagram on Java to convert a VISIO to PDF & PNG on a Linux machine.

As we are using windows fonts so we added the required fonts on the application and are adding them as shown bellow in the code snippet

When running the conversion to PDF on the Linux machine it works fine and is the same as on Windows and we can see that the correct fonts are used.
However when running the same code but converting to PNG the correct fonts are not used and the PNG is different from when the code is running on Windows. Why are the fonts not used when converting to PNG?

InputStream visioStream = new ByteArrayInputStream(visio);
ByteArrayOutputStream image = new ByteArrayOutputStream();
// Call the diagram constructor to load diagram from a VSD file
Diagram diagram = new Diagram(visioStream);
diagram.setFontDirs(fontDirs);
diagram.save(image, SaveFileFormat.PDF);
// diagram.save(image, SaveFileFormat.PNG); → doesnt use the fonts

@ln1

The issue you’re experiencing with font rendering when converting a Visio file to PNG on a Linux machine, while it works correctly for PDF, may be related to how fonts are handled during the image rendering process.

When saving diagrams as images, you can specify additional options using the ImageSaveOptions class. One important property to consider is the setDefaultFont() method. This method allows you to set a default font that will be used when characters in the diagram are Unicode and the correct font is not available or installed locally.

Here’s a code snippet that demonstrates how to set the default font when saving to PNG:

InputStream visioStream = new ByteArrayInputStream(visio);
ByteArrayOutputStream image = new ByteArrayOutputStream(); 
Diagram diagram = new Diagram(visioStream);
diagram.setFontDirs(fontDirs);

// Create ImageSaveOptions and set the default font
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFileFormat.PNG);
saveOptions.setDefaultFont("YourDefaultFontName"); // Set your desired default font

// Save the diagram as PNG
diagram.save(image, saveOptions);

Make sure to replace "YourDefaultFontName" with the name of a font that is available on your Linux system. This should help ensure that the correct fonts are used when generating the PNG image.

If you continue to experience issues, ensure that the fonts you are trying to use are properly installed and accessible in the environment where the conversion is taking place.

For further details on the ImageSaveOptions class and its properties, you can refer to the official documentation.

Sources:
[1]: Class: ImageSaveOptions - Aspose.Diagram for Node.js via Java - API …

Setting the default font to the one that is supposed to be used does not change the PNG output. But why does setting the diagram.setFontDirs(fontDirs); not work for PNG but it does for PDF?

@ln1
Please try this sample code to set font folder before loading visio stream:

   com.aspose.diagram.FontConfigs.setFontFolder("Fonts", false);

or setting font folder in load option

      LoadOptions o = new LoadOptions();
      o.getFontConfigs().setFontFolder("Fonts", false);
      Diagram diagram1 = new Diagram( visioStream, o);

Please refer to the document and we will update the document for java soon:

Thanks.

Thanks for the reply, unfortunately it is still not working as expected, is there anything else I could try?

@ln1
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-51229

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.

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

Hi

We indeed no longer have the wrong fonts used on Linux. So that part is working, thanks!
However, I did notice something else
The generation of the PNG is no longer correct, both on Windows and Linux. We tried different visio and had similar issues. I have attached the png generated with the latest version and the previous one we were using, in the bottom left you can see the issue. Something to note is that when converting to PDF using 24.10 it is still fine and looks like the PNG of the 24.6. Could it be that a bug was introduced in the conversion to PNG?
The code and visio are the same only diff is the version in the pom.

Diagram_v_24_6.jpg (169.6 KB)

Diagram_v24_10.PNG.jpg (122.7 KB)

@ln1
Thank you for your feedback.
Could you please share the sample file that you are using. We will check and assist you accordingly.
Thanks.