diff --git a/src/ACadSharp/Entities/IText.cs b/src/ACadSharp/Entities/IText.cs index 2fe026fb..3a5e4730 100644 --- a/src/ACadSharp/Entities/IText.cs +++ b/src/ACadSharp/Entities/IText.cs @@ -1,4 +1,5 @@ using ACadSharp.Tables; +using CSMath; namespace ACadSharp.Entities { @@ -23,6 +24,19 @@ public interface IText /// /// Style of this text entity. /// - TextStyle Style { get; set; } + TextStyle Style { get; set; } + + /// + /// First alignment point(in OCS). + /// + XYZ InsertPoint { get; set; } + + /// + /// X-axis direction vector(in WCS). + /// + /// + /// A group code 50 (rotation angle in radians) passed as DXF input is converted to the equivalent direction vector (if both a code 50 and codes 11, 21, 31 are passed, the last one wins). This is provided as a convenience for conversions from text objects + /// + XYZ AlignmentPoint { get; set; } } } \ No newline at end of file diff --git a/src/ACadSharp/Entities/MText.cs b/src/ACadSharp/Entities/MText.cs index 7f55e5ba..3af1a8dc 100644 --- a/src/ACadSharp/Entities/MText.cs +++ b/src/ACadSharp/Entities/MText.cs @@ -2,6 +2,7 @@ using ACadSharp.Tables; using CSMath; using System; +using System.Collections; namespace ACadSharp.Entities { @@ -102,22 +103,9 @@ public TextStyle Style } } - /// - /// X-axis direction vector(in WCS) - /// - /// - /// A group code 50 (rotation angle in radians) passed as DXF input is converted to the equivalent direction vector (if both a code 50 and codes 11, 21, 31 are passed, the last one wins). This is provided as a convenience for conversions from text objects - /// + /// [DxfCodeValue(11, 21, 31)] - public XYZ AlignmentPoint - { - get => this._alignmentPoint; - set - { - this._alignmentPoint = value; - this._rotation = new XY(this._alignmentPoint.X, this._alignmentPoint.Y).GetAngle(); - } - } + public XYZ AlignmentPoint { get; set; } /// /// Horizontal width of the characters that make up the mtext entity. @@ -145,18 +133,10 @@ public XYZ AlignmentPoint /// The rotation angle in radians. /// [DxfCodeValue(DxfReferenceType.IsAngle, 50)] - public double Rotation - { - get => this._rotation; - set - { - this._rotation = value; - this.AlignmentPoint = new XYZ(Math.Cos(this._rotation), Math.Sin(this._rotation), 0.0); - } - } + public double Rotation { get; set; } = 0.0; /// - /// Mtext line spacing style + /// Mtext line spacing style. /// [DxfCodeValue(73)] public LineSpacingStyleType LineSpacingStyle { get; set; } @@ -203,10 +183,6 @@ public double Rotation private double _height = 1.0; - private XYZ _alignmentPoint = XYZ.AxisX; - - private double _rotation = 0.0; - private TextStyle _style = TextStyle.Default; /// @@ -218,6 +194,18 @@ public override BoundingBox GetBoundingBox() return new BoundingBox(this.InsertPoint); } + /// + /// Get the text value separated in lines. + /// + /// + public string[] GetTextLines() + { + return this.Value.Split( + new string[] { "\r\n", "\r", "\n" }, + StringSplitOptions.None + ); + } + /// public override CadObject Clone() { diff --git a/src/ACadSharp/Entities/TextEntity.cs b/src/ACadSharp/Entities/TextEntity.cs index 0f1e5613..3474a9cf 100644 --- a/src/ACadSharp/Entities/TextEntity.cs +++ b/src/ACadSharp/Entities/TextEntity.cs @@ -31,9 +31,7 @@ public class TextEntity : Entity, IText [DxfCodeValue(39)] public double Thickness { get; set; } = 0.0; - /// - /// First alignment point(in OCS) - /// + /// [DxfCodeValue(10, 20, 30)] public XYZ InsertPoint { get; set; } = XYZ.Zero; @@ -134,7 +132,7 @@ public TextStyle Style public TextHorizontalAlignment HorizontalAlignment { get; set; } = TextHorizontalAlignment.Left; /// - /// Second alignment point (in OCS) + /// Second alignment point (in OCS). /// /// /// This value is meaningful only if the value of a 72 or 73 group is nonzero (if the justification is anything other than baseline/left) @@ -156,7 +154,7 @@ public TextStyle Style private string _value = string.Empty; - private double _height = 0.0; + private double _height = 1.0; private TextStyle _style = TextStyle.Default;