FontSettings.addFontsFolder only loads TTF fonts


#1

I found that Aspose.Imaging wasn’t finding MS Gothic when attempting to render an EMF containing Japanese text.


It turns out that when you call FontSettings.addFontsFolder, it doesn’t find MS Gothic because MS Gothic is a TTC (TrueType Collection), and Aspose.Imaging is only looking for files ending in “.ttf”.

This is in the obfuscated code of Aspose, in com.aspose.imaging.B:

private void a(File var1) throws IOException, FontFormatException {
File[] var2 = var1.listFiles();
File[] var3 = var2;
int var4 = var2.length;

for(int var5 = 0; var5 < var4; ++var5) {
File var6 = var3[var5];
if(var6.isDirectory()) {
this.a(var6);
} else if(var6.getName().toLowerCase().endsWith(“ttf”)) {
Font var7 = Font.createFont(0, var6);
this.b.add(var7);
}
}

}

This code is clearly not going to find the TTC files since it requires the name to end in “ttf”, but I also worry that it’s using java.awt.Font to create the font here, as this probably won’t find the font, as Java won’t know about it either.

(On a separate note, calls to String.toLowerCase() without passing a Locale are generally very dangerous. Although perhaps in this particular instance it might be safe, it’s safest to avoid using this method entirely. It would be worth getting calls to this removed from all libraries just in case. In this particular case, Locale.ROOT should have been passed in.)


#2
Hi Nicholas,

Thank you for your inquiry and sharing details.

This is to update you that an investigation ticket has been logged into our system with ID IMAGINGJAVA-643. All information has also been shared with our product team. Our product team will further look into it and provide feedback. We will update you with the feedback in this thread once available.


#3

The issues you have found earlier (filed as IMAGINGJAVA-643) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

#4

Seems like I get the same results under v17.4. EmfMetafileImage#getMissedFonts() returns {“MS Gothic”}, same as before, and the resulting image looks the same.


Attaching the EMF we used, as well as the font. Maybe the library failed to parse the font, or something like that?

#5

Hi Nicholas,


I have worked with file shared by you using Aspose.Imaging for Java 17.4 and unable to observe the issue.

Please try using the attached sample code. You can place the MS Gothic font in your computer directory somewhere. By using sample code, you have option to load the fonts externally using FontSettings.setFontsFolder(Fontpath) method. You can try setting the font folder and render the EMF to PDF. Then you can try generating the PDF without setting the fonts folder and you will observe the difference. I have attached the generated PDF file on my end for your reference as well.

The shared code will help you to achieve your requirements. Please share feedback with us if there is still an issue.

Best Regards,

#6

Ah, I believe this helps reproduce a different problem that I hadn’t noticed yet. Our own code had caught the exception and proceeded, which hid the real problem…


Exception in thread “main” class com.aspose.imaging.coreexceptions.FrameworkException: Font name not found —> java.awt.FontFormatException: Font name not found
— End of inner exception stack trace —
com.aspose.imaging.FontSettings.setFontsFolders(Unknown Source)
com.aspose.imaging.FontSettings.setFontsFolders(Unknown Source)
com.nuix.integration.TestEmf.main(TestEmf.java:26)
at com.aspose.imaging.FontSettings.setFontsFolders(Unknown Source)
at com.aspose.imaging.FontSettings.setFontsFolders(Unknown Source)
at com.nuix.integration.TestEmf.main(TestEmf.java:26)
Caused by: java.awt.FontFormatException: Font name not found
at sun.font.TrueTypeFont.init(TrueTypeFont.java:590)
at sun.font.TrueTypeFont.(TrueTypeFont.java:198)
at sun.font.TrueTypeFont.(TrueTypeFont.java:178)
at sun.font.CFontManager.createFont2D(CFontManager.java:155)
at java.awt.Font.(Font.java:615)
at java.awt.Font.createFont(Font.java:1056)
at com.aspose.imaging.z.a(Unknown Source)
at com.aspose.imaging.z.(Unknown Source)
… 3 more

I’m attaching the font which it failed on.


#7

Hi Nicholas,


Thanks for sharing further details with us.

I have tested the EMF file shared by you using code sample given in Testemf.txt and have been able to reproduce the exception. A ticket with ID IMAGINGJAVA-692 has been added in our issue tracking system to resolve the issue. This thread has been linked with ticket so that you may be notified once issue will be fixed.

We are sorry for your inconvenience,

#8

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.