Text alignment looks random in the converted image

Hi,

A few months ago I’ve discovered and reported an issue on image rendering with font SimHei+Arial Black text alignment (Cell text alignment is changed in the converted image)
The output image looks fine after the fix.

However, when I tried a different font (DFKai-SB + Calibri), the issue happens again and looks even worse than the previous post:

Code:
var newWorkbook = new Workbook(@“test.xlsx”);
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Emf,
OnlyArea = false,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
OnePagePerSheet = true,
Transparent = true
};

var sheet = newWorkbook.Worksheets[0];
sheet.PageSetup.PrintArea = “A1:B1”;
sheet.PageSetup.LeftMargin =
sheet.PageSetup.RightMargin = sheet.PageSetup.TopMargin = sheet.PageSetup.BottomMargin = sheet.PageSetup.HeaderMargin = sheet.PageSetup.FooterMargin = 0;
SheetRender render = new SheetRender(sheet, options);
render.ToImage(0, @“out.emf”);

In the Excel sheet I had two cells where one has two fonts (DFKai-SB and Calibri on A1 and DFKai-SB only on B1), it looks aligned properly in Excel and also in the image by copy/pasting manually. But the alignments are totally different in Aspose’s rendered image. (See the screenshot where I compared the outputs from Office vs. Aspose, and marked the difference)

screenshot.png (7.3 KB)

I’ve also attached the test files and font files.

test.zip (2.8 MB)

To me it looks like Aspose didn’t do a very good job on rendering Excel sheets with Asian fonts or with a mixture of Asian and Latin fonts, as there seems to be a lot of problems specifically on the text alignments. (Apart from the link above, I also had another ticket Text cut off in rendered image when a cell has more than one fonts which is also related to the alignment I believe)

As Asian+Latin text is usually needed in Excel sheet and rendering is one of the key features we need from Aspose. Could you please take a look into this?

Thanks

Hi,

An update here, I’ve double checked the fix for Cell text alignment is changed in the converted image - #7 by amjad.sahi I mentioned above, it actually only works if the Latin text font is ‘Arial Black’, if I changed the font from ‘Arial Black’ to ‘Calibri’ the issue still exists. Please refer to my new reply in the link. I believe that issue may not be completely fixed either.

It caused quite a big problem on image rendering. Could you please look into this?

Thanks

@ServerSide527,

Thanks for the template file, sample code, screenshot and details.

Which version of Aspose.Cells you are using? When I use Aspose.Cells for .NET v18.2.4 (latest fix), I got “A generic error occurred in GDI+.” error on the last line of your code. I did install your provide font “DFKai-SB” first and then tried your sample code with your template file but got the error when rendering to image file. I got correct PDF file though if I save to PDF file format (by adding a line for saving to PDF at the end).

I am also attaching the output PDF file by Aspose.Cells APIs.
out1.pdf (42.2 KB)

Hi,

I’m using the latest official version 18.2.0 from nuget. I didn’t see the GDI+ error either using the licensed version or the evaluation version (see screenshot).
image.png (4.7 KB)

To confirm I downloaded the test file from the attachment in this post but I couldn’t reproduce the GDI+ error either. Could it be something specific in 18.2.4?

Thanks

@ServerSide527,

Could you try our latest version/fix: Aspose.Cells for .NET v18.2.4 and confirm the exception which I mentioned, so we could proceed further:

Hi,

Thanks for providing the latest version. (with .NET 4.0)

I’ve tested using this dll but still no error message and still produced wrong image layout.
To confirm I even printed out the version number as well as a log right before the render line (see my screenshot):
image.png (28.9 KB)

Just in case I’ve again attached my test file.
test.zip (6.1 KB)

@ServerSide527,

I will check it why I am getting this error, may be it is due to my environment (Windows 64-bit, VS.NET 2008, NET 2.0(target framework), etc.) or other settings. I also appreciate if you could create a console demo application (runnable) with template file(s), zip the project and post us here (you may exclude the Aspose.Cells assembly when zipping the project). This may also help us to evaluate your issue precisely.

@ServerSide527

Thanks for using Aspose APIs.

We were able to observe this issue and logged it in our database for investigation and for a fix. Once, the issue is resolved or we have some other news for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-45952 - Text alignment looks random in the converted image

@ServerSide527

The text alignment issue in Cell A1 is fixed in

but we cannot make text in Cell A1 and Cell B1 align to the same line since they are of different fonts. However, the text alignment difference between Cell A1 and Cell B1 is less in the new fix.

Hi

Thanks for the update.

In fact the Asian text font in A1 and B1 are the same (DFKai-SB). And if you copy/paste manually, you will notice the alignment is correct, while with 18.2.6 there’s still minor difference. I believe Aspose rendering should behave the same as what we have in the office.

Could you please take a further look into that?

Thanks

@ServerSide527

Text in Cell A1 is rich text, the text “测试” is DFKai-SB font, but the text “CFA” is Calibri font. The baseline of DFKai-SB font (Bold style, 10 size) and Calibri font (Bold style, 10 size) are different. We use the larger baseline(Calibri font(Bold style, 10 size)), but it seems that Microsoft Excel uses the baseline of DFKai-SB font, so the text in Cell A1 in our output is a bit upper comparing the one in Microsoft Excel output.

This issue of text alignment difference between Cell A1 and B1 is similar to the ticket CELLSNET-45963.

We will investigate it and update you if we have some more findings.