Strange font substitution

Hello,
I’m writing you because today I’ve tested new aspose-cells 8.5.0 and observed strange result:
1) I’ve prepared document on my PC, applying fonts which are missed on Server.
2) Then I’ve uploaded the document on server and performed ‘conversion’.
Test-doc and result are attached

Best regards

Hi Akane,


Thank you for contacting Aspose support.

I am afraid, we require more information to properly analyze the presented scenario. Please provide the following details/artifacts.

  1. Operating system version & architecture of your server where conversion is taking place.
  2. JDK type & version installed on the server.
  3. Does your server has the following fonts installed and are your setting the font location using the CellsHelper.setFontDir method at the start of your application?
    1. Alexandra Script
    2. MS PGothic
    3. MS Gothic
  4. Please provide the above mentioned fonts from the machine where you have created the spreadsheet.
  5. To what format are your converting the spreadsheet?
  6. Please provide a PDF generated on the server so we could get a hint about the font substitution process on the server. You may save the spreadsheet in PDF format using the Workbook.save method while passing SaveFormat.Pdf as second parameter.

That being said, please note, Aspose.Cells APIs require the TrueType fonts used in the spreadsheet to be available on the machine where conversion is taking place. In case the operating system is Linux then it is advised to set the font location at the start of the application to point the API to pick the required fonts. Moreover, Aspose.Cells APIs currently support TTF & TTC font types only therefore while setting the font location path, the API will pick only TTF & TTC files. Other fonts files will be ignores and consequently the API will substitute the font with the ones available at the time of conversion.

Hello,
1. Doc was created on Win7 64, the conversion was performed on Linux x86_64
(as before with earlier releases)
2. java version "1.7.0_67"
3. No
4. MS fonts are commonly exist on any Win syst I suppose. Moreover I saw that tables was created with Colibri font
5. to PNG:
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setWarningCallback(exWCallback);
imgOptions.setImageFormat(format);
imgOptions.setHorizontalResolution(dpi_Resolution);
imgOptions.setVerticalResolution(dpi_Resolution);
imgOptions.setOnePagePerSheet(false);
imgOptions.setPrintingPage(PrintingPageType.IGNORE_BLANK);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
SheetRender sheetRender = new SheetRender(sheet, imgOptions);
sheetRender.toImage(pgIx, baos);

6. I’m a little confused by result. There are correct table at least for pdf file

The main thing why I wrote here is that I didn’t see so strange result with 8.4.x releases.
And yes, I know about font substitution. There are no applied in the document fonts on server, but we have another ones and as you see for simple cells it works.

Would you know something else?
Best regards.

Hi Akane,


Thank you for providing the information.

I have checked the PDF you have shared, and it is using entirely a different set of fonts as compared to the original spreadsheet. You may notice this while checking the document properties, Font tab. Moreover, I am unable to find the Alexandra Script font in my windows installation, rest of the fonts from the spreadsheet are available so I will perform a few tests in Linux environment with latest as well as previous releases. I will share my findings here for your reference.

Hi Akane,


Thank you for your patience with us.

Please check the attachments for the PDF & PNG files generated with Aspose.Cells for Java 8.4.2.5 & 8.5.0 on CentOS JDK 1.7. You will notice that the result generated with latest revision of the API is correct, moreover, the text displays fine by placing the fonts in the Linux environment and setting the font location. Please note, I was unable to find the font Alexandra Script that is the reason the text in Oval 79 shape hasn’t rendered correctly.

I suspect that the said problem could be due to the set of fonts that you currently have in Linux so I request you to please create an archive of all fonts available in Linux folder which you are setting in your application using the CellsHelper.setFontDir method and share here or via any free file hosting service. We will re-evaluate the case by placing your provided fonts in CentOS and regenerating the images for further investigation.

Hello,
I’ve tested several times.
1) There no one fonts applied in original document on server where conversion is performed.
List of available fonts:
Trebuchet

Bookman Old Style

Wingdings

Times New Roman

Arial Narrow WGL

FBBlueMingL

Comic Sans

Verdana

CSongGB18030C-Light

Century Gothic

Book Antiqua

Corsiva

Symbol

Webdings

Century Schoolbook

Arial

Georgia

Courier New

MotoyaExMincho

Wingdings 3

Sorts

Tahoma

Wingdings 2

MSung HK Light

Impact

Lucida Sans

Lucida Bright

Lucida Sans Typewriter

No one MS font.
2) You can find Alexandra Script font in the internet Alexandra Script - Поиск в Google I don’t think that the problem occurs due to this font.

3) I didn’t change code:

