vb.net怎么获取多行文字包围盒
用vb.net怎么获取多行文字包围盒,只是显示的文字部分,不包含编辑框范围的。''' <summary>
''' Gets the WCS points of the mtext bounding box.
''' </summary>
''' <param name="mtext">Instance of MText the method applies to.</param>
''' <returns>The bounding box points in counterclockwise sense.</returns>
Public Shared Function GetMTextBoxCorners(mtext As MText) As Point3d()
Dim width As Double = mtext.ActualWidth
Dim height As Double = mtext.ActualHeight
Dim point1 As Point3d, point2 As Point3d
Select Case mtext.Attachment
Case AttachmentPoint.TopLeft
point1 = New Point3d(0.0, -height, 0.0)
point2 = New Point3d(width, 0.0, 0.0)
Exit Select
Case AttachmentPoint.TopCenter
point1 = New Point3d(-width * 0.5, -height, 0.0)
point2 = New Point3d(width * 0.5, 0.0, 0.0)
Exit Select
Case AttachmentPoint.TopRight
point1 = New Point3d(-width, -height, 0.0)
point2 = New Point3d(0.0, 0.0, 0.0)
Exit Select
Case AttachmentPoint.MiddleLeft
point1 = New Point3d(0.0, -height * 0.5, 0.0)
point2 = New Point3d(width, height * 0.5, 0.0)
Exit Select
Case AttachmentPoint.MiddleCenter
point1 = New Point3d(-width * 0.5, -height * 0.5, 0.0)
point2 = New Point3d(width * 0.5, height * 0.5, 0.0)
Exit Select
Case AttachmentPoint.MiddleRight
point1 = New Point3d(-width, -height * 0.5, 0.0)
point2 = New Point3d(0.0, height * 0.5, 0.0)
Exit Select
Case AttachmentPoint.BottomLeft
point1 = New Point3d(0.0, 0.0, 0.0)
point2 = New Point3d(width, height, 0.0)
Exit Select
Case AttachmentPoint.BottomCenter
point1 = New Point3d(-width * 0.5, 0.0, 0.0)
point2 = New Point3d(width * 0.5, height, 0.0)
Exit Select
Case AttachmentPoint.BottomRight
point1 = New Point3d(-width, 0.0, 0.0)
point2 = New Point3d(0.0, height, 0.0)
Exit Select
End Select
Dim xform As Matrix3d = Matrix3d.Displacement(mtext.Location.GetAsVector()) * Matrix3d.Rotation(mtext.Rotation, mtext.Normal, Point3d.Origin) * Matrix3d.PlaneToWorld(New Plane(Point3d.Origin, mtext.Normal))
Return New Point3d() {point1.TransformBy(xform), New Point3d(point2.X, point1.Y, 0.0).TransformBy(xform), point2.TransformBy(xform), New Point3d(point1.X, point2.Y, 0.0).TransformBy(xform)}
End Function tiancao100 发表于 2024-5-7 17:11
感谢感谢 /// <summary>
/// 单行文字OBB包围盒
/// </summary>
/// <param name="dBtext"></param>
/// <returns></returns>
public static RectAng GetBestTextBox(this DBText dBtext)
{
var recAng = new RectAng();
var ang = dBtext.Rotation;
var box = dBtext.GetBoundingBoxEx();
if (!box.HasValue)
return recAng;
var cenPt = box.Value.MidCenter;
var mat = Matrix3d.Rotation(-ang, Vector3d.ZAxis, cenPt);
if (dBtext.GetTransformedCopy(mat) is not DBText newDBtext)
return recAng;
var newBox = newDBtext.GetBoundingBoxEx();
if (!newBox.HasValue)
return recAng;
var rec = new Rect(newBox.Value.BottomLeft.Point2d(), newBox.Value.TopRight.Point2d());
recAng.Ang = ang;
recAng.Rec = rec;
return recAng;
}
/// <summary>
/// 多行文字OBB包围盒
/// </summary>
/// <param name="mtext"></param>
/// <returns></returns>
public static RectAng GetBestTextBox(this MText mtext)
{
var recAng = new RectAng();
var ang = mtext.Rotation;
var box = mtext.GetBoundingBoxEx();
if (!box.HasValue)
return recAng;
var cenPt = box.Value.MidCenter;
var mat = Matrix3d.Rotation(-ang, Vector3d.ZAxis, cenPt);
if (mtext.GetTransformedCopy(mat) is not DBText newMtext)
return recAng;
var newBox = newMtext.GetBoundingBoxEx();
if (!newBox.HasValue)
return recAng;
var rec = new Rect(newBox.Value.BottomLeft.Point2d(), newBox.Value.TopRight.Point2d());
recAng.Ang = ang;
recAng.Rec = rec;
return recAng;
}
页:
[1]