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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

0.0
/src/ACadSharp/Entities/MText.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Tables;
3
using CSMath;
4
using System;
5
using System.Collections.Generic;
6

7
namespace ACadSharp.Entities
8
{
9
        /// <summary>
10
        /// Represents a <see cref="MText"/> entity.
11
        /// </summary>
12
        /// <remarks>
13
        /// Object name <see cref="DxfFileToken.EntityMText"/> <br/>
14
        /// Dxf class name <see cref="DxfSubclassMarker.MText"/>
15
        /// </remarks>
16
        [DxfName(DxfFileToken.EntityMText)]
17
        [DxfSubClass(DxfSubclassMarker.MText)]
18
        public partial class MText : Entity, IText
19
        {
20
                /// <inheritdoc/>
21
                [DxfCodeValue(11, 21, 31)]
UNCOV
22
                public XYZ AlignmentPoint { get; set; } = XYZ.AxisX;
×
23

24
                /// <summary>
25
                /// Attachment point
26
                /// </summary>
27
                [DxfCodeValue(71)]
UNCOV
28
                public AttachmentPointType AttachmentPoint { get; set; } = AttachmentPointType.TopLeft;
×
29

30
                /// <summary>
31
                /// Background fill color
32
                /// </summary>
33
                /// <remarks>
34
                /// Color to use for background fill when group code 90 is 1.
35
                /// </remarks>
36
                [DxfCodeValue(63, 420, 430)]
UNCOV
37
                public Color BackgroundColor { get; set; }
×
38

39
                /// <summary>
40
                /// Background fill setting
41
                /// </summary>
42
                [DxfCodeValue(90)]
UNCOV
43
                public BackgroundFillFlags BackgroundFillFlags { get; set; } = BackgroundFillFlags.None;
×
44

45
                /// <summary>
46
                /// Determines how much border there is around the text.
47
                /// </summary>
48
                [DxfCodeValue(45)]
UNCOV
49
                public double BackgroundScale { get; set; } = 1.5;
×
50

51
                /// <summary>
52
                /// Transparency of background fill color
53
                /// </summary>
54
                [DxfCodeValue(441)]
UNCOV
55
                public Transparency BackgroundTransparency { get; set; }
×
56

UNCOV
57
                public TextColumn Column { get; set; } = new TextColumn();
×
58

59
                /// <summary>
60
                /// Drawing direction
61
                /// </summary>
62
                [DxfCodeValue(72)]
UNCOV
63
                public DrawingDirectionType DrawingDirection { get; set; } = DrawingDirectionType.LeftToRight;
×
64

65
                /// <inheritdoc/>
66
                [DxfCodeValue(40)]
67
                public double Height
68
                {
UNCOV
69
                        get => this._height;
×
70
                        set
UNCOV
71
                        {
×
UNCOV
72
                                if (value < 0)
×
73
                                        throw new ArgumentOutOfRangeException("Height value cannot be negative.");
×
74
                                else
UNCOV
75
                                        this._height = value;
×
UNCOV
76
                        }
×
77
                }
78

79
                /// <summary>
80
                /// Horizontal width of the characters that make up the mtext entity.
81
                /// This value will always be equal to or less than the value of group code 41
82
                /// </summary>
83
                /// <remarks>
84
                /// read-only, ignored if supplied
85
                /// </remarks>
86
                [DxfCodeValue(DxfReferenceType.Ignored, 42)]
UNCOV
87
                public double HorizontalWidth { get; set; } = 0.9;
×
88

89
                /// <summary>
90
                /// A 3D WCS coordinate representing the insertion or origin point.
91
                /// </summary>
92
                [DxfCodeValue(10, 20, 30)]
UNCOV
93
                public XYZ InsertPoint { get; set; } = XYZ.Zero;
×
94

UNCOV
95
                public bool IsAnnotative { get; set; } = false;
×
96

97
                /// <summary>
98
                /// Mtext line spacing factor.
99
                /// </summary>
100
                /// <remarks>
101
                /// Percentage of default (3-on-5) line spacing to be applied.Valid values range from 0.25 to 4.00
102
                /// </remarks>
103
                [DxfCodeValue(44)]
UNCOV
104
                public double LineSpacing { get; set; } = 1.0;
×
105

106
                /// <summary>
107
                /// Mtext line spacing style.
108
                /// </summary>
109
                [DxfCodeValue(73)]
UNCOV
110
                public LineSpacingStyleType LineSpacingStyle { get; set; }
×
111

112
                /// <summary>
113
                /// Specifies the three-dimensional normal unit vector for the object.
114
                /// </summary>
115
                [DxfCodeValue(210, 220, 230)]
UNCOV
116
                public XYZ Normal { get; set; } = XYZ.AxisZ;
×
117

118
                /// <inheritdoc/>
UNCOV
119
                public override string ObjectName => DxfFileToken.EntityMText;
×
120

121
                /// <inheritdoc/>
UNCOV
122
                public override ObjectType ObjectType => ObjectType.MTEXT;
×
123

124
                /// <summary>
125
                /// Reference rectangle height.
126
                /// </summary>
127
                [DxfCodeValue(46)]
UNCOV
128
                public double RectangleHeight { get; set; }
×
129

130
                /// <summary>
131
                /// Reference rectangle width.
132
                /// </summary>
133
                [DxfCodeValue(41)]
UNCOV
134
                public double RectangleWidth { get; set; }
×
135

136
                /// <inheritdoc/>
137
                /// <remarks>
138
                /// The rotation is only valid if the <see cref="Normal"/> is set to the Z axis.
139
                /// </remarks>
140
                [DxfCodeValue(DxfReferenceType.IsAngle | DxfReferenceType.Ignored, 50)]
141
                public double Rotation
142
                {
143
                        get
UNCOV
144
                        {
×
UNCOV
145
                                return new XY(this.AlignmentPoint.X, this.AlignmentPoint.Y).GetAngle();
×
UNCOV
146
                        }
×
147
                }
148

149
                /// <inheritdoc/>
150
                [DxfCodeValue(DxfReferenceType.Name | DxfReferenceType.Optional, 7)]
151
                public TextStyle Style
152
                {
UNCOV
153
                        get { return this._style; }
×
154
                        set
UNCOV
155
                        {
×
UNCOV
156
                                if (value == null)
×
157
                                {
×
158
                                        throw new ArgumentNullException(nameof(value));
×
159
                                }
160

UNCOV
161
                                if (this.Document != null)
×
UNCOV
162
                                {
×
UNCOV
163
                                        this._style = CadObject.updateCollection(value, this.Document.TextStyles);
×
UNCOV
164
                                }
×
165
                                else
UNCOV
166
                                {
×
UNCOV
167
                                        this._style = value;
×
UNCOV
168
                                }
×
UNCOV
169
                        }
×
170
                }
171

172
                /// <inheritdoc/>
UNCOV
173
                public override string SubclassMarker => DxfSubclassMarker.MText;
×
174

175
                /// <inheritdoc/>
176
                [DxfCodeValue(1)]
UNCOV
177
                public string Value { get; set; } = string.Empty;
×
178

179
                /// <summary>
180
                /// Vertical height of the mtext entity
181
                /// </summary>
182
                /// <remarks>
183
                /// read-only, ignored if supplied
184
                /// </remarks>
185
                [DxfCodeValue(DxfReferenceType.Ignored, 43)]
UNCOV
186
                public double VerticalHeight { get; set; } = 0.2;
×
187

UNCOV
188
                private double _height = 0.18;
×
189

UNCOV
190
                private TextStyle _style = TextStyle.Default;
×
191

192
                /// <inheritdoc/>
UNCOV
193
                public MText() : base() { }
×
194

195
                /// <inheritdoc/>
196
                public override void ApplyTransform(Transform transform)
UNCOV
197
                {
×
UNCOV
198
                        XYZ newInsert = transform.ApplyTransform(this.InsertPoint);
×
UNCOV
199
                        XYZ newNormal = this.transformNormal(transform, this.Normal);
×
200

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

UNCOV
203
                        transWO = transWO.Transpose();
×
204

UNCOV
205
                        List<XY> uv = applyRotation(
×
UNCOV
206
                                new[]
×
UNCOV
207
                                {
×
UNCOV
208
                                        XY.AxisX, XY.AxisY
×
UNCOV
209
                                },
×
UNCOV
210
                                this.Rotation);
×
211

212
                        XYZ v;
UNCOV
213
                        v = transOW * new XYZ(uv[0].X, uv[0].Y, 0.0);
×
UNCOV
214
                        v = transformation * v;
×
UNCOV
215
                        v = transWO * v;
×
UNCOV
216
                        XY newUvector = new XY(v.X, v.Y);
×
217

218
                        // the MText entity does not support non-uniform scaling
UNCOV
219
                        double scale = newUvector.GetLength();
×
220

UNCOV
221
                        v = transOW * new XYZ(uv[1].X, uv[1].Y, 0.0);
×
UNCOV
222
                        v = transformation * v;
×
UNCOV
223
                        v = transWO * v;
×
UNCOV
224
                        XY newVvector = new XY(v.X, v.Y);
×
225

UNCOV
226
                        double newRotation = newUvector.GetAngle();
×
227

UNCOV
228
                        if (XY.Cross(newUvector, newVvector) < 0.0)
×
229
                        {
×
230
                                if (newUvector.Dot(uv[0]) < 0.0)
×
231
                                {
×
232
                                        newRotation += 180;
×
233

234
                                        switch (this.AttachmentPoint)
×
235
                                        {
236
                                                case AttachmentPointType.TopLeft:
237
                                                        this.AttachmentPoint = AttachmentPointType.TopRight;
×
238
                                                        break;
×
239
                                                case AttachmentPointType.TopRight:
240
                                                        this.AttachmentPoint = AttachmentPointType.TopLeft;
×
241
                                                        break;
×
242
                                                case AttachmentPointType.MiddleLeft:
243
                                                        this.AttachmentPoint = AttachmentPointType.MiddleRight;
×
244
                                                        break;
×
245
                                                case AttachmentPointType.MiddleRight:
246
                                                        this.AttachmentPoint = AttachmentPointType.MiddleLeft;
×
247
                                                        break;
×
248
                                                case AttachmentPointType.BottomLeft:
249
                                                        this.AttachmentPoint = AttachmentPointType.BottomRight;
×
250
                                                        break;
×
251
                                                case AttachmentPointType.BottomRight:
252
                                                        this.AttachmentPoint = AttachmentPointType.BottomLeft;
×
253
                                                        break;
×
254
                                        }
255
                                }
×
256
                                else
257
                                {
×
258
                                        switch (this.AttachmentPoint)
×
259
                                        {
260
                                                case AttachmentPointType.TopLeft:
261
                                                        this.AttachmentPoint = AttachmentPointType.BottomLeft;
×
262
                                                        break;
×
263
                                                case AttachmentPointType.TopCenter:
264
                                                        this.AttachmentPoint = AttachmentPointType.BottomCenter;
×
265
                                                        break;
×
266
                                                case AttachmentPointType.TopRight:
267
                                                        this.AttachmentPoint = AttachmentPointType.BottomRight;
×
268
                                                        break;
×
269
                                                case AttachmentPointType.BottomLeft:
270
                                                        this.AttachmentPoint = AttachmentPointType.TopLeft;
×
271
                                                        break;
×
272
                                                case AttachmentPointType.BottomCenter:
273
                                                        this.AttachmentPoint = AttachmentPointType.TopCenter;
×
274
                                                        break;
×
275
                                                case AttachmentPointType.BottomRight:
276
                                                        this.AttachmentPoint = AttachmentPointType.TopRight;
×
277
                                                        break;
×
278
                                        }
279
                                }
×
280
                        }
×
281

UNCOV
282
                        double newHeight = this.Height * scale;
×
UNCOV
283
                        newHeight = MathHelper.IsZero(newHeight) ? MathHelper.Epsilon : newHeight;
×
284

UNCOV
285
                        this.InsertPoint = newInsert;
×
UNCOV
286
                        this.Normal = newNormal;
×
UNCOV
287
                        this.Height = newHeight;
×
UNCOV
288
                        this.RectangleWidth *= scale;
×
UNCOV
289
                }
×
290

291
                /// <inheritdoc/>
292
                public override CadObject Clone()
UNCOV
293
                {
×
UNCOV
294
                        MText clone = (MText)base.Clone();
×
295

UNCOV
296
                        clone.Style = (TextStyle)(this.Style?.Clone());
×
UNCOV
297
                        clone.Column = this.Column?.Clone();
×
298

UNCOV
299
                        return clone;
×
UNCOV
300
                }
×
301

302
                /// <inheritdoc/>
303
                public override BoundingBox GetBoundingBox()
UNCOV
304
                {
×
UNCOV
305
                        return new BoundingBox(this.InsertPoint);
×
UNCOV
306
                }
×
307

308
                /// <summary>
309
                /// Get the text value separated in lines.
310
                /// </summary>
311
                /// <returns></returns>
312
                public string[] GetTextLines()
UNCOV
313
                {
×
UNCOV
314
                        return this.Value.Split(
×
UNCOV
315
                                new string[] { "\r\n", "\r", "\n", "\\P" },
×
UNCOV
316
                                StringSplitOptions.None
×
UNCOV
317
                        );
×
UNCOV
318
                }
×
319

320
                internal override void AssignDocument(CadDocument doc)
UNCOV
321
                {
×
UNCOV
322
                        base.AssignDocument(doc);
×
323

UNCOV
324
                        this._style = CadObject.updateCollection(this.Style, doc.TextStyles);
×
325

UNCOV
326
                        doc.DimensionStyles.OnRemove += this.tableOnRemove;
×
UNCOV
327
                }
×
328

329
                internal override void UnassignDocument()
UNCOV
330
                {
×
UNCOV
331
                        this.Document.DimensionStyles.OnRemove -= this.tableOnRemove;
×
332

UNCOV
333
                        base.UnassignDocument();
×
334

UNCOV
335
                        this.Style = (TextStyle)this.Style.Clone();
×
UNCOV
336
                }
×
337

338
                protected override void tableOnRemove(object sender, CollectionChangedEventArgs e)
339
                {
×
340
                        base.tableOnRemove(sender, e);
×
341

342
                        if (e.Item.Equals(this.Style))
×
343
                        {
×
344
                                this.Style = this.Document.TextStyles[TextStyle.DefaultName];
×
345
                        }
×
346
                }
×
347
        }
348
}
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