Changing size of text inside Shape

I can’t get the size of the text inside a shape to update. I have tried Shape.TextXForm.TxtHeight, that didn’t make the size increase/decrease.


Thanks

Hi Nicholas,


Thank you for contacting support. Please note, you can get a shape by id and then update its font size as narrated in this help topic: Apply Different Style on the Each Text Value of a Shape

In case, this does not help, then please attach a zip archive of your Visio diagram to your reply post. We’ll investigate and let you know about our findings.

Imran, thanks for your reply.


The code used is below.
The line with legendShape.Chars[0].Size.Value = 36; doesn’t seem to have any effect on the shape. Additionally, legendShape.Chars[0].Style.Value = StyleValue.Bold | StyleValue.Italic; doesn’t have an effect on the shape’s text, either.

private void AddPogHeaderInformationToDiagram(Diagram diagram, double x, double y)
{
Shape legendShape = new Shape();

// Add planogram header information to top of diagram
legendShape.Text.Value.Add(new Txt((string.Format("Planogram ID: {0} " + Environment.NewLine + “Planogram Name: {1}”, this.Planogram.PogId, this.Planogram.PogName))));
legendShape.Chars.Add(new Aspose.Diagram.Char());
legendShape.Chars[0].Style.Value = StyleValue.Bold | StyleValue.Italic;
legendShape.Chars[0].Size.Value = 36;
legendShape.SetHeight(.5);
legendShape.Fill.FillForegnd.Value = “#DEC2B8”;
legendShape.SetWidth(5);
legendShape.XForm.PinX.Value = x + 5;
legendShape.XForm.PinY.Value = y;
diagram.AddShape(legendShape, “Rectangle”, 0);
}

Hi Nicholas,


Thank you for the details. It is necessary to add a Char element while setting a shape’s text because it defines formatting attributes. For example, you may add a new shape as below:

[.NET, C#]
// Create a new diagram
Diagram diagram = new Diagram(@“c:\ad\test720\Drawing1.vsdx”);

// Get page by name
Aspose.Diagram.Page page = diagram.Pages.GetPage(“Page-1”);

// Page indexing starts from 0
int PageIndex = 0;
double width = 2, height = 2, pinX = 4.25, pinY = 4.5;
// Add a new rectangle shape
long rectangleId = diagram.AddShape(pinX, pinY, width, height, “Rectangle”, PageIndex);

// Set shape properties
Aspose.Diagram.Shape rectangle = page.Shapes.GetShape(rectangleId);
rectangle.XForm.PinX.Value = 5;
rectangle.XForm.PinY.Value = 5;
rectangle.Type = TypeValue.Shape;
rectangle.Text.Value.Add(new Cp(0));
rectangle.Text.Value.Add(new Txt(“Aspose Diagram”));
rectangle.TextStyle = diagram.StyleSheets[3];
rectangle.Line.LineColor.Value = “#ff0000”;
rectangle.Line.LineWeight.Value = 0.03;
rectangle.Line.Rounding.Value = 0.1;
rectangle.Fill.FillBkgnd.Value = “#ff00ff”;
rectangle.Fill.FillForegnd.Value = “#ebf8df”;
// add a character element
rectangle.Chars.Add(new Aspose.Diagram.Char());

// Set properties e.g. color, font, size and style etc.
rectangle.Chars[0].IX = 0;
rectangle.Chars[0].Color.Value = “#FF0000”;
rectangle.Chars[0].Font.Value = 4;
rectangle.Chars[0].Size.Value = 0.5;
rectangle.Chars[0].Style.Value = StyleValue.Bold;

diagram.Save(@“c:\ad\test720\Output.vsdx”, SaveFileFormat.VSDX);

If this does not help, then please prepare a simple console application which reproduces this issue on your side and provide its zip archive in this forum thread for testing purposes. We'll investigate and reply you appropriately.

Hi Imran,


I’ll give your explanation a go and let you know the outcome.



Regards

Nick

Hi Nick,


Sure, please take your time and let us know about your outcomes. We’ll be happy to help you in using Aspose.Diagram API in your application projects.

Imran-


I tried to implement styling through the Char property as you mentioned. However, I cannot get any changes to the text to come through.

I have tried bolding, font size increase/decrease, underlining, etc. and nothing ends up on the PDF.

My code is below:
private void AddPogHeaderInformationToDiagram(Diagram diagram, double x, double y)
{
Shape headerInformationShape = new Shape();

// Add planogram header information to top of diagram
headerInformationShape.Text.Value.Add(new Cp(0));
headerInformationShape.Text.Value.Add(new Txt(string.Format("Planogram ID: {0} " + Environment.NewLine + “Planogram Name: {1}”, this.Planogram.PogId, this.Planogram.PogName)));
headerInformationShape.SetHeight(.5);
headerInformationShape.Fill.FillForegnd.Value = “#DEC2B8”;
headerInformationShape.SetWidth(5);
headerInformationShape.XForm.PinX.Value = x + 5;
headerInformationShape.XForm.PinY.Value = y;
headerInformationShape.Chars.Add(new Aspose.Diagram.Char());
headerInformationShape.Chars[0].Size.Value = 20;
headerInformationShape.Chars[0].Font.Value = 20;
diagram.AddShape(headerInformationShape, “Rectangle”, 0);
}


Unfortunately I am not really able to prepare a console application for you to test this locally. But this is still something I need to find a solution for. Without a console application, can you think of anything else that may be causing styles to not show on the text? I made sure there was no code after my function AddPogHeaderInformationToDiagram() that would be clearing styles from the text inside the shape.
Hi Nick,

Thank you for the code example. Please modify your code as below and let us know how that goes on your side.

[.NET, C#]
private void AddPogHeaderInformationToDiagram(Diagram diagram, double x, double y) { Shape headerInformationShape = new Shape();
// Add planogram header information to top of diagram headerInformationShape.Text.Value.Add(new Cp(0)); headerInformationShape.Text.Value.Add(new Txt(string.Format("Planogram ID: {0} " + Environment.NewLine + "Planogram Name: {1}", this.Planogram.PogId, this.Planogram.PogName))); headerInformationShape.SetHeight(.5); headerInformationShape.Fill.FillForegnd.Value = "#DEC2B8"; headerInformationShape.SetWidth(5); headerInformationShape.XForm.PinX.Value = x + 5; headerInformationShape.XForm.PinY.Value = y;

headerInformationShape.Chars.Add(new Aspose.Diagram.Char());
headerInformationShape.Chars[0].IX = 0;
// API takes size and font values in inches
// 20 is a large value, you may convert it to points headerInformationShape.Chars[0].Size.Value = 20; headerInformationShape.Chars[0].Font.Value = 20; diagram.AddShape(headerInformationShape, "Rectangle", 0); }

Please let us know in case of any confusion or questions.

What does the .IX property affect?

Hi Nick,

Well, please note that the multiple Char elements represent the multiple Character rows. Each has an IX attribute describing the relative order of the rows. For more details, please check this help topic: [Working with a Shape’s Text] (https://msdn.microsoft.com/en-us/library/office/ff767313(v=office.14).aspx)