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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 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

6
namespace ACadSharp.Entities
7
{
8
        /// <summary>
9
        /// Represents a <see cref="MText"/> entity.
10
        /// </summary>
11
        /// <remarks>
12
        /// Object name <see cref="DxfFileToken.EntityMText"/> <br/>
13
        /// Dxf class name <see cref="DxfSubclassMarker.MText"/>
14
        /// </remarks>
15
        [DxfName(DxfFileToken.EntityMText)]
16
        [DxfSubClass(DxfSubclassMarker.MText)]
17
        public partial class MText : Entity, IText
18
        {
19
                /// <inheritdoc/>
20
                public override ObjectType ObjectType => ObjectType.MTEXT;
×
21

22
                /// <inheritdoc/>
23
                public override string ObjectName => DxfFileToken.EntityMText;
×
24

25
                /// <inheritdoc/>
26
                public override string SubclassMarker => DxfSubclassMarker.MText;
×
27

28
                /// <summary>
29
                /// A 3D WCS coordinate representing the insertion or origin point.
30
                /// </summary>
31
                [DxfCodeValue(10, 20, 30)]
32
                public XYZ InsertPoint { get; set; } = XYZ.Zero;
×
33

34
                /// <summary>
35
                /// Specifies the three-dimensional normal unit vector for the object.
36
                /// </summary>
37
                [DxfCodeValue(210, 220, 230)]
38
                public XYZ Normal { get; set; } = XYZ.AxisZ;
×
39

40
                /// <inheritdoc/>
41
                [DxfCodeValue(40)]
42
                public double Height
43
                {
44
                        get => this._height;
×
45
                        set
46
                        {
×
47
                                if (value < 0)
×
48
                                        throw new ArgumentOutOfRangeException("Height value cannot be negative.");
×
49
                                else
50
                                        this._height = value;
×
51
                        }
×
52
                }
53

54
                /// <summary>
55
                /// Reference rectangle width.
56
                /// </summary>
57
                [DxfCodeValue(41)]
58
                public double RectangleWidth { get; set; }
×
59

60
                /// <summary>
61
                /// Reference rectangle height.
62
                /// </summary>
63
                [DxfCodeValue(46)]
64
                public double RectangleHeight { get; set; }
×
65

66
                /// <summary>
67
                /// Attachment point
68
                /// </summary>
69
                [DxfCodeValue(71)]
70
                public AttachmentPointType AttachmentPoint { get; set; } = AttachmentPointType.TopLeft;
×
71

72
                /// <summary>
73
                /// Drawing direction
74
                /// </summary>
75
                [DxfCodeValue(72)]
76
                public DrawingDirectionType DrawingDirection { get; set; }
×
77

78
                /// <inheritdoc/>
79
                [DxfCodeValue(1)]
80
                public string Value { get; set; } = string.Empty;
×
81

82
                /// <inheritdoc/>
83
                [DxfCodeValue(DxfReferenceType.Name | DxfReferenceType.Optional, 7)]
84
                public TextStyle Style
85
                {
86
                        get { return this._style; }
×
87
                        set
88
                        {
×
89
                                if (value == null)
×
90
                                {
×
91
                                        throw new ArgumentNullException(nameof(value));
×
92
                                }
93

94
                                if (this.Document != null)
×
95
                                {
×
96
                                        this._style = this.updateTable(value, this.Document.TextStyles);
×
97
                                }
×
98
                                else
99
                                {
×
100
                                        this._style = value;
×
101
                                }
×
102
                        }
×
103
                }
104

105
                /// <summary>
106
                /// X-axis direction vector(in WCS)
107
                /// </summary>
108
                /// <remarks>
109
                /// 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
110
                /// </remarks>
111
                [DxfCodeValue(11, 21, 31)]
112
                public XYZ AlignmentPoint
113
                {
114
                        get => this._alignmentPoint;
×
115
                        set
116
                        {
×
117
                                this._alignmentPoint = value;
×
118
                                this._rotation = new XY(this._alignmentPoint.X, this._alignmentPoint.Y).GetAngle();
×
119
                        }
×
120
                }
121

122
                /// <summary>
123
                /// Horizontal width of the characters that make up the mtext entity.
124
                /// This value will always be equal to or less than the value of group code 41 
125
                /// </summary>
126
                /// <remarks>
127
                /// read-only, ignored if supplied
128
                /// </remarks>
129
                [DxfCodeValue(DxfReferenceType.Ignored, 42)]
130
                public double HorizontalWidth { get; set; } = 0.9;
×
131

132
                /// <summary>
133
                /// Vertical height of the mtext entity
134
                /// </summary>
135
                /// <remarks>
136
                /// read-only, ignored if supplied
137
                /// </remarks>
138
                [DxfCodeValue(DxfReferenceType.Ignored, 43)]
139
                public double VerticalHeight { get; set; } = 0.2;
×
140

141
                /// <summary>
142
                /// Specifies the rotation angle for the object.
143
                /// </summary>
144
                /// <value>
145
                /// The rotation angle in radians.
146
                /// </value>
147
                [DxfCodeValue(DxfReferenceType.IsAngle, 50)]
148
                public double Rotation
149
                {
150
                        get => this._rotation;
×
151
                        set
152
                        {
×
153
                                this._rotation = value;
×
154
                                this.AlignmentPoint = new XYZ(Math.Cos(this._rotation), Math.Sin(this._rotation), 0.0);
×
155
                        }
×
156
                }
157

158
                /// <summary>
159
                /// Mtext line spacing style 
160
                /// </summary>
161
                [DxfCodeValue(73)]
162
                public LineSpacingStyleType LineSpacingStyle { get; set; }
×
163

164
                /// <summary>
165
                /// Mtext line spacing factor.
166
                /// </summary>
167
                /// <remarks>
168
                /// Percentage of default (3-on-5) line spacing to be applied.Valid values range from 0.25 to 4.00
169
                /// </remarks>
170
                [DxfCodeValue(44)]
171
                public double LineSpacing { get; set; } = 1.0;
×
172

173
                /// <summary>
174
                /// Background fill setting
175
                /// </summary>
176
                [DxfCodeValue(90)]
177
                public BackgroundFillFlags BackgroundFillFlags { get; set; } = BackgroundFillFlags.None;
×
178

179
                /// <summary>
180
                /// Determines how much border there is around the text.
181
                /// </summary>
182
                [DxfCodeValue(45)]
183
                public double BackgroundScale { get; set; } = 1.5;
×
184

185
                /// <summary>
186
                /// Background fill color 
187
                /// </summary>
188
                /// <remarks>
189
                /// Color to use for background fill when group code 90 is 1.
190
                /// </remarks>
191
                [DxfCodeValue(63, 420, 430)]
192
                public Color BackgroundColor { get; set; }
×
193

194
                /// <summary>
195
                /// Transparency of background fill color
196
                /// </summary>
197
                [DxfCodeValue(441)]
198
                public Transparency BackgroundTransparency { get; set; }
×
199

200
                public TextColumn Column { get; set; } = new TextColumn();
×
201

202
                public bool IsAnnotative { get; set; } = false;
×
203

204
                private double _height = 1.0;
×
205

206
                private XYZ _alignmentPoint = XYZ.AxisX;
×
207

208
                private double _rotation = 0.0;
×
209

210
                private TextStyle _style = TextStyle.Default;
×
211

212
                /// <inheritdoc/>
213
                public MText() : base() { }
×
214

215
                /// <inheritdoc/>
216
                public override BoundingBox GetBoundingBox()
217
                {
×
218
                        return new BoundingBox(this.InsertPoint);
×
219
                }
×
220

221
                /// <inheritdoc/>
222
                public override CadObject Clone()
223
                {
×
224
                        MText clone = (MText)base.Clone();
×
225

226
                        clone.Style = (TextStyle)(this.Style?.Clone());
×
227
                        clone.Column = this.Column?.Clone();
×
228

229
                        return clone;
×
230
                }
×
231

232
                internal override void AssignDocument(CadDocument doc)
233
                {
×
234
                        base.AssignDocument(doc);
×
235

236
                        this._style = this.updateTable(this.Style, doc.TextStyles);
×
237

238
                        doc.DimensionStyles.OnRemove += this.tableOnRemove;
×
239
                }
×
240

241
                internal override void UnassignDocument()
242
                {
×
243
                        this.Document.DimensionStyles.OnRemove -= this.tableOnRemove;
×
244

245
                        base.UnassignDocument();
×
246

247
                        this.Style = (TextStyle)this.Style.Clone();
×
248
                }
×
249

250
                protected override void tableOnRemove(object sender, CollectionChangedEventArgs e)
251
                {
×
252
                        base.tableOnRemove(sender, e);
×
253

254
                        if (e.Item.Equals(this.Style))
×
255
                        {
×
256
                                this.Style = this.Document.TextStyles[TextStyle.DefaultName];
×
257
                        }
×
258
                }
×
259
        }
260
}
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