• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 25000885590

27 Apr 2026 02:27PM UTC coverage: 77.062% (-0.01%) from 77.074%
25000885590

push

github

web-flow
Merge pull request #1047 from DomCR/issue/1045_textenity-value-length-fix

Issue-1045 text length limit

8456 of 11921 branches covered (70.93%)

Branch coverage included in aggregate %.

95 of 135 new or added lines in 1 file covered. (70.37%)

24 existing lines in 2 files now uncovered.

30448 of 38563 relevant lines covered (78.96%)

153246.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.56
/src/ACadSharp/Entities/TextEntity.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Tables;
3
using CSMath;
4
using CSUtilities.Extensions;
5
using System;
6
using System.Collections.Generic;
7

8
namespace ACadSharp.Entities;
9

10
/// <summary>
11
/// Represents a <see cref="TextEntity"/>
12
/// </summary>
13
/// <remarks>
14
/// Object name <see cref="DxfFileToken.EntityText"/> <br/>
15
/// Dxf class name <see cref="DxfSubclassMarker.Text"/>
16
/// </remarks>
17
[DxfName(DxfFileToken.EntityText)]
18
[DxfSubClass(DxfSubclassMarker.Text)]
19
public class TextEntity : Entity, IText
20
{
21
        /// <summary>
22
        /// Second alignment point (in OCS)
23
        /// </summary>
24
        /// <remarks>
25
        /// 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)
26
        /// </remarks>
27
        [DxfCodeValue(DxfReferenceType.Optional, 11, 21, 31)]
28
        public XYZ AlignmentPoint { get; set; }
6,921✔
29

30
        /// <inheritdoc/>
31
        [DxfCodeValue(40)]
32
        public double Height
33
        {
34
                get => this._height;
5,224✔
35
                set
36
                {
23,153✔
37
                        if (value <= 0)
23,153!
NEW
38
                                throw new ArgumentOutOfRangeException(nameof(value), value, "The Text height must be greater than zero.");
×
39
                        else
40
                                this._height = value;
23,153✔
41
                }
23,153✔
42
        }
43

44
        /// <summary>
45
        /// Horizontal text justification type.
46
        /// </summary>
47
        [DxfCodeValue(72)]
48
        public TextHorizontalAlignment HorizontalAlignment { get; set; } = TextHorizontalAlignment.Left;
23,943✔
49

50
        /// <summary>
51
        /// First alignment point(in OCS)
52
        /// </summary>
53
        [DxfCodeValue(10, 20, 30)]
54
        public XYZ InsertPoint { get; set; } = XYZ.Zero;
129,564✔
55

56
        /// <summary>
57
        /// Mirror flags.
58
        /// </summary>
59
        [DxfCodeValue(71)]
60
        public TextMirrorFlag Mirror { get => this._mirror; set => this._mirror = value; }
3,255✔
61

62
        /// <summary>
63
        /// Specifies the three-dimensional normal unit vector for the object.
64
        /// </summary>
65
        [DxfCodeValue(210, 220, 230)]
66
        public XYZ Normal { get; set; } = XYZ.AxisZ;
32,396✔
67

68
        /// <inheritdoc/>
69
        public override string ObjectName => DxfFileToken.EntityText;
29,460✔
70

71
        /// <inheritdoc/>
72
        public override ObjectType ObjectType => ObjectType.TEXT;
97✔
73

74
        /// <summary>
75
        /// Specifies the oblique angle of the object.
76
        /// </summary>
77
        /// <value>
78
        /// The angle in radians within the range of -85 to +85 degrees. A positive angle denotes a lean to the right; a negative value will have 2*PI added to it to convert it to its positive equivalent.
79
        /// </value>
80
        [DxfCodeValue(DxfReferenceType.IsAngle, 51)]
81
        public double ObliqueAngle { get; set; } = 0.0;
26,383✔
82

83
        /// <inheritdoc/>
84
        [DxfCodeValue(DxfReferenceType.IsAngle, 50)]
85
        public double Rotation { get; set; }
5,109✔
86

87
        /// <inheritdoc/>
88
        [DxfCodeValue(DxfReferenceType.Name | DxfReferenceType.Optional, 7)]
89
        public TextStyle Style
90
        {
91
                get { return this._style; }
73,314✔
92
                set
93
                {
9,184✔
94
                        if (value == null)
9,184!
UNCOV
95
                        {
×
NEW
96
                                throw new ArgumentNullException(nameof(value));
×
97
                        }
98

99
                        if (this.Document != null)
9,184✔
100
                        {
8,035✔
101
                                this._style = CadObject.updateCollection(value, this.Document.TextStyles);
8,035✔
102
                        }
8,035✔
103
                        else
104
                        {
1,149✔
105
                                this._style = value;
1,149✔
106
                        }
1,149✔
107
                }
9,184✔
108
        }
109

110
        /// <inheritdoc/>
111
        public override string SubclassMarker => DxfSubclassMarker.Text;
132,562✔
112

113
        /// <summary>
114
        /// Specifies the distance a 2D object is extruded above or below its elevation.
115
        /// </summary>
116
        [DxfCodeValue(39)]
117
        public double Thickness { get; set; } = 0.0;
27,293✔
118

119
        /// <inheritdoc/>
120
        [DxfCodeValue(1)]
121
        public string Value
122
        {
123
                get
124
                {
976✔
125
                        return this._value;
976✔
126
                }
976✔
127
                set
128
                {
21,742✔
129
                        this._value = value;
21,742✔
130
                }
21,742✔
131
        }
132

133
        /// <summary>
134
        /// Vertical text justification type.
135
        /// </summary>
136
        [DxfCodeValue(DxfReferenceType.Optional, 73)]
137
        public virtual TextVerticalAlignmentType VerticalAlignment { get; set; } = TextVerticalAlignmentType.Baseline;
23,112✔
138

139
        /// <summary>
140
        /// Relative X scale factor—widt
141
        /// </summary>
142
        /// <remarks>
143
        /// This value is also adjusted when fit-type text is used
144
        /// </remarks>
145
        [DxfCodeValue(DxfReferenceType.Optional, 41)]
146
        public double WidthFactor { get; set; } = 1.0;
26,387✔
147

148
        private double _height = 1.0d;
21,776✔
149

150
        private TextMirrorFlag _mirror = TextMirrorFlag.None;
21,776✔
151

152
        private TextStyle _style = TextStyle.Default;
21,776✔
153

154
        private string _value = string.Empty;
21,776✔
155

156
        public TextEntity() : base()
21,776✔
157
        {
21,776✔
158
        }
21,776✔
159

160
        /// <inheritdoc/>
161
        public override void ApplyTransform(Transform transform)
162
        {
1,416✔
163
                bool mirrText = this.Mirror.HasFlag(TextMirrorFlag.Backward);
1,416✔
164

165
                XYZ newInsert = transform.ApplyTransform(this.InsertPoint);
1,416✔
166
                XYZ newNormal = this.transformNormal(transform, this.Normal);
1,416✔
167

168
                var transformation = this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
1,416✔
169

170
                List<XY> uv = this.applyRotation(
1,416✔
171
                        new[]
1,416✔
172
                        {
1,416✔
173
                                this.WidthFactor * this.Height * XY.AxisX,
1,416✔
174
                                new XY(this.Height * Math.Tan(this.ObliqueAngle), this.Height)
1,416✔
175
                        },
1,416✔
176
                        this.Rotation);
1,416✔
177

178
                XYZ v;
179
                v = transOW * new XYZ(uv[0].X, uv[0].Y, 0.0);
1,416✔
180
                v = transformation * v;
1,416✔
181
                v = transWO * v;
1,416✔
182
                XY newUvector = new XY(v.X, v.Y);
1,416✔
183

184
                v = transOW * new XYZ(uv[1].X, uv[1].Y, 0.0);
1,416✔
185
                v = transformation * v;
1,416✔
186
                v = transWO * v;
1,416✔
187
                XY newVvector = new XY(v.X, v.Y);
1,416✔
188

189
                double newRotation = newUvector.GetAngle();
1,416✔
190
                double newObliqueAngle = newVvector.GetAngle();
1,416✔
191

192
                if (mirrText)
1,416!
NEW
193
                {
×
NEW
194
                        if (XY.Cross(newUvector, newVvector) < 0)
×
NEW
195
                        {
×
NEW
196
                                newObliqueAngle = MathHelper.HalfPI - (newRotation - newObliqueAngle);
×
NEW
197
                                if (!(this.HorizontalAlignment.HasFlag(TextHorizontalAlignment.Fit)
×
NEW
198
                                        || this.HorizontalAlignment.HasFlag(TextHorizontalAlignment.Aligned)))
×
199
                                {
×
NEW
200
                                        newRotation += Math.PI;
×
201
                                }
×
202

NEW
203
                                this._mirror.RemoveFlag(TextMirrorFlag.Backward);
×
UNCOV
204
                        }
×
205
                        else
UNCOV
206
                        {
×
NEW
207
                                newObliqueAngle = MathHelper.HalfPI + (newRotation - newObliqueAngle);
×
NEW
208
                        }
×
NEW
209
                }
×
210
                else
211
                {
1,416✔
212
                        if (XY.Cross(newUvector, newVvector) < 0.0)
1,416!
NEW
213
                        {
×
NEW
214
                                newObliqueAngle = MathHelper.HalfPI - (newRotation - newObliqueAngle);
×
215

NEW
216
                                if (newUvector.Dot(uv[0]) < 0.0)
×
217
                                {
×
NEW
218
                                        newRotation += Math.PI;
×
219

NEW
220
                                        switch (this.HorizontalAlignment)
×
221
                                        {
222
                                                case TextHorizontalAlignment.Left:
NEW
223
                                                        this.HorizontalAlignment = TextHorizontalAlignment.Right;
×
NEW
224
                                                        break;
×
225
                                                case TextHorizontalAlignment.Right:
NEW
226
                                                        this.HorizontalAlignment = TextHorizontalAlignment.Left;
×
NEW
227
                                                        break;
×
228
                                        }
229
                                }
×
230
                                else
UNCOV
231
                                {
×
NEW
232
                                        switch (this.VerticalAlignment)
×
233
                                        {
234
                                                case TextVerticalAlignmentType.Top:
NEW
235
                                                        this.VerticalAlignment = TextVerticalAlignmentType.Bottom;
×
NEW
236
                                                        break;
×
237
                                                case TextVerticalAlignmentType.Bottom:
NEW
238
                                                        this.VerticalAlignment = TextVerticalAlignmentType.Top;
×
NEW
239
                                                        break;
×
240
                                        }
UNCOV
241
                                }
×
UNCOV
242
                        }
×
243
                        else
244
                        {
1,416✔
245
                                newObliqueAngle = MathHelper.HalfPI + (newRotation - newObliqueAngle);
1,416✔
246
                        }
1,416✔
247
                }
1,416✔
248

249
                // the oblique angle is defined between -85 and 85 degrees
250
                double maxOblique = MathHelper.DegToRad(85);
1,416✔
251
                double minOblique = -maxOblique;
1,416✔
252
                if (newObliqueAngle > Math.PI)
1,416!
UNCOV
253
                {
×
NEW
254
                        newObliqueAngle = Math.PI - newObliqueAngle;
×
UNCOV
255
                }
×
256

257
                if (newObliqueAngle < minOblique)
1,416!
UNCOV
258
                {
×
NEW
259
                        newObliqueAngle = minOblique;
×
UNCOV
260
                }
×
261
                else if (newObliqueAngle > maxOblique)
1,416!
UNCOV
262
                {
×
NEW
263
                        newObliqueAngle = maxOblique;
×
NEW
264
                }
×
265

266
                // the height must be greater than zero, the cos is always positive between -85 and 85
267
                double newHeight = newVvector.GetLength() * Math.Cos(newObliqueAngle);
1,416✔
268
                newHeight = MathHelper.IsZero(newHeight) ? MathHelper.Epsilon : newHeight;
1,416!
269

270
                // the width factor is defined between 0.01 and 100
271
                double newWidthFactor = newUvector.GetLength() / newHeight;
1,416✔
272
                if (newWidthFactor < 0.01)
1,416!
NEW
273
                {
×
NEW
274
                        newWidthFactor = 0.01;
×
UNCOV
275
                }
×
276
                else if (newWidthFactor > 100)
1,416!
UNCOV
277
                {
×
NEW
278
                        newWidthFactor = 100;
×
NEW
279
                }
×
280

281
                this.InsertPoint = newInsert;
1,416✔
282
                this.Normal = newNormal;
1,416✔
283
                this.Rotation = newRotation;
1,416✔
284
                this.Height = newHeight;
1,416✔
285
                this.WidthFactor = newWidthFactor;
1,416✔
286
                this.ObliqueAngle = newObliqueAngle;
1,416✔
287
        }
1,416✔
288

289
        /// <inheritdoc/>
290
        public override CadObject Clone()
291
        {
419✔
292
                TextEntity clone = (TextEntity)base.Clone();
419✔
293
                clone.Style = (TextStyle)this.Style.Clone();
419✔
294
                return clone;
419✔
295
        }
419✔
296

297
        /// <inheritdoc/>
298
        public override BoundingBox GetBoundingBox()
299
        {
6✔
300
                return new BoundingBox(this.InsertPoint);
6✔
301
        }
6✔
302

303
        internal override void AssignDocument(CadDocument doc)
304
        {
22,274✔
305
                base.AssignDocument(doc);
22,274✔
306

307
                this._style = CadObject.updateCollection(this.Style, doc.TextStyles);
22,274✔
308

309
                doc.DimensionStyles.OnRemove += this.tableOnRemove;
22,274✔
310
        }
22,274✔
311

312
        internal override void UnassignDocument()
313
        {
693✔
314
                this.Document.DimensionStyles.OnRemove -= this.tableOnRemove;
693✔
315

316
                base.UnassignDocument();
693✔
317

318
                this.Style = (TextStyle)this.Style.Clone();
693✔
319
        }
693✔
320

321
        protected override void tableOnRemove(object sender, CollectionChangedEventArgs e)
NEW
322
        {
×
NEW
323
                base.tableOnRemove(sender, e);
×
324

NEW
325
                if (e.Item.Equals(this.Style))
×
NEW
326
                {
×
NEW
327
                        this.Style = this.Document.TextStyles[TextStyle.DefaultName];
×
UNCOV
328
                }
×
UNCOV
329
        }
×
330
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc