Default font substitution does not use fontconfig configs for Linux when converting xlsx to pdf

Hi,

A
default font substitution does not use fontconfig configs for Linux
(Ubuntu 15.10 + mono 4.2.3.4) when converting xlsx to pdf (see the attached
files WinFonts.xlsx and WinFonts.xlsx.pdf) that looks like a bug. The version Aspose.Cells 16.11.0 for .NET
4.0 is used.
It should be noted that at the same time Aspose.Slides
does the right substitution according to the configs when converting
pptx to pdf (see the attached files WinFonts.pptx and WinFonts.pptx.pdf).

So, by fontconfig config, the
font Arial should be substituted by “Liberation Sans” and “Times New
Roman” - by “Liberation Serif”. But the sample code produces the pdf
with the font BGPArial.

Sample code:
{
Aspose.Cells.FontConfigs.SetFontFolder("/usr/share/fonts", true);
var doc = new Aspose.Words.Document(“WinFonts.xlsx”);
doc.Save(“WinFonts.xlsx.pdf”);
}

Reference code for Aspose.Slides that works properly:
{
var presentation = (new Aspose.Slides.PresentationFactory()).ReadPresentation(“WinFonts.pptx”);
presentation.Save(“WinFonts.pptx.pdf”, Aspose.Slides.Export.SaveFormat.Pdf);
}

Best Regards,
Aleksey.

Hi,

Thanks for your posting and using Aspose.Cells.

Please try the following code and see if you still have the problem. Please share us "Liberation Serif", "Liberation Sans" font files in your "/usr/share/fonts" folder and the generated pdf file.

C#
Aspose.Cells.FontConfigs.SetFontFolder("/usr/share/fonts", true);

//Set font substitute: “Arail”->“Liberation Sans”, be sure “Liberation Sans” font is in your “/usr/share/fonts” folder
Aspose.Cells.FontConfigs.SetFontSubstitutes(“Arial”, new string[] { “Liberation Sans” });

//Set font substitute: “Times New Roman”->“Liberation Serif”, be sure “Liberation Sans” font is in your “/usr/share/fonts” folder
Aspose.Cells.FontConfigs.SetFontSubstitutes(“Times New Roman”, new string[] { “Liberation Serif” });

var workbook = new Aspose.Cells.Workbook(“WinFonts.xlsx”);
workbook.Save(“WinFonts.xlsx.pdf”);


Hi Shakeel,



the issue does not concern any explicit client font substitution through Aspose API but deals with default font substitution.



So, on my Linux (Ubuntu 15.10 + mono 4.2.3.4) the following code shows that the font “Liberation Sans” is used instead of Arial by .NET itself:

C#:

var fontName=“Arial”;

var fontFamily = new System.Drawing.FontFamily(fontName);

if (fontName==fontFamily.Name)

Console.WriteLine(“The font ‘{0}’ is directly used.”, fontName);

else

Console.WriteLine(“The font ‘{0}’ is auto substituted by ‘{1}’.”, fontName, fontFamily.Name);



The output of the code:

>> The font ‘Arial’ is auto substituted by ‘Liberation Sans’.



As I wrote above, Aspose.Slides works properly, apparently uses a similar code for valid default font substitution. But Aspose.Cells does not - and it looks like a bug.



Best Regards,

Aleksey.

Hi Aleksey,

I believe your concerns are that Aspose.Cells and Aspose.Slides are using different substituted fonts for PDF rendering when required fonts are not present on the machine. This is quite possible because both APIs have different font substitution mechanism. My colleague has already shared a way to control this behavior by using the FontConfigs.SetFontSubstitutes method which allows to specify a list of substitution fonts against a particular missing font.

By the way, we were not able to execute the code as the variable fontName is undefined. Please share executable code so we may perform tests and share our feedback.

Hi, Babar,



I have corrected the code above (it had a mistake). It shows using of .NET class FontFamily to get information about system font substitution. The mechanism is used by nearly all the applications for Linux.

The question is why Aspose.Cells does not use it?

Could the product provide this variant of font substitution in a some future (may be in addition to existing one in the product already and providing a selection of mechanism)?



Best Regards,

Aleksey.

Hi Aleksey,


Thank you for the correction in code.

