Mimic the 'textbox' LISP function by P/Invoking acedTextBox but avoiding to P/Invoke acdbGetAdsName32/64 and acdbEntGet by building the ResultBuffer from the DBText properties.
The minimum required data is DBText.TextString, the default for other data is got from the Database current settings (TestSize, TextStyle).
[DllImport("accore.dll", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedTextBox")]
static extern System.IntPtr acedTextBox(IntPtr rb, double[] point1, double[] point2);
/// <summary>
/// Gets the extents of a DBText (mimics the 'textbox' LISP function)
/// </summary>
/// <param name="rb">DXF data decribing the DBText</param>
/// <returns>The diagonal of the non rotated text with insertion point at (0, 0, 0).</returns>
public static Extents3d TextBox(ResultBuffer rb)
{
var point1
= new double[3]; var point2
= new double[3]; acedTextBox(rb.UnmanagedObject, point1, point2);
return new Extents3d
(new Point3d
(point1
),
new Point3d
(point2
)); }
/// <summary>
/// Gets the WCS points of the text bounding box.
/// </summary>
/// <param name="dbText">Instance of DBText the method applies to.</param>
/// <returns>The bounding box points in counterclockwise sense.</returns>
public static Point3d[] GetTextBoxCorners(this DBText dbText)
{
if (dbText == null)
throw new ArgumentNullException
("dbText");
int mirrored = dbText.IsMirroredInX ? 2 : 0;
mirrored |= dbText.IsMirroredInY ? 4 : 0;
var rb
= new ResultBuffer
( new TypedValue
(1, dbText
.TextString),
new TypedValue
(40, dbText
.Height),
new TypedValue
(41, dbText
.WidthFactor),
new TypedValue
(51, dbText
.Oblique),
new TypedValue
(7, dbText
.TextStyleName),
new TypedValue
(71, mirrored
),
new TypedValue
(72,
(int)dbText
.HorizontalMode),
new TypedValue
(73,
(int)dbText
.VerticalMode));
var extents = TextBox(rb);
var xform =
Matrix3d.Displacement(dbText.Position.GetAsVector()) *
Matrix3d.Rotation(dbText.Rotation, dbText.Normal, Point3d.Origin) *
Matrix3d
.WorldToPlane(new Plane
(Point3d
.Origin, dbText
.Normal));
{
extents.MinPoint.TransformBy(xform),
new Point3d
(extents
.MaxPoint.X, extents
.MinPoint.Y,
0.0).TransformBy(xform
),
extents.MaxPoint.TransformBy(xform),
new Point3d
(extents
.MinPoint.X, extents
.MaxPoint.Y,
0.0).TransformBy(xform
) };
}