Rotated shapes do not return the correct position or dimensions

When a shape is rotated in Excel and read by the Aspose.Cells assembly, incorrect position and dimensions are reported. The rotation affects the position and dimensions, but incorrectly. If the shape is rotated by 90, 180, 270, or 360 degrees, then the output values are correct, but it seems that they are restricted to these angles only. Any other rotation angle will return values relating to one of these 4 angles. Note that the image attained by calling the Shape.ToImage method is correct. It is just the position and dimensions of the rotated shapes that are incorrect. Please see the attached document and image, where the rectangle highlights the incorrect returned positional details.

Many thanks,
Sheridan

Modified_Rotation.zip (6.1 KB)
Capture.PNG (3.4 KB)

@workshare,

Thanks for the screenshot and template file.

Do you read those attributes regarding position and dimensions in code, please provide your sample code (runnable) to show the issue, we will check it soon.

There is no code sample required. Please read the supplied document with the Aspose.Cells assembly and look at the size and position of the ‘rotated’ shape. It will not equal the size of the actual rotated shape in Excel. If you rotate the shape by between 90 and 180 degrees (I think), the size values output from your 10.6.0.0 version will be those of a shape rotated by exactly 90 degrees. If you look, you will see what I mean.

@workshare,

Thanks for providing further details.

I did evaluate your issue a bit using your template file and following sample code with Aspose.Cells for .NET v19.1.x (please try it if you are not already using it), it works fine. It gives correct size and other attributes for the shape. Even it renders to image file fine. Comments are attached to the lines of code for output prints:
e.g
Sample code:

 Workbook workbook = new Workbook("e:\\test2\\Modified_Rotation2.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            //Get the first shape in the worksheet.
            Aspose.Cells.Drawing.Shape shape = sheet.Shapes[0];
            //If the first shape is rectangle shape.
            if (shape.GetType().ToString() == "Aspose.Cells.Drawing.RectangleShape")
            {
                Aspose.Cells.Drawing.RectangleShape rec = (Aspose.Cells.Drawing.RectangleShape)shape;

                string place = rec.Placement.ToString();//Move and size - Ok
                double lnwt = rec.LineFormat.Weight;//  0.5 (pt) - Ok
                //There is an issue where height and width attributes swap each other
                //So you may swap the variables.
                double width = rec.HeightCM;//aprox. 1.11 - Ok
                double height = rec.WidthCM;//aprox. 4.29 - Ok
                double angle = rec.RotationAngle;//225 - Ok

                rec.ToImage("e:\\test2\\out1.png", new ImageOrPrintOptions() {ImageType = ImageType.Png});
            }  

Let us know with more details and sample code (runnable) if you still find any issue with v19.1.x, we will check it soon.

Thank you for your response Amjad,

We cannot currently update to version 19.1 under our existing license. I have updated to the previous version 18.12 and this problem still exists in it, totally unchanged. Can you please verify that there is a difference in this area between the two latest versions and that this has specifically been fixed in only the latest version?

I have uploaded two new documents that exhibit this problem and the screenshot output, that draws a border around the boundary of the provided and size data position by the Aspose.Cells dll.

I think that your code example is flawed, because

a) why should we have to swap the width and height values at all? That is clearly another bug.
b) as can be clearly seen in the attached screenshot, part a) is not always the case, as it seems to depend on the rotation angle.

Many thanks.
Sheridan

Rotation.zip (36.9 KB)

@workshare,

