计算引脚值和设置形状的大小

计算子形状的 PinX 和 PinY 值

如果形状是组形状的孩子,它的 xform 是它的父形状的相对坐标,但不是绝对坐标.如果用户需要获取绝对坐标,则此示例代码会有所帮助。

通过按以下顺序应用以下转换,可以将局部坐标中指定的点转换为父坐标:

  1. 从 x 坐标中减去 Cell_Type 元素的 LocPinX 属性值。
  2. 从 y 坐标中减去 Cell_Type 的 LocPinY 属性值。
  3. 如果 Cell_Type 的 FlipX 属性的值等于 1,则镜像关于 y 轴的点。
  4. 如果 Cell_Type 的 FlipY 属性的值等于 1,则镜像关于 x 轴的点。
  5. 根据 Cell_Type 的 Angle 属性的值,围绕原点逆时针旋转该点。
  6. 将 PinX Cell_Type 的值添加到 x 坐标。
  7. 将 PinY Cell_Type 的值添加到 y 坐标。

计算 PinX 和 PinY 编程示例

在您的 Java 应用程序中使用以下代码,使用 Aspose.Diagram for Java API 计算子形状的 PinX 和 PinY 值。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(CalculateCenterOfSubShapes.class);
// load Visio diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
// get group shape
Shape shape = diagram.getPages().get(0).getShapes().getShape(138);
// get sub-shape of the group shape
Shape subShape = shape.getShapes().getShape(140);
AffineTransform m = new AffineTransform();
// apply the translation vector
m.translate(-(float)subShape.getXForm().getLocPinX().getValue(), -(float)subShape.getXForm().getLocPinY().getValue());
// set the elements of that matrix to a rotation
m.rotate((float)subShape.getXForm().getAngle().getValue());
// apply the translation vector
m.translate((float)subShape.getXForm().getPinX().getValue(), (float)subShape.getXForm().getPinY().getValue());
// get pinx and piny
double pinx = m.getTranslateX();
double piny = m.getTranslateY();
// calculate the sub-shape pinx and piny
double resultx = shape.getXForm().getPinX().getValue() - shape.getXForm().getLocPinX().getValue() - pinx;
double resulty = shape.getXForm().getPinY().getValue() - shape.getXForm().getLocPinY().getValue() - piny;

设置形状的高度和宽度

形状类允许您通过使用 SetHeight 和 SetWidth 方法指定形状的高度和宽度来控制形状大小。

SetHeight 和 SetWidth 方法,由形状类,支持带母版、无母版或组形变大。

本文中的代码示例设置高度和宽度以调整页面上形状的大小。

输入 diagram

待办事项:图片_替代_文本

改变高度和宽度后的diagram

待办事项:图片_替代_文本

设置Height和Width的过程是:

  1. 加载一个 diagram。
  2. 找到一个特定的形状。
  3. 设置形状的高度。
  4. 设置形状的宽度。
  5. 保存 diagram。

设置高度和宽度编程示例

下面的代码片段显示了如何设置形状的高度和宽度。该代码查找形状名称为矩形且形状 ID 为 1 的矩形,并将其高度和宽度设置为双精度值。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ChangeShapeSize.class);
// call a Diagram class constructor to load the VSDX diagram
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
// get page by name
Page page = diagram.getPages().getPage("Page-1");
// get shape by id
Shape shape = page.getShapes().getShape(796);
// alter the size of Shape
shape.setWidth(2 * shape.getXForm().getWidth().getValue());
shape.setHeight(2 * shape.getXForm().getHeight().getValue());
// save diagram
diagram.save(dataDir + "ChangeShapeSize_Out.vsdx", SaveFileFormat.VSDX);