No warnings logged for incorrect font type

Hi,

We are using Aspose.cells java version 19.7 to generate .xlsx files. One of the use case is that our product users can provide the font type/name value to be applied on the cells. We see that in cases where the provided value exceeds the length of 31, the generated excel document upon opening gives an error about style.xml. I found about this limitation on length by setting the same value using Ms. Excel 365, here the value is automatically truncated every time it exceeds length of 31. The following code can be used to reproduce the issue.
public static void main(String[] args) throws Exception
{
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
Cell a = worksheet.getCells().get(CellsHelper.cellIndexToName(0, 0));
a.setValue(“RPEAsposecells”);
Style style = a.getStyle();
style.getFont().setName(“IBM Plex Sans SemiBold, Arial Black”);
workbook.save(“D:\issues\ABC\work.xlsx”);
}

In such scenarios, we expect atleast some warning to be logged by the library. I tried using the IWarningCallBack interface to see if there’s any warning reported while saving the workbook but it doesn’t happen.
However, we also use aspose.words java 19.7 version and while saving the document we do get a warning(via IWarningCallBack interface) such as - “Font ‘IBM Plex Sans, Arial’ has not been found. Using ‘Times New Roman’ font instead. Reason: default font substitution.”

Regards,
Akash Srivastava

@Akash007,

Thanks for providing us code segment and details.

Well, IWarningCallBack interface would take effect if you are saving to PDF rendering. I guess you may also try to save to PDF file format to get to know if there are some unsupported fonts in the workbook, see the sample code segment for your reference. I tried it using the latest version and it works ok:
e.g
Sample code:

Workbook workbook = new Workbook();
		Worksheet worksheet = workbook.getWorksheets().get(0);
		Cell a = worksheet.getCells().get(CellsHelper.cellIndexToName(0, 0));
		a.setValue("RPEAsposecells");
		Style style = a.getStyle();
		style.getFont().setName("IBM Plex Sans SemiBold, Arial Black");
		a.setStyle(style);
		
		PdfSaveOptions options = new PdfSaveOptions();
	    options.setWarningCallback(new WarningCallback());

workbook.save("f:\\files\\out1.pdf", options);
	 
.............

class WarningCallback implements IWarningCallback {
	 
    @Override
    public void warning(WarningInfo info) {
        if(info.getWarningType() == WarningType.FONT_SUBSTITUTION)
        {
        	System.out.println(info.getDescription() + " In short, this font is not found");
        	
        	
        }
    }
}

Hope, this helps a bit.

@Amjad_Sahi
Thanks for the reply. Saving the workbook as pdf is another big operation, plus it comes with managing the deletion of the unwanted pdf file. Is there a better option to know about the validity/availability of a font type?

@Amjad_Sahi We made another observation. Aspose.words and Aspose.cells handle font name values differently when the font name values exceed the length of 31. In case of aspose.words, the value is truncated automatically whereas with aspose.cells the value is set without any truncation and this causes error when the .xlsx file is opened.

Regards,
Akash Srivastava

@Akash007,

Thanks for providing us further details and concerns.

As you demand some means or other way around to handle your scenarios when specifying incorrect fonts, so I have logged a ticket with an id “CELLSJAVA-43191” for your issue. We need to investigate and analyze and check if we can/should throw an exception to users. Alternatively, Aspose.Cells might just truncate the font names automatically for the users. We have to foresee other aspects as well.

We will look into it soon.

Once we have an update on it, we will let you know.

@Amjad_Sahi
Thanks again for understanding the concerns. I’ll be monitoring this thread for any updates on the mentioned issues.

@Akash007,

Sure, we will keep you posted with updates in this regard.

@Akash007,

Please note, when drawing text with the font is applied, then we can only know whether the font should be substituted or not. We will throw a warning (message) if the font name’s length exceeds 31 chars, this will suit your needs.

Moreover, we have figured out the issue now. The new fix will be posted in the next few days after we have performed QA and incorporated other enhancements and fixes.

@Amjad_Sahi
So this warning would occur upon its own or we’ll have to use the PDFSaveOptions and WarningCallback mechanism to get it?

@Akash007,

We will provide complete details when we post the fix.

@Akash007,
WarningType.FONT_SUBSTITUTION only occurs when saving pdf or rendering shapes to image.
WarningType.InvalidFontName (in the next fix) occurs when set font name with Font.setName().

@ahsaniqbalsidiqui
Just to get my understanding correct, does that mean while saving an Excel(using aspose.cells) or Word(using aspose.words) file, usage of PDFSaveOptions won’t be a requirement to get the warning WarningType.InvalidFontName through IWarningCallBack object?

@Akash007,

Yes, your understanding is correct. You got to set the attribute for the class (which implements the interface) under OoxmlSaveOptions API. See the sample code segment for your reference:
e.g
Sample code:

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.XLSX);
		saveOptions.setWarningCallback(new WarningCallback()); 

Please wait for the next fix which you will use for your needs.

@Amjad_Sahi
Great. Thanks!

@Akash007,

You are welcome.

@Akash007,

Please try our latest version/fix: Aspose.Cells for Java v20.5.3 (attached)
aspose-cells-20.5.3-java.zip (7.1 MB)

Your issue should be fixed in it. If an invalid font name (that exceeds the length of 31), a warning will be thrown if you implement IWarningCallback interface.

Let us know your feedback.

The issues you have found earlier (filed as CELLSJAVA-43191) have been fixed in Aspose.Cells for Java v20.6. This message was posted using Bugs notification tool by ahsaniqbalsidiqui

@Amjad_Sahi We upgraded the aspose cells library to version 20.8. The behavior is not what is described in your comment from June 3. Instead a CellsException is thrown when a font name with length > 31 characters is passed into the method com.aspose.cells.Font.setName() .

com.aspose.cells.CellsException: The max length of the font name is 31
at com.aspose.cells.ztu.warning(Unknown Source)
at com.aspose.cells.Font.setName(Unknown Source)

The expected IWarningCallBack approach doesn’t seem to be helping here.

@Akash007,

Please note, when length of the font name exceeds 31 chars (for the method com.aspose.cells.Font.setName()), an exception would be inevitable.

But we found WarningType.INVALID_FONT_NAME is not evaluated/instantiated in the interface when saving to Excel or PDF file format. We will look into it and get back to you soon.

@Amjad_Sahi i don’t see this behavior of exception occurring in aspose words for java while setting font name. And if an exception is being mandatorily thrown and is inevitable then what use-case a warning serves?