The height/width swapping issue is not there when I used your newly attached template file. I again tested your scenario/ case using the following sample code with your template file and it works find. I could not find any issue regarding size (height, width, etc.) and other formattings attributes. I have attached the output images in the zipped archive and also pasted the console output for your reference:
e.g
Sample code:

                Workbook workbook = new Workbook("e:\\test2\\ShapeRotationModified.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            int i = 0;
            //Get the first shape in the worksheet.
            foreach (var shape in sheet.Shapes)
            {
                //If the first shape is rectangle shape.
                if (shape.GetType().ToString() == "Aspose.Cells.Drawing.RectangleShape")
                {
                    i++;
                    Aspose.Cells.Drawing.RectangleShape rec = (Aspose.Cells.Drawing.RectangleShape)shape;
                    Console.WriteLine(rec.Name + ":");
                    string place = rec.Placement.ToString();
                    Console.WriteLine("Placement: "+ place);
                    double lnwt = rec.LineFormat.Weight;
                    Console.WriteLine("Border line wt:" + lnwt);
                    double width = rec.WidthCM;
                    Console.WriteLine("Width: " + width);
                    double height = rec.HeightCM;
                    Console.WriteLine("Height: " + height);
                    double angle = rec.RotationAngle;
                    Console.WriteLine("Rotation angle: " + angle);

                    rec.ToImage("e:\\test2\\outshp" + i.ToString()+ ".png", new ImageOrPrintOptions() { ImageType = ImageType.Png });

                    Console.WriteLine("----------- ");
                }
            }

Rectangle 5:
Placement: MoveAndSize
Border line wt:0.5
Width: 3.04270833333333
Height: 2.09020833333333
Rotation angle: 315

Rectangle 6:
Placement: MoveAndSize
Border line wt:0.5
Width: 2.09020833333333
Height: 3.04270833333333
Rotation angle: 240

Rectangle 7:
Placement: MoveAndSize
Border line wt:0.5
Width: 2.09020833333333
Height: 3.04270833333333
Rotation angle: 120

Rectangle 8:
Placement: MoveAndSize
Border line wt:0.5
Width: 3.04270833333333
Height: 2.09020833333333
Rotation angle: 15

I am using latest version/fix: Aspose.Cells for .NET v19.1.5 (attached). If you find any issue with v19.1.5, let me know with sample code (runnable) and template file, we will check it soon.

Moreover, with each release and fix, we do enhance reading/writing, parsing and rendering shapes module. So, using latest version/fix would be always better.
files1.zip (9.5 KB)

Aspose.Cells19.1.5 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells19.1.5 For .Net4.0.Zip (4.8 MB)

PS. I guess I found Rectangle 6 and Rectangle 7 have swapping issue for width and height attributes. We will look into it soon.

Look at my screenshot. It shows that shapes that are rotated between 90 and 180 degrees and 270 and 360 degrees have their widths and heights swapped.

@workshare,

Thanks for providing further details.

Yes, we found the swapping issue (as I mentioned in PS. in last reply). I tested your scenario/ case using the sample code (as pasted in previous post) with your template file and it works partially. I could not find any issue regarding size (height, width, etc.) and other formatting attributes for first and last Rectangle shape in the sheet. But I have found the issue for the second and third shape, i.e., I found “Rectangle 6” and “Rectangle 7” have swapping issue for width and height attributes. I have logged a ticket with an id “CELLSNET-46579” for your issue. We will look into it soon.

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

Regarding “incorrect position” issue, could you elaborate more with sample code (runnable) and template file(s) to show the issue, we will look into it as well.

Hi Amjad,

There also seems to be another bug relating to rotation, but this time with Text Boxes. Please look at the attached documents and the resulting image, that was created by calling:

Shape.ToImage(new ImageOrPrintOptions { ImageType = ImageType.Png });

As the text box has incorrect dimension values, the output image is also the incorrect size.

Broken Rotation.zip (13.5 KB)

@workshare,

Could you please share the complete runnable code which is used to create this image? Provide us the expected output file created by Excel for our reference.

It is simply not possible to share the working code. It is part of a huge application and the code is not the issue here. The same code works perfectly fine for creating images from other shapes. This small excerpt shows the problem:

Workbook workbook = new Workbook(@"C:\Users\sheridan.yuen\Downloads\6.xlsx");
Shape shape = workbook.Worksheets[0].Shapes[0];
Aspose.Cells.Drawing.TextBox textBox = (Aspose.Cells.Drawing.TextBox)shape;
textBox.ToImage(@"C:\Users\sheridan.yuen\Downloads\6.png", new ImageOrPrintOptions() { ImageType = ImageType.Png });

I already attached the document used. Run this code and look at the image to clearly see the issue.

@workshare,

Thanks for the sample code and template file.

After an initial test, I am able to observe the issue as you mentioned by using your sample code with your template file. I found an incorrect rendering of rotated shapes in Shape to image conversion. Your might be right, as the rotated text box has incorrect dimensions, the output image may be with incorrect size. I have logged your issue with an id “CELLSNET-46580” for your issue. We will look into it soon.

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

Hi Amjad,

I have discovered that the same problem exists for some shapes. If you look at the attached documents, you can find another example.

Can you please provide me with a complete list of all shapes that are affected by this error, as we will have to document these as limitations of our software?

SAMPLES.zip (12.5 KB)

@workshare,

I am afraid that as this issue is not reported earlier, therefore no such list is available. You may please try different scenarios and if you face any issue please share with us the sample file and runnable code snippet (if any) for our reference. We will analyze the issue and provide assistance accordingly.

@workshare,

Please try our latest version/fix: Aspose.Cells for .NET v19.2.1:

Aspose.Cells19.2.1 For .Net2_AuthenticodeSigned.Zip (4.7 MB)
Aspose.Cells19.2.1 For .Net4.0.Zip (4.8 MB)

Your issue (logged earlier as “CELLSNET-46580”) should be fixed in it.

Let us know your feedback.

With all due respect ahsaniqbalsidiqui, as this bug is caused by Aspose code, do you not think that someone from Aspose should provide a list of the shapes that are affected?

@workshare,

We have logged this requirement in our database for investigation. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46612 - List of all the rotated shapes that do not return the correct position or dimensions

Thank you kindly.

@workshare,
You are welcome.

The issues you have found earlier (filed as CELLSNET-46580) have been fixed in Aspose.Cells for .NET v19.3. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi