How to programmatically resize shape as per text?

Hi,


Thank you for contacting support. You can formulate the shape height and width as below:

[Java]
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>shape1.getXForm().getWidth().getUfe().setF(<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 0);”>“GUARD(TEXTWIDTH(TheText,Height))”<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
shape1.getXForm().getHeight().getUfe().setF(<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 0);”>“GUARD(TEXTHEIGHT(TheText,Width))”<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>);
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>

Thanks.

This works fine for resizing the shape but I am not getting the enlarged shape height.
I need this shape height to position my next shape correctly.

shape1.getXForm().getWidth().getUfe().setF(“GUARD(MAX(TEXTWIDTH(TheText),2 in))”);
shape1.getXForm().getHeight().getUfe().setF(“GUARD(TEXTHEIGHT(TheText,Width))”);
double value = shape1.getXForm().getHeight().getValue();

The shape is enlarged as per text height but it always returns default height value of - 0.18888888888888888

Please look into this.



One of my concerns is -

We will have to set this formula for each shape to provide for dynamic resizing.

shape1.getXForm().getWidth().getUfe().setF("GUARD(TEXTWIDTH(TheText,Height))"); shape1.getXForm().getHeight().getUfe().setF("GUARD(TEXTHEIGHT(TheText,Width))");

Isn't there an easier approach like setting it set from the stencil itself.
When dopping a shape manually or via automation on Visio, the formula remains intact, so cant the same thing be provided via Aspose as well?

Another approach can be to get the height of each line of text and via unitary method calculate the height for all lines and then set that as the shape height.
However, this is again a kind of hardcoding and is sensitive to different fonts.

Ideally, it would be nice to have the formula set as default somehow on all shapes.
Is there a way?




Hi,


Thank you for the inquiry.
asthac:
The shape is enlarged as per text height but it always returns default height value of - 0.18888888888888888
We have tested your scenario with the latest version 17.5 of Aspose.Diagram for Java API and it does not return a negative value. Kindly confirm which Aspose.Diagram for Java API version are you using?
asthac:
Isn’t there an easier approach like setting it set from the stencil itself.
When dopping a shape manually or via automation on Visio, the formula remains intact, so cant the same thing be provided via Aspose as well?
Each shape instance is an extended form of a master and we can edit masters in the stencil files using Aspose.Diagram for Java API. When you will load your VSS stencil and modify a master, you cannot store back a stencil in VSS format. As an alternative, you can save VSS stencil in the VSSX format. Please try the following code:

[Java]
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>String dataDir = “C:\Diagram\test2073\”;<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
String visioStencil = dataDir + “XANFLOWCHARTNEW.vss”;<br style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”><span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>Diagram diagram = <span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>new<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> Diagram(visioStencil);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>for<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”> (Master master : (Iterable) diagram.getMasters())<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
{<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
<span class=“kwrd” style=“color: rgb(0, 0, 255); font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre;”>if<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>(master.getName() == “Process”)<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
{<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
master.getPageSheet().getXForm().getWidth().getUfe().setF(“GUARD(TEXTWIDTH(TheText,Height))”);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
master.getPageSheet().getXForm().getHeight().getUfe().setF(“GUARD(TEXTHEIGHT(TheText,Width))”);<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
}<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>
}
<span style=“font-family: “Courier New”, Consolas, Courier, monospace; font-size: small; white-space: pre; background-color: rgb(255, 255, 255);”>diagram.save(dataDir + “XANFLOWCHARTNEW_2.vssx”, SaveFileFormat.VSSX);
We have tested your scenario with the latest version 17.5 of Aspose.Diagram for Java API and it does not return a negative value. Kindly confirm which Aspose.Diagram for Java API version are you using?

Sorry for the confusion.

I meant it returns a default height of 0.18888888888888888 (not a negative value).
It does not return the new height of the resized shape with the below formula-
double value = shape1.getXForm().getHeight().getValue();

How to get the new height?

Hi,


Thank you for the details. We managed to replicate the problem of not retrieving the new formulated height value. It has been logged under the ticket ID DIAGRAMJAVA-50491 in our bug tracking system. We have also linked your post to this ticket and will keep you informed regarding any available updates. We are sorry for the inconvenience caused.

Each shape instance is an extended form of a master and we can edit masters in the stencil files using Aspose.Diagram for Java API. When you will load your VSS stencil and modify a master, you cannot store back a stencil in VSS format. As an alternative, you can save VSS stencil in the VSSX format

