Rotate text within a shape

Hello! I am currently using the Diagram Trial Version; I am brand new to Aspose.


I have fairly small rectangles on my diagram, and I need to rotate the text to read vertically.

e.g. “TEXT” should be in the rectangle as

T
X
E
T

Can anyone provide guidance as to how to do this?

//Add a new rectangle shape
long shapeId = diagram.AddShape(posX * .2, posY * .2, posWidth * .1, posHeight * .1, @“Rectangle”, 0);
Aspose.Diagram.Shape shape = diagram.Pages[0].Shapes.GetShape(shapeId);

string shapeText = GetTextForPosition(item);

shape.Text.Value.Add(new Aspose.Diagram.Txt(shapeText));

Hi Nicholas,


Thank you for contacting support. Please note, there is no way to write English characters in a top to bottom direction using MS Visio. Aspose.Diagram API mimics the behavior of MS Visio. If you can manually prepare a sample Visio diagram including the desired text direction, then please provide its zip here in this forum thread. We’ll investigate and reply you appropriately.

Thanks for the reply.


I have attached a sample Visio Diagram containing a rectangle, and rotated text.

This was done by clicking the “Rotate Text” button in the Paragraph section of the Toolbar/Ribbon of Visio.

Hi Nicholas,


Thank you for supplying a sample Visio. Please use these lines of code to accomplish this task:

