FontConfigSubstitutionRule.isFontConfigAvailable() returns false on linux

Hi,

I think I discovered a bug in Aspose Words for Java, affecting the newest version 23.12 and several older versions, for which I could not find any other threads in this forum:

FontConfigSubstitutionRule.isFontConfigAvailable() returns false on linux systems, although Font-Config, especially fc-match, is available. In consequence, this leads to Aspose Words for Java ignoring all font subsitutions known to Font-Config / fc-match.

My actual use case is converting user supplied DOCX files to PDF using com.aspose.words.Document#save(java.io.OutputStream, int). Due to this bug the resulting PDF files use inappropriate fonts and therefore are displayed incorrectly.

This issue is reproducible with the sample code supplied in Aspose Words for Java’s javadocs: The javadoc of FontConfigSubstitutionRule provides the following code sample:

FontSettings fontSettings = new FontSettings();
FontConfigSubstitutionRule fontConfigSubstitution = fontSettings.getSubstitutionSettings().getFontConfigSubstitution();

// The FontConfigSubstitutionRule object works differently on Windows/non-Windows platforms.
// On Windows, it is unavailable.
if (SystemUtils.IS_OS_WINDOWS) {
    Assert.assertFalse(fontConfigSubstitution.getEnabled());
    Assert.assertFalse(fontConfigSubstitution.isFontConfigAvailable());
}

// On Linux/Mac, we will have access to it, and will be able to perform operations.
if (SystemUtils.IS_OS_LINUX) {
    Assert.assertTrue(fontConfigSubstitution.getEnabled());
    Assert.assertTrue(fontConfigSubstitution.isFontConfigAvailable());

    fontConfigSubstitution.resetCache();
}

Source: FontConfigSubstitutionRule | Aspose.Words for Java

I’ve put this code in a small maven project, see below. When this is run on a linux system, the assertions inside if (SystemUtils.IS_OS_LINUX) {…} fail:

[ERROR] Failures: 
[ERROR]   AsposeWordsFontConfigBugTest.demonstrateBugOnLinux:32
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

Actually both assertions fail, although JUnit of course stops after the first failure. Just remove the first assertion (containing getEnabled()) to verify this.

Tested on: Ubuntu 20.04, Debian 10 using Oracle JDK 17.

Complete maven project demonstrating this issue, containing a unit test with the sample code vom Aspose Word for Java’s javadoc:
aspose-words-fontconfig-bug.zip (2,3 KB)

I would like to emphasize that this code is taken from Aspose Words for Java’s own javadocs and that this issue leads to severe layout problems in PDF files due to the wrong fonts being used.

Is this already known?
Is there a workaround to force Aspose Words for Java to use Font-Config / fc-match even though isFontConfigAvailable() returns false?

Thank you and kind regards,
Achim Bitzer (Seitenbau GmbH)

@Achim_Bitzer
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): WORDSNET-26349

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.