How to set a new font

Hello,

to test aspose.diagram i’ve only a page with a rectangle that contains the text “Hello Text”.

Now i want to set the font to another fontname.

I can read the actual font with following code

var fontID = myShape.Chars[0].Font.Value
var fontName = myDiagram.Fonts[fontID - 1].Name

The issued name is Times New Roman.

Now i want to set the font to Arial. I tried the following:

Aspose.Diagram.Font newFont = new Aspose.Diagram.Font();
newFont.Name = "Arial";
int fontIndex = diagram.Fonts.Add(newFont);
foreach (Aspose.Diagram.Char ch in myShape.Chars)
{
	ch.Font.Value = fontIndex;
}

After saving the file and open it in Visio the font is still the old one.
Do you have an example to change the font of a shape.

regards
steve

@sgruth
Thanks for your inquiry. We will add relevant examples to the documents.
Please try this sample code:

newFont.ID = fontIndex+ 1;
foreach (Aspose.Diagram.Char ch in myShape.Chars)
{
	   ch.Font.Value = newFont.ID; 
       ch.FontName.Value = newFont.Name;   //set font name for saving vsdx
}

Thanks.

Thank you for the example. That has saved me from sleepless nights.
Now it works for me too.

@sgruth
It is great that you were able to resolve this issue on your end. In case you have further inquiries or may need any help in future, please let us know by posting a new thread in Aspose.Diagram’ forum.