Rectangle's width and height from text size

Hi, I want to add a rectangle with size exactly like the text it would contain [without any line breaks]. Is that possible?
If I use
rectangle.getXForm().getWidth().getUfe().setF(“TEXTWIDTH(TheText)”);
rectangle.getXForm().getHeight().getUfe().setF(“TEXTHEIGHT(TheText,Width))”);
shape is to wide, if I don’t use I get line breaks.

SizeFromText.zip (1.7 MB)

@Lukasz_Dobrzynski

We are checking it and will get back to you shortly.

@Lukasz_Dobrzynski

Please add this sample code to set text’s font and size in your code:

// set shape properties
Shape rectangle = page.getShapes().getShape(rectangleId);
rectangle.getXForm().getPinX().setValue(5);
rectangle.getXForm().getPinY().setValue(5);
rectangle.setType(TypeValue.SHAPE);
rectangle.getText().getValue().add(new Txt("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
//Setting char
rectangle.getChars().add(new Char());
rectangle.getChars().get(0).setIX(0);
rectangle.getChars().get(0).getFont().setValue(4);
rectangle.getChars().get(0).getSize().setValue( 0.16667);

“xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” is only an example. I get texts from the external source. What size should I set for all the strings different than “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”?

@Lukasz_Dobrzynski

We will further investigate this scenario and will let you know soon.

@Lukasz_Dobrzynski

Please use the default size of 0.16667inch,which is 12pt. If it does not fit, please adjust the size according to the actual situation.

please adjust the size according to the actual situation.

Ok, please tell me how to automatically adjust i.e. calculate the size of the rectangle using the text coming from the external source using your library.

@Lukasz_Dobrzynski

Please set the default font size first. Then using rectangle.RefreshData(); will calculate the size of the rectangle automatically. If you still have issue, please provide sample code.

Hi, apparently you missed that the code I provided the first time was already calling refreshData - line 53. I added all of your suggestions and changed the String to the longer one and it didn’t work - I got line breaks. Please attach the java code you used to test that your suggestions are working for String of any length.

@Lukasz_Dobrzynski

We are checking it and will get back to you shortly.

@Lukasz_Dobrzynski

Please check the attached Java Code and generated output VSDX file from our testing and let us know about your feedback.

files.zip (1.0 MB)

Hi, ok, that works in this example, I still have an issue in my application, but think don’t get the correct shape size, but it appears to be caused now by Fit to sheet(s) across/sheet(s) down - #7 by asad.ali. Anyway, this ticket can be closed, thanks.

@Lukasz_Dobrzynski

Thanks for the feedback. We have responded to your other inquiry related to Fit to sheet(s) across/sheet(s) down. You can please check our response and share your feedback there.

Hi, I found one additional issue. In the code I changed the text to
private String text = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxx”;
So 2 lines - but it appears as the width is computed as there would be no line break and everything was in 1 line.

@Lukasz_Dobrzynski

Did you try the same code snippet that we shared earlier in one of our replies?

Hi, yes: https://drive.google.com/file/d/1si0Siu6gn6e1sWBdTNCsf7_WDLJFMkJf/view?usp=sharing.

@Lukasz_Dobrzynski

We have logged an investigation ticket to further check why API is ignoring the line break in the string. The ticket ID is DIAGRAMJAVA-50997 and it has been linked with this forum thread. You will be notified as soon as the ticket is resolved. Please spare us some time.

We are sorry for the inconvenience.

@Lukasz_Dobrzynski

Please make sure that the compiler such as eclipse will add extra slashes to make

private String text = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxx";

Make sure there is only one slash in the string.

The string in the your result file contain the character \n?

Please check the screenshot of the file generated by 22.6 in the attachment.
50997.PNG (3.5 KB)

Hi, I’m not sure what you’re asking for.
As I wrote 10 days ago: the line is
private String text = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxx”;
and as you can see there is one and only one slash in the string and I have no idea how can eclipse [intellij actually] modify this string without my knowledge.
As I also wrote before: the result is the box that has multiple lines (so new line character \n is correctly processed and the result is the same as you attached), the height is correct - so equals sum(all lines’ heights), but it’s width is also the sum - sum(all lines’ widths) to be exact when it should obviously be max(all lines’ widths).
Please clarify what exactly you’re asking for.

BR, LD

@Lukasz_Dobrzynski

We apologize for the confusion here. We investigated the ticket in terms of line breaks only. Auto calculation of the width of the text is still not correct. In order to rectify it, we have logged an issue as DIAGRAMJAVA-51005 in our issue tracking system. We will further look into its details and let you know once it is resolved. Please spare us some time.

We are sorry for the inconvenience.