Limiting font folders and providing custom paths

Hi,


I have a usecase where I need to let aspose cells api know where to look for fonts. I use the below mentioned line to achieve that:
Fontconfigs.setFontFolders(new String[]{“pathToMyDir”}, true);

I also have a usecase where I need to limit the folder that aspose looks into to find the necessary fonts and skip looking into any default system defined font folders.

I found on the page at

that this could be done by setting the system property. I used the below mentioned line:


System.setProperty(“Aspose.Cells.FontDirExc”, “pathToMyDir”);

The structure of my directory is:
pathToMyDir/oracle-wingding.ttf
pathToMyDir/albany/.ttf (variations of albany font)
pathToMyDir/liberation/.ttf (variations of liberation font)

I am running into the problem that whenever I set the system property to limit the folders that aspose cells looks into, I can no longer use any other font from under albany or liberation folder. Cells is always choosing oracle-wingdings as the font that substitutes any missing font in excel files.

So, if I have an excel file that uses Times New Roman in a table, and I want to generate an image from the sheet in question, it looks like aspose cells is using the font oracle-wingdings, even when I have the default font defined as follows:
FontConfigs.setDefaultFontName(“Albany WT J”);

I can use this default font that I set to generate the image if I don’t have the system property set.

Can you please advice me how to limit the folders, and also have the flexibility that allows aspose cells to recursively look in to folders for fonts specified? And if necessary, use a default font as well?

For you reference I have attached:

1. ReferenceDoclet.xlsx – the excel file that has the table defined
2. actual_table_fonts.PNG – the actual table generated using the wrong font
3. expected_table_fonts.PNG – the expected table that should be generated when I have the system property set, and the font folders specified via the FontConfigs method mentioned.

below is the code that I have used to generate that result:

Workbook wb = new Workbook(“ReferenceDoclet.xlsx”);
Worksheet sheet = wb.getWorksheets().get(“Table Range”);
PageSetup setUp = sheet.getPageSetup();
setUp.setPrintArea(“A8:H50”);
ByteArrayOutputStream opStream = new ByteArrayOutputStream();
ImageOrPrintOptions opts = new ImageOrPrintOptions();
opts.setImageFormat(ImageFormat.getPng());
new SheetRender(sheet, opts).toImage(0, opStream);

And the code to set the fonts is as follows:
System.setProperty(“Aspose.Cells.FontDirExc”, “pathToMyDir”);
FontConfigs.setFontFolders(“pathToMyDir”, true);
// the below mentioned default is an additional line:
FontConfigs.setDefaultFontName("Albany WT J);

Also,

It is interesting that I was earlier using 8.7.1 of aspose cells, and the below mentioned code with the CellsHelper class was working as expected:
CellsHelper.setFontDirs(new ArrayList(fontPaths));

But with newer versions of aspose, even the above mentioned code is choosing a different undesired font.

This new behavior is seen both with 17.02.0 and 17.3.0 of aspose cells for java.


My environment details: Oracle Linux 5 (Intel 64-bit)
Java version: 1.7.0_85(default)
Java SE version: 1.7.0_85 (default)

Thanks.

Hi.


Thanks for your posting and using Aspose.Cells for Java.

Please change your line to following. The last parameter is true, it means, it will search all the sub-directories inside your font directory.

FontConfigs.setFontFolder("/usr/temp/fonts", true); //Linux
FontConfigs.setFontFolder(“C:/temp/fonts”, true); //Windows

So, it should solve your issue. Please also check more information provided to you in your other thread.


Hi,

We did evaluate your issue further. Well, if for example, System.setProperty("Aspose.Cells.FontDirExc", "pathToMyDir"); is set, Aspose.Cells will only use fonts in "pathToMyDir" and won't look for fonts into its sub dirs. So, any other font folders setting and font sources setting in FontConfigs will not take effect anymore.

For your requirements, as you mentioned:
"Can you please advice me how to limit the folders, and also have the flexibility that allows aspose cells to recursively look in to folders for fonts specified? And if necessary, use a default font as well?"
We can add a new API so that you could limit to some folder and its sub-folders (directory) to use fonts in rendering images/PDF. I have logged a ticket with an id "CELLSJAVA-42226" for your issue/requirements.

By the way, you can use FontConfigs.setFontSubstitutes(String originalFontName, String[] substituteFontNames) to specify font substitute if you are not satisfied with our font substitution.

Thank you.
Hi,

Thanks for using Aspose.Cells.

This is to inform you that we have fixed your issue CELLSJAVA-42226 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

Hi,


We added API: setFontExclusiveSources(FontSourceBase[] exclusiveSources) in FontConfigs to set the fonts exclusive sources in the fix: Aspose.Cells for Java v17.3.5 (please try it), like older APIs: System.setProperty(“Aspose.Cells.FontDirExc”, “fontExclusiveFolder”).
System.setProperty(“Aspose.Cells.FontDirExc”, “fontExclusiveFolder”) will be ignored if this is set.
e.g
Sample code:

//only use fonts in “fontExclusiveFolder” dir and it’s sub dirs.
FontConfigs.setFontExclusiveSources(new FontSourceBase[]{new FolderFontSource(“fontExclusiveFolder”, true)});

Thank you.

Hi,


I tried the above provided fix, and it works.

When I can expect this fix to be released?

Thanks!

Hi,


Good to know that the new fix works for your requirements.

For your information, the hotfixes (e.g v17.3.5) posted into the forums can be directly used for production, these will behave like official releases of the product which have all the functionality (full fledged) of Aspose.Cells for .NET v17.3.0 till this fix. We normally provide quick fixes (interim releases) into support forums for the users against their issues, so they do not have to wait much to get fix of their issues. However, our next official release of the product i.e., Aspose.Cells for .NET v17.4.0 (which will also include the functionality of this fix) will be scheduled to be released in the mid of next month (April 2017).

Thank you.

The issues you have found earlier (filed as CELLSJAVA-42226) have been fixed in Aspose.Cells for Java 17.4.0.


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