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

DomCR / ACadSharp / 29143042407

11 Jul 2026 06:34AM UTC coverage: 2.912% (-73.0%) from 75.918%
29143042407

push

github

web-flow
Merge pull request #1146 from ilCosmico/acds-read-payload-anchor

Read the AcDs payload area offset from the data segment header

264 of 12999 branches covered (2.03%)

Branch coverage included in aggregate %.

0 of 30 new or added lines in 1 file covered. (0.0%)

31243 existing lines in 465 files now uncovered.

1337 of 41984 relevant lines covered (3.18%)

5.38 hits per line

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

0.0
/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)]
UNCOV
28
        public XYZ AlignmentPoint { get; set; }
×
29

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

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

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

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

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

68
        /// <inheritdoc/>
UNCOV
69
        public override string ObjectName => DxfFileToken.EntityText;
×
70

71
        /// <inheritdoc/>
UNCOV
72
        public override ObjectType ObjectType => ObjectType.TEXT;
×
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)]
UNCOV
81
        public double ObliqueAngle { get; set; } = 0.0;
×
82

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

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

UNCOV
99
                        if (this.Document != null)
×
UNCOV
100
                        {
×
UNCOV
101
                                this._style = CadObject.updateCollection(value, this.Document.TextStyles);
×
UNCOV
102
                        }
×
103
                        else
UNCOV
104
                        {
×
UNCOV
105
                                this._style = value;
×
UNCOV
106
                        }
×
UNCOV
107
                }
×
108
        }
109

110
        /// <inheritdoc/>
UNCOV
111
        public override string SubclassMarker => DxfSubclassMarker.Text;
×
112

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

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

133
        /// <summary>
134
        /// Vertical text justification type.
135
        /// </summary>
136
        [DxfCodeValue(DxfReferenceType.Optional, 73)]
UNCOV
137
        public virtual TextVerticalAlignmentType VerticalAlignment { get; set; } = TextVerticalAlignmentType.Baseline;
×
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)]
UNCOV
146
        public double WidthFactor { get; set; } = 1.0;
×
147

UNCOV
148
        private double _height = 1.0d;
×
149

UNCOV
150
        private TextMirrorFlag _mirror = TextMirrorFlag.None;
×
151

UNCOV
152
        private TextStyle _style = TextStyle.Default;
×
153

UNCOV
154
        private string _value = string.Empty;
×
155

UNCOV
156
        public TextEntity() : base()
×
UNCOV
157
        {
×
UNCOV
158
        }
×
159

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

UNCOV
165
                XYZ newInsert = transform.ApplyTransform(this.InsertPoint);
×
UNCOV
166
                XYZ newNormal = this.transformNormal(transform, this.Normal);
×
167

UNCOV
168
                var transformation = this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
×
169

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

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

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

UNCOV
189
                double newRotation = newUvector.GetAngle();
×
UNCOV
190
                double newObliqueAngle = newVvector.GetAngle();
×
191

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

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

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

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

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

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

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

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

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

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

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

303
        internal override void AssignDocument(CadDocument doc)
UNCOV
304
        {
×
UNCOV
305
                base.AssignDocument(doc);
×
306

UNCOV
307
                this._style = CadObject.updateCollection(this.Style, doc.TextStyles);
×
308

UNCOV
309
                doc.DimensionStyles.OnRemove += this.tableOnRemove;
×
UNCOV
310
        }
×
311

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

UNCOV
316
                base.UnassignDocument();
×
317

UNCOV
318
                this.Style = (TextStyle)this.Style.Clone();
×
UNCOV
319
        }
×
320

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

325
                if (e.Item.Equals(this.Style))
×
326
                {
×
327
                        this.Style = this.Document.TextStyles[TextStyle.DefaultName];
×
328
                }
×
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