使用文本框
在 Visio 形状的文本块部分设置文本格式
Aspose.Diagram API 允许开发人员控制文本方向、对齐方式、边距、背景颜色、背景颜色透明度以及形状文本块中文本的默认制表位位置。他们可以使用编程方式与这些属性交互Aspose.Diagram for Java.
设置形状文本块中文本的方向、对齐方式、边距、背景颜色、透明度和默认制表位
Visio 形状表的文本块格式部分包含格式信息。这形状课程优惠文本块属性以获取或设置形状文本的视觉外观。
格式文本编程示例
以下代码段设置方向、对齐方式、边距、背景颜色、背景颜色透明度以及方向角的默认制表位位置和形状文本在顶部的位置。
// 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(FormatShapeTextBlockSection.class); | |
// load source Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
// get the page by its name | |
Page page1 = diagram.getPages().getPage("Page-1"); | |
// get shape by its ID | |
Shape shape = page1.getShapes().getShape(1); | |
// set orientation angle | |
DoubleValue margin = new DoubleValue(4, MeasureConst.PT); | |
// set left, right, top and bottom margins of the shape's text block | |
shape.getTextBlock().setLeftMargin(margin); | |
shape.getTextBlock().setRightMargin(margin); | |
shape.getTextBlock().setTopMargin(margin); | |
shape.getTextBlock().setBottomMargin(margin); | |
// set the text direction | |
shape.getTextBlock().getTextDirection().setValue(TextDirectionValue.VERTICAL); | |
// set the text alignment | |
shape.getTextBlock().getVerticalAlign().setValue(VerticalAlignValue.MIDDLE); | |
// set the text block background color | |
shape.getTextBlock().getTextBkgnd().getUfe().setF("RGB(95,108,53)"); | |
// set the background color transparency in percent | |
shape.getTextBlock().getTextBkgndTrans().setValue(50); | |
// set the distance between default tab stops for the selected shape. | |
shape.getTextBlock().getDefaultTabStop().setValue(2); | |
// save Visio | |
diagram.save(dataDir + "FormatShapeTextBlockSection_Out.vsdx", SaveFileFormat.VSDX); |
旋转和设置形状文本的位置
Aspose.Diagram API 允许开发人员调整文本位置并旋转 Visio 形状上的文本。为完成此任务,形状表上的文本转换部分提供了 TxtPin、TxtLocPin、TxtWidth 和 TxtHeight 属性。开发人员可以使用 Aspose.Diagram API 以编程方式与这些属性进行交互。
文本转换部分包含有关形状文本块的位置信息。这些示例展示了如何调整形状文本位置和方向角度:
将形状的文本位置设置在顶部
以下代码段设置形状文本在顶部的方向角度和位置。
// 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(SetShapeTextPositionAtTop.class); | |
// load source Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
// get shape | |
long shapeid = 1; | |
Shape shape = diagram.getPages().getPage("Page-1").getShapes().getShape(shapeid); | |
// set text position at the top, | |
// TxtLocPinY = "TxtHeight*0" and TxtPinY = "Height*1" | |
shape.getTextXForm().getTxtLocPinY().setValue(0); | |
shape.getTextXForm().getTxtPinY().setValue(shape.getXForm().getHeight().getValue()); | |
// set orientation angle | |
double angleDeg = 0; | |
double angleRad = (Math.PI / 180) * angleDeg; | |
shape.getTextXForm().getTxtAngle().setValue(angleRad); | |
// save Visio diagram in the local storage | |
diagram.save(dataDir + "SetShapeTextPositionAtTop_Out.vsdx", SaveFileFormat.VSDX); |
将形状的文本位置设置在底部
以下代码段设置形状文本在底部的方向角度和位置。
// 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(SetShapeTextPositionAtBottom.class); | |
// load source Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
// get shape | |
long shapeid = 1; | |
Shape shape = diagram.getPages().getPage("Page-1").getShapes().getShape(shapeid); | |
// set text position at the bottom, | |
// TxtLocPinY = "TxtHeight*1" and TxtPinY = "Height*0" | |
shape.getTextXForm().getTxtLocPinY().setValue(shape.getTextXForm().getTxtHeight().getValue()); | |
shape.getTextXForm().getTxtPinY().setValue(0); | |
// set orientation angle | |
double angleDeg = 0; | |
double angleRad = (Math.PI / 180) * angleDeg; | |
shape.getTextXForm().getTxtAngle().setValue(angleRad); | |
// save Visio diagram in the local storage | |
diagram.save(dataDir + "SetShapeTextPositionAtBottom_Out.vsdx", SaveFileFormat.VSDX); |
将形状的文本位置设置在左侧
以下代码段设置形状文本在左侧的方向角度和位置。
// 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(SetShapeTextPositionAtLeft.class); | |
// load source Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
// get shape | |
long shapeid = 1; | |
Shape shape = diagram.getPages().getPage("Page-1").getShapes().getShape(shapeid); | |
// set text position at the left, | |
// TxtLocPinX = "TxtWidth*1" and TxtPinX = "Width*0" | |
shape.getTextXForm().getTxtLocPinX().setValue(shape.getTextXForm().getTxtWidth().getValue()); | |
shape.getTextXForm().getTxtPinX().setValue(0); | |
// set orientation angle | |
double angleDeg = 0; | |
double angleRad = (Math.PI / 180) * angleDeg; | |
shape.getTextXForm().getTxtAngle().setValue(angleRad); | |
// save Visio diagram in the local storage | |
diagram.save(dataDir + "SetShapeTextPositionAtLeft_Out.vsdx", SaveFileFormat.VSDX); |
将形状的文本位置设置在右侧
以下代码段设置形状文本在右侧的方向角度和位置。
// 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(SetShapeTextPositionAtRight.class); | |
// load source Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
// get shape | |
long shapeid = 1; | |
Shape shape = diagram.getPages().getPage("Page-1").getShapes().getShape(shapeid); | |
// set text position at the right, | |
// TxtLocPinX = "TxtWidth*0" and TxtPinX = "Width*1" | |
shape.getTextXForm().getTxtLocPinX().setValue(0); | |
shape.getTextXForm().getTxtPinX().setValue(shape.getXForm().getWidth().getValue()); | |
// set orientation angle | |
double angleDeg = 0; | |
double angleRad = (Math.PI / 180) * angleDeg; | |
shape.getTextXForm().getTxtAngle().setValue(angleRad); | |
// save Visio diagram in the local storage | |
diagram.save(dataDir + "SetShapeTextPositionAtRight_Out.vsdx", SaveFileFormat.VSDX); |