[.NET, C#]
// load a Visio diagram
Diagram diagram = new Diagram(@“C:\temp\text_rotated.vsdx”);
// get shape
long shapeid = 1;
Shape shape = diagram.Pages.GetPage(“Page-1”).Shapes.GetShape(shapeid);
// set orientation angle
DoubleValue deg = new DoubleValue(180, MeasureConst.DEG);
shape.TextXForm.TxtAngle = deg;
// save Visio diagram in the local storage
diagram.Save(@“C:\temp\text_rotatedOut.vsdx”, SaveFileFormat.VSDX);

We hope, this helps. Please let us know in case of any confusion or questions.

Thank you very much for the quick response, Imran!


This appears to be exactly what I need – I was unaware of the TextXForm class.

I will implement now, and let you know if I encounter any troubles.

Nick

Hi Imran,


For some reason, when I implement the TextXForm.TxtAngle of 180 deg, or 270 degrees, I do not see a difference in the output file.

I am saving as PDF.

On your side, did you see a text angle transformation work successfully with the code you provided? There isn’t much else in my code that I would identify as causing the TextAngle to not have an effect.

Thank you,
Nick

I cannot get any of the properties in the TextXForm class to affect my output diagram.


I have tried to use TxtWidth, and TxtAngle, neither has an effect in the slightest.

Can someone confirm that these are not in fact bugged?

EDIT:
In addition, I went into the original visio document I provided in this thread. I right-clicked the shape with the rotated text, and clicked “View ShapeSheet”. This showed me all of the properties for that rectangle. One of said properties was “TextAngle”. Not to my surprise, the value of this was 90. When I changed it to 180, 270 etc., the text reflected those angles.

So I am not entirely sure where to go with this now, as I have exhausted all of my options from my end …

Hi Nick,


Thank you for the details. We’ve tested your sample Visio against the latest build of Aspose.Diagram for .NET version 5.9.0 and managed to replicate the problem of setting an incorrect orientation. On my side, it sets angle of 233 degrees when setting 180 degrees and also sets 349 degrees when setting 270 degree angle. We’ve logged this problem under ticket id DIAGRAMNET-50659 in our bug tracking system. Your post has also been linked to this issue. We’ll let you know once a significant progress has been made in this regard. We’re sorry for the inconvenience caused.

imran.rafique:
On my side, it sets angle of 233 degrees when setting 180 degrees and also sets 349 degrees when setting 270 degree angle.

Hi Imran,

Per your quote above, are you saying that the TextXForm.TextAngle property does have an effect for you? For me it makes absolutely no difference. Regardless of the angle I set that to, the text itself always reads Left to Right, with zero rotation, like normal.

Additionally, thank you for creating the Issue for this. Generally speaking, how long would a solution for this take for you guys to create a patch for the community? I am just wondering.

Regards,
Nick

Hi Nick,

Thank you for the details.

nvielbig:

imran.rafique:
On my side, it sets angle of 233 degrees when setting 180 degrees and also sets 349 degrees when setting 270 degree angle.
Per your quote above, are you saying that the TextXForm.TextAngle property does have an effect for you? For me it makes absolutely no difference. Regardless of the angle I set that to, the text itself always reads Left to Right, with zero rotation, like normal.

It appears as you are using an old version of Aspose.Diagram library because on my side, it is not setting an accurate orientation. Furthermore, it is taking effect on my side. We have tested this use case against the latest version 5.9.0. If you are also using the latest version 5.9.0, then please create a sample application project and provide its zip archive in this forum thread. We’ll investigate and reply you appropriately.

nvielbig:
Additionally, thank you for creating the Issue for this. Generally speaking, how long would a solution for this take for you guys to create a patch for the community? I am just wondering.

Normally, we release a new version of Aspose.Diagram API on every month. We also keep our community tuned regarding the new changes through the blog posts there.

Please let us know in case of any other query or assistance.

Hi Imran,


I do believe I have the most recent release of Aspose Diagram, because when I view my reference to Aspose.Diagram in Visual Studio, the version is 5.9.0

Unfortunately it’s not straightforward for me to provide me a zip of my project as there are confidential db connections, etc. within.

While it does sound like there is a bug, I find it strange that we are seeing different outputs. You are using the following property Shape.TextXForm.TextAngle, correct?

Lastly, if you do not mind, try to export the file to both Visio, and PDF formats – do you see the same result in both cases? I have been using PDF, and I don’t suspect that has any impact, but I would like to know for sure. I had difficulties exporting to .vsdx format, but my end goal is PDF, so I didn’t bother troubleshooting.

Thank you!
Nick


Hi Nick,


Thank you for writing back.

Please note, you have to set the rotation angle in the unit of radian and not in degree for Shape.TextXForm.TextAngle property. Please check the following piece of code and it’s resultant PDF as well as VSDX as attached (in an archive).

C#

Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(dir + “text_rotated.vsdx”);
long shapeid = 1;
Aspose.Diagram.Shape shape = diagram.Pages.GetPage(“Page-1”).Shapes.GetShape(shapeid);
Aspose.Diagram.DoubleValue deg = new Aspose.Diagram.DoubleValue(3.1415926, MeasureConst.DEG);
shape.TextXForm.TxtAngle = deg;
diagram.Save(dir + “text_rotatedOut_180degDEG.pdf”, SaveFileFormat.PDF);
diagram.Save(dir + “text_rotatedOut_180degDEG.vsdx”, SaveFileFormat.VSDX);

For your future reference, 1º = π/180º = 0.005555556π = 0.01745329252 rad.

Hi Babar, thank you for the reply.


I do see that it appears you were successfully in rotating the word “TEXT” 180 degrees.

I have attached a class which is doing the bulk of my work here - basically I am generating a diagram based on some data passed into my method. Of course you won’t be able to run this in any way, but I was hoping you or Imran could possibly see if you see anything faulty in this code that would cause the text to not rotate.

Note that the code you should focus on is from line 76 - 89 (at least that is where the shape, and rotation is being coded).

Thank you for any help you can provide,
Nick

Hi Nick,


In your code, please substitute the following statements, and give the scenario another try on your side.

Aspose.Diagram.DoubleValue deg = new Aspose.Diagram.DoubleValue(90, MeasureConst.DEG);

with

Aspose.Diagram.DoubleValue deg = new Aspose.Diagram.DoubleValue(1.5708, MeasureConst.DEG);

In case the problem persists, you have to provide us an executable sample application replicating the issue. Please note, you do not have to provide your original project but a demo application that could allow us to replicate the issue on our side. Moreover, if your application is using database connectivity to pull some information, you can substitute it with simple DataTable which you may create dynamically in your project or even hard code the values for elaboration purposes. Please note, we will not be able to properly investigate the matter or log it for product team's review if we are unable to replicate the issue on our end.

Thank you for your understanding.

Hi Babar, I completely understand what you’re saying.


Sadly the 1.5708 made no impact either.

I will attempt to provide you with an executable sometime soon.

Nick

Hi Nick,


We are sorry to know that setting the 90 degree angle in radian didn’t help in your scenario. We will be looking forward to your sample application to re-initiate the investigation in this regard.