public boolean convert() throws ConversionServiceException {
prepare();//There the license is loaded
// Set conversion start time
synchronized (ExcelToPNGConverter.class) {
ArrayList paths = new ArrayList();
paths.add(getFontPath());
if (javaHome != null && !javaHome.isEmpty()) {
paths.add(javaHome + “/lib/fonts/”);
}
CellsHelper.setFontDirs(paths);
}
Workbook book = null;
int sheetCount = 0;
String uploadedFile = formatUploadedFile(inputFileName);
try {
synchronized (ExcelToPNGConverter.class) {
book = new Workbook(uploadedFile, loadOptions);
sheetCount = book.getWorksheets().getCount();
}
}
catch (CellsException e) {
}
catch (Exception e) {
}

if (book.getSettings().isProtected()) {
handleException(…);
}

if (sheetCount > getPageLimit()) {
handleException(…);
}

// Track page numbers independent of sheet no.
int filePgNo = 0;
com.aspose.cells.Font font;
ImageOrPrintOptions imgOptions = getImageOrPrintOptions();
try {
for (int i = 0; i < sheetCount; i++) {
if (imgOptions.getOnePagePerSheet()) {
imgOptions.setOnePagePerSheet(false);
}
Worksheet sheet = book.getWorksheets().get(i);
if (sheet != null) {
Cells cells = sheet.getCells();
if (cells != null) {
cells.setDefaultRowHeightMatched(true);
}
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setPaperSize(PaperSizeType.PAPER_LEDGER); // 17 in. x 11 in.
pageSetup.setPrintHeadings(true);
pageSetup.setPrintGridlines(true);
pageSetup.setOrientation(PageOrientationType.LANDSCAPE);
pageSetup.setFitToPagesWide(1);
pageSetup.setFitToPagesTall(0);
pageSetup.setTopMargin(0.5);
pageSetup.setLeftMargin(0.5);
SheetRender sheetRender = new SheetRender(sheet, imgOptions);
int pgCount = sheetRender.getPageCount();
if (pgCount == 1) {
imgOptions.setOnePagePerSheet(true);
sheetRender = new SheetRender(sheet, imgOptions);
}
// Check if there are more than one page per sheet
if (pgCount > 1) {
for (int p = 0; p < pgCount; p++) {
saveImageToFile(filePgNo, p, sheetRender);
filePgNo++;
}
}
else {
saveImageToFile(filePgNo, -1, sheetRender);
filePgNo++;
}
}
}
}
catch (Exception e) {
handleException(…);
}

return true;
}


private ImageOrPrintOptions getImageOrPrintOptions() {
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getPng());
imgOptions.setHorizontalResolution(dpi_Resolution);
imgOptions.setVerticalResolution(dpi_Resolution);
imgOptions.setOnePagePerSheet(false);
imgOptions.setPrintingPage(PrintingPageType.IGNORE_BLANK);
return imgOptions;
}

private void saveImageToFile(int sheetIx, int pgIx, SheetRender sheetRender) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (pgIx > 0) {
sheetRender.toImage(pgIx, baos);
}
else {
sheetRender.toImage(0, baos);
}
baos.close();
byte[] pngImageInBytes = baos.toByteArray();

String processFileName = formatProcessFile(sheetIx, PNG_EXTENSION);
writeToFile(processFileName, pngImageInBytes);
}

protected void writeToFile(String processFileName, byte[] imageInBytes) throws IOException {
OutputStream fos = null;
try {
fos = new FileOutputStream(processFileName);
if (fos != null) {
fos.write(imageInBytes);
}
}
catch (IOException e) {
throw e;
}
finally {
if (fos != null) {
fos.close();
}
}
}


So the steps where:
1) cells 8.4. Building the project, deploying on Server, Uploading documents and converting. Results attached.
2) cells 8.5. Building the project, deploying on Server, Uploading documents and converting. Results attached.
Only aspose-cell.jar was changed. Font Dir is the same, the rest is the same.

If you suppose that I made mistake using the libs could you please help me to find out the mistake?

Thank you in advance

Hi Akane,


Thank you for providing the list of fonts and the results produced on your side, however, we requested you to provide the font files because in our experience, font files having different revision and/or acquired from different source may produce diverse results. Anyway, let us collect all the mentioned fonts and reevaluate the scenario in Linux environment. In the meanwhile, we request you to please try the scenario on your side while using the latest version of Aspose.Cells for Java 8.5.0.4, and share the resultant PDF as well as the image without making any change to the application or fonts.

Hello,
Unfortunately I see the same result for 8.5.0.4 as for 8.5.0
Monotype.rar contains all server fonts + Alexandra (that is unavailable on server)
Test4.pdf - result for 8.4.0
Test5.pdf - result for 8.5.0
Test0.pdf - result for 8.5.0.4
code:

CellsHelper.setFontDirs(paths);
loadOptions = new LoadOptions(LoadFormat.AUTO);
Workbook book = null;
try {
book = new Workbook(uploadedFile, loadOptions);
book.save("/var/mcp/media/TestX.pdf", SaveFormat.PDF);
}
catch (Exception e1) {
}

Hi Akane,


Thank you for providing the font files from your server.

I have thoroughly tested the scenario again by placing your provided fonts to a directory in my CentOS 6.6 environment, pointed the API to pick those fonts using the CellsHelper.setFontDir (I have only one directory with fonts) at the start of the application and performed the simple conversion similar to your provided code snippet against different revisions of the Aspose.Cells for Java 8.4.0 to 8.5.0.4. I am afraid, I am not able to see the mentioned problem. Please check the attached archive for the resultant files produced on my side.

I have used the exact fonts (provided by you) and compiled the application against JDK 1.7.0_65. I am not sure what I am missing here that is not allowing me to reproduce the problem on my side. Let me discuss this matter with the product team and get back to you with some troubleshooting technique that could enable us to pin point the problem cause.

Hi again,


This is to inform you that upon discussion with the product team, I have learned that the font substitution behavior was altered between the releases 8.4.x & 8.5.0 due to which the font replacement algorithm could choose different font depending upon the environment. We will make some fixes to handle such scenarios with the next release of Aspose.Cells for Java.

In order to he send you the notifications regarding the aforesaid fix, I have logged a ticket in our database with Id CELLSJAVA-41411 and have attached it to this thread. As soon as we get more updates in this regard, we will post here for your kind reference.

Thank you. Looking forward for further information
BestRegards

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


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

Hello,
Sorry for delay.
The last release was tested, and I don’t observe the problem anymore.
Thank you.

Hi,


Thank you for the confirmation. Please feel free to contact us back in case you need our further assistance with Aspose APIs.