Tried the below-

(When the initial vss has formula set)

1. In program, loaded the vss via constructor, modified master to set the formula, then saved as vssx, but continued using the same diagram object, which was saved as vssx-
-> the formula is not available when we drop the master to the page

2. In program, loaded the vss via constructor, modified master to set the formula, then saved as vssx. Now created new diagram object with the new vssx in constructor-
-> the formula is not available when we drop the master to the page

3. Saved vss as vssx - via Visio, and ensured that the masters had the formula.
In program, loaded this vssx-
-> the formula is not available when we drop master to page.

In all the 3 approaches, the shapes in the generated vsdx file do not have the formula set for height and width but have hardcoded values.

The above approaches of modifying the stencil and then using it to avoid setting the formula again - do not work for me.

My point still remains the same-
when shapes dropped via automation or manually on Visio from the same stencil, then formula is maintained, then why not via aspose?

Why using Aspose, we have to explicitly set this formula when it is already present in the
stencil.
Cant this be incorporated in Aspose?




Hi,


Thank you for the inquiry. We are working to replicate all your above mentioned issues in our environment and will get back to you soon.

Hi,

asthac:
The above approaches of modifying the stencil and then using it to avoid setting the formula again - do not work for me.

My point still remains the same-
when shapes dropped via automation or manually on Visio from the same stencil, then formula is maintained, then why not via aspose?

Why using Aspose, we have to explicitly set this formula when it is already present in the
stencil.
Thank you for the details. We have logged this problem under the ticket ID DIAGRAMJAVA-50492 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. We are sorry for the inconvenience caused.

Hi,

Thank you for being patient. The ticket ID DIAGRAMJAVA-50492 has been resolved. If there is no issue in the quality assurance phase, then this fix will be included in the next version 17.6 of Aspose.Diagram for Java API. We will notify you in this thread as soon as the new release is published.

Hi,

Thank you for being patient. In reference to the ticket ID DIAGRAMJAVA-50492, please download and try this latest Hotfix version: Aspose.Diagram for Java 17.5.1. Please also let us know how that goes on your side.

Verified the fix for DIAGRAMJAVA-50492 in the hotfix version.

The fix is workig fine- the height/width formula remains intact from the stencil.

Thanks.

Hi,


Thank you for the confirmation. It is nice to hear from you that the issue has been resolved. Please let us know in case of any further assistance or questions.

Your welcome.

Just a reminder, I am still waiting for DIAGRAMJAVA-50491 to get fixed. :slight_smile:

Hi,


Thank you for the inquiry. The linked ticket ID DIAGRAMJAVA-50491 is pending for the analysis and not resolved yet. Our product team will investigate it as per the development schedule. We will share details when a significant progress has been made in this regard.

Hi @imran.rafique

DIAGRAMJAVA-50492: Maintain height and width formula of a shape dropped from stencil
This was fixed and released in Aspose v17.6.

However, it is again broken in v17.7
Problem is that width formula of any shape in the shape transform is not maintained and is again set as hardcoded value.
This applies to all the shapes and is not specific to just loop limit shape.

Please check.

Thanks,
Astha

@asthac,
We have re-evaluated your ticket ID DIAGRAMJAVA-50492 with the latest version 17.7 of Aspose.Diagram for Java API. We can see the height and width formulas in the shapesheet of the VSDX drawing. This is the output VSDX drawing: Output17.7.zip (79.2 KB). However, if you can reproduce the same problem of hard-coded values, then kindly share the complete details of the use case. We will investigate and share our findings with you.

Best Regards,
Imran Rafique

@imran.rafique

PFA the test case for hardcoded Width in shape transform section of shapesheet
(With v17.7 of Aspose.Diagram for Java API).

WidthFormulaNotInherited.zip (153.3 KB)

Thanks.

@asthac,
We managed to replicate the problem of the missing width formula of the shapes. It has been logged under the ticket ID DIAGRAMJAVA-50525 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. We are sorry for the inconvenience caused.

Best Regards,
Imran Rafique

@asthac,
The ticket ID DIAGRAMJAVA-50525 has been resolved. If there is no issue in the quality assurance phase, then this fix will be included in the next version 17.8 of Aspose.Diagram for Java API. We will notify you once the new version is published.

Best Regards,
Imran Rafique