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.