I can observe that Aspose.Cells for .NET API substitutes the font differently than .NET Framework. Currently I am not sure of the reason behind this behaviour therefore I would request you to give me some time to discuss this matter with the concerned member of the product team. As soon as I have further updates in this regard, I will post here for your kind reference.

Hi Aleksey,

This is to update you that I have logged a formal request in our database (CELLSNET-44944) to analyze the Aspose.Cells's font substitution mechanism in order to mimic .NET framework's behavior. Moreover, I have requested the product team to consider providing a duel mechanism so that the users may choose from Aspose.Cells' font substitution mechanism or .NET's. Please spare us little time for the feasibility analysis. In the meanwhile, we will keep you posted with updates in this regard.

Hi again,

This is to update you that we have resolved the problem logged earlier as CELLSNET-44944. Please note, we have exposed the FontConfigs.PreferSystemFontSubstitutes with the latest revision of Aspose.Cells for .NET 16.11.7 (attached) in order to achieve your desired behavior. If the said property is set to true, the Aspose.Cells APIs will prefer to use .NET’s font substitution mechanism. In order to verify the behavior, please try the following piece of code.

C#

var fontName=“Calibri”;
var fontFamily = new System.Drawing.FontFamily(fontName);
if (fontName==fontFamily.Name)
Console.WriteLine(“The font ‘{0}’ is directly used.”, fontName);
else
Console.WriteLine(“The font ‘{0}’ is auto substituted by ‘{1}’.”, fontName, fontFamily.Name);

FontConfigs.PreferSystemFontSubstitutes = true;
var book = new Workbook ();
var sheet = book.Worksheets [0];
var cells = sheet.Cells;
var style = book.CreateStyle ();
style.Font.Name = “Calibri”;
cells [“A1”].SetStyle (style);
cells [“A1”].PutValue (“Hello World!”);
PdfSaveOptions options = new PdfSaveOptions ();
book.Save ("/home/babar/Downloads/output.pdf", options);

Hi Babar,



thanks for the new feature! But it seems to have a bug: FontConfigs.SetFontSubstitutes does not work when FontConfigs.PreferSystemFontSubstitutes set to true.



Sample:

FontConfigs.PreferSystemFontSubstitutes = true;

// does not work:

Aspose.Cells.FontConfigs.SetFontSubstitutes(“Times New Roman”, new string[]{“Ubuntu”});

- that yields:

The font “Liberation Sans” substitutes instead of the missing Arial font by the system font substitution rules - it is ok. But the missing font “Times New Roman” is not substituted by present Ubuntu font (specified by FontConfigs.SetFontSubstitutes) - it is a bug.



I think it would be better to have the following sequence steps to resolve fonts:

1. Try to resolve and find font using FontConfigs.SetFontSubstitutes substitution rules.

2. If font is not found, use own or system font substitution depending on FontConfigs.PreferSystemFontSubstitutes flag.



Best Regards,

Aleksey.

Hi Aleksey,


Thank you for your feedback. Regarding your recently shared scenario, I am able to replicate the said behaviour on my side while using the following piece of code. Based on the test results, I have created a separate ticket with Id CELLSNET-44958 for the product team’s review. Please spare us little time for the proper analysis. In the meanwhile, we will keep you posted with updates in this regard.

C#

FontConfigs.PreferSystemFontSubstitutes = true; //Switch between true & false
FontConfigs.SetFontSubstitutes (“Calibri”, new string[]{ “Liberation Mono”, “Takao PGothic” });
var book = new Workbook ();
var sheet = book.Worksheets [0];
var cells = sheet.Cells;
var style = book.CreateStyle ();
style.Font.Name = “Calibri”;
cells [“A1”].SetStyle (style);
cells [“A1”].PutValue (“Hello World!”);
PdfSaveOptions options = new PdfSaveOptions ();
book.Save ("/home/babar/Downloads/output-with-PreferSystemFontSubstitutes.pdf", options);

Hi again,


Please try the latest version of Aspose.Cells for .NET 16.11.8 against the problem logged earlier as CELLSNET-44958, and share your feedback.

Hi Babar,



thanks for the fix - I have tried Aspose.Cells for .NET 16.11.8 against the issue - it does work properly.



Best Regards,

Aleksey.

Hi,

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved with the latest fix. Let us know if you encounter any other issue, we will be glad to look into it and help you further.

The issues you have found earlier (filed as CELLSNET-44944;CELLSNET-44958) have been fixed in this update.


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