Cannot access text formatting information (1470)

Hi,

In the attached file, I’m trying to access text formatting information of a shape, but I’m unable to get it for the first part of the text which is bold.

Code:

Diagram diagram = new Diagram("DB struct.vsdx");

Shape shape = diagram.getPages().get(0).getShapes().get(0);

FormatTxtCollection txtCollection = shape.getText().getValue();

for (int i = 0; i < txtCollection.getCount(); i++) {

    FormatTxt formatTxt = txtCollection.get(i);

    System.out.println(formatTxt.getValue());
}

System.out.println("CharCollection:");

CharCollection charCollection = shape.getChars();

for (int i = 0; i < charCollection.getCount(); i++) {
    
    Char ch = charCollection.get(i);
    
    System.out.println(ch.getIX());
    
}

Output:

<cp IX="0"/>
<pp IX="0"/>
<tp IX="0"/>
StanSeeds 
<cp IX="1"/>
DataBase
<cp IX="2"/>


CharCollection:
1
2

Can you check this?

Thanks,
Zeljko

DB struct.vsdx.zip (19.7 KB)

@Zeljko,

Please get style value of the Char element, it is 17 for the Bold text:

ch.getStyle().getValue();

Hi Imran,

Sorry, I wanted to ask how can I access the formatting of “StanSeeds” text in the shape?

In CharCollection, I have only two chars, IX=1 and IX=2. There’s no char IX=0.

Thanks,
Zeljko

@Zeljko,

Char Element contains the formatting attributes of the shape’s text. The Visio shape has three Char elements because there are three parts of the shape’s text. However, there is no text string in one of the text parts and it may not require to define Char element for this. However, we can sense difficulty to retrieve the right Char element of the text part. We have logged an enhancement under the ticket ID DIAGRAMJAVA-50587 in our issue tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

An updates Java code example for your reference:
Java

String dataDir = "C:\\Diagram\\test2353\\";		
Diagram diagram = new Diagram(dataDir + "DB struct.vsdx");
Shape shape = diagram.getPages().get(0).getShapes().getShape(3);
FormatTxtCollection txtCollection = shape.getText().getValue();
for (int i = 0; i < txtCollection.getCount(); i++) 
{
    FormatTxt formatTxt = txtCollection.get(i);
    Txt tx = (Txt)((formatTxt instanceof Txt) ? formatTxt : null);
    //System.out.println(formatTxt.getValue());
    if (tx != null)
    	System.out.println("Index: " +i+ " Text: " +tx.getText());
}
System.out.println("CharCollection:" + shape.getChars().getCount());
CharCollection charCollection = shape.getChars();
for (Char ch : (Iterable<Char>) charCollection)	
	System.out.println(ch.getIX() + " - "+ ch.getStyle().getValue());

@Zeljko,

The linked ticket ID DIAGRAMJAVA-50587 has been resolved and included in the full version 18.2 of Aspose.Diagram for Java API. Please download and try the latest version 18.2 of Aspose.Diagram for Java API.