FontConfig changes behavior after version 24.5

Hello,
we have a multitenant Microservice that uses Aspose Cells Java to extract images from Workbooks.
Before rendering and extract the images, the Microservice initializes the tenant dedicated custom fonts using the FontConfig class.
At the end, it cleans the FontConfig sources.

This is the code:

@Service
public class AsposeCustomFontServiceImpl implements AsposeCustomFontService {

  @Override
  public void setCustomFonts(List<byte[]> fonts) {
    if(fonts == null || fonts.isEmpty()) {
      return;
    }

    List<MemoryFontSource> fontSources = new ArrayList<>();
    for(byte[] font: fonts) {
      fontSources.add(new MemoryFontSource(font));
    }

    FontConfigs.setFontSources(fontSources.toArray(new MemoryFontSource[0]));
  }

  @Override
  public void clearCustomFonts() {
    FontConfigs.setFontSources(new FontSourceBase[] {});
  }
}

We have the necessity of update the Aspose Cells Java version from 24.5 to 25.2 but using the last version this test fails:

@Test
  void setCustomFontsTest() throws Exception {

    List<byte[]> fonts =
      getAllFonts(Paths.get(Objects.requireNonNull(this.getClass().getResource("/fonts/customerName")).toURI()).toString());
    asposeCustomFontService.setCustomFonts(fonts);

    Assertions.assertTrue(FontConfigs.isFontAvailable("Lobster"));
    Assertions.assertTrue(FontConfigs.isFontAvailable("Roboto"));

    asposeCustomFontService.clearCustomFonts();
    Assertions.assertFalse(FontConfigs.isFontAvailable("Lobster"));
    Assertions.assertFalse(FontConfigs.isFontAvailable("Roboto"));
  }

The failure is at this row:

Assertions.assertFalse(FontConfigs.isFontAvailable("Lobster"));

because the “FontConfigs.isFontAvailable(“Lobster”)” returns true as the font is available despite the microservice cleaned the font sources.
Could you help us to understand if are there any changes in this behavior, we checked release notes without find anything, please?
What is the correct way to initialize fonts and clean them?
Thanks

@giulio.andolfi ,

Besides FontConfigs.setFontSources API to set fonts, Aspose.Cells for Java also loads fonts in default font folders. e.g. "C:\Windows\Fonts" on Windows platform. We also load Office cached clould fonts on Windows platform in recent versions. This may be the reason. In a word, the “Lobster” font is loaded by default.
You can check Assertions.assertFalse(FontConfigs.isFontAvailable("Lobster")); before setting FontSources.

void setCustomFontsTest() throws Exception {

    //Check whether the font is loaded by default.
    Assertions.assertFalse(FontConfigs.isFontAvailable("Lobster"));

    List<byte[]> fonts =
      getAllFonts(Paths.get(Objects.requireNonNull(this.getClass().getResource("/fonts/customerName")).toURI()).toString());
    asposeCustomFontService.setCustomFonts(fonts);

    Assertions.assertTrue(FontConfigs.isFontAvailable("Lobster"));
    Assertions.assertTrue(FontConfigs.isFontAvailable("Roboto"));

    asposeCustomFontService.clearCustomFonts();
    Assertions.assertFalse(FontConfigs.isFontAvailable("Lobster"));
    Assertions.assertFalse(FontConfigs.isFontAvailable("Roboto"));
}

We tested again using different PCs and we have found different behavior.
Using PCs where in the past we installed the fonts Lobster and Roboto even after uninstalled, the test fails. But using PCs where the two fonts are never installed the test run properly.
This is local environment and we do not care if the test fails.

We just care that in the production environment where we run this microservice multitenant and the fonts are never installed if we load a customer license font and after use we clear the custom fonts using this code:

@Override
public void clearCustomFonts() {
  FontConfigs.setFontSources(new FontSourceBase[] {});
}

we are sure that we do not use the fonts for another customer without license.

In alternative could you explain us the correct approach to handle this scenario?
Thanks

@giulio.andolfi
Thanks for further details. Let us investigate and analyze your issue in details. Once we have any new information, we will share it with you. We will get back to you soon.

@giulio.andolfi

From Aspose.Cells for Java 24.7, we load Office cached clould fonts additonaly by default. For your issue, there may be another “Lobster” font file in cached clould fonts folder. The folder is “C:\Users\YourUserName\AppData\Local\Microsoft\FontCache\4\CloudFonts”(Please replace “YourUserName”). Could you please check it on your production environment?

Aspose.Cells never installs fonts, it just load fonts when you run FontConfigs.setFontSources(fontSources.toArray(new MemoryFontSource[0])); and the set fonts can be clear when you run FontConfigs.setFontSources(new FontSourceBase[] {});.

Also, the other API FontConfigs.setFontExclusiveSources(FontSourceBase[] exclusiveSources) only load the set font sources. It will not load other system fonts(e.g. fonts in “C:\Windows\Fonts”) by default.

Hello @peyton.xu,
thank you to better explain us how the FontConfig works.
The release notes of the version 24.7 does not contains this behavior but now it is clear for us.
We have removed the Lobster and Roboto fonts from the cache and now all works fine.
In the production environment this cache does not contain the custom fonts because we do not install them.
Thank you for help us.
Regards

@giulio.andolfi,

Thank you for your feedback. It’s good to hear that you’ve resolved your issue. If you have any further questions or comments, please don’t hesitate to reach out to us again.