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

DomCR / ACadSharp / 12008475829

25 Nov 2024 10:52AM UTC coverage: 75.339% (-0.3%) from 75.668%
12008475829

push

github

web-flow
Merge pull request #494 from DomCR/Issue-487_DBCOLOR

Issue 487 dbcolor

4956 of 7275 branches covered (68.12%)

Branch coverage included in aggregate %.

116 of 206 new or added lines in 21 files covered. (56.31%)

91 existing lines in 11 files now uncovered.

19811 of 25599 relevant lines covered (77.39%)

36312.43 hits per line

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

42.16
/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs
1
using ACadSharp.Objects;
2
using CSMath;
3
using CSUtilities.Converters;
4
using CSUtilities.IO;
5
using System;
6
using System.IO;
7
using System.Linq;
8

9
namespace ACadSharp.IO.DWG
10
{
11
        internal partial class DwgObjectWriter : DwgSectionIO
12
        {
13
                private void writeObjects()
14
                {
38✔
15
                        while (this._objects.Any())
1,406✔
16
                        {
1,368✔
17
                                CadObject obj = this._objects.Dequeue();
1,368✔
18

19
                                this.writeObject(obj);
1,368✔
20
                        }
1,368✔
21
                }
38✔
22

23
                private void writeObject(CadObject obj)
24
                {
1,368✔
25
                        switch (obj)
1,368✔
26
                        {
27
                                case Material:
28
                                case MultiLeaderAnnotContext:
29
                                case MultiLeaderStyle:
30
                                case SortEntitiesTable:
31
                                case UnknownNonGraphicalObject:
32
                                case VisualStyle:
33
                                        this.notify($"Object type not implemented {obj.GetType().FullName}", NotificationType.NotImplemented);
38✔
34
                                        return;
38✔
35
                        }
36

37
                        if (obj is XRecord && !this.WriteXRecords)
1,330!
38
                        {
×
39
                                return;
×
40
                        }
41

42
                        this.writeCommonNonEntityData(obj);
1,330✔
43

44
                        switch (obj)
1,330!
45
                        {
46
                                case AcdbPlaceHolder acdbPlaceHolder:
47
                                        this.writeAcdbPlaceHolder(acdbPlaceHolder);
×
48
                                        break;
×
49
                                case BookColor bookColor:
NEW
50
                                        this.writeBookColor(bookColor);
×
NEW
51
                                        break;
×
52
                                case CadDictionaryWithDefault dictionarydef:
53
                                        this.writeCadDictionaryWithDefault(dictionarydef);
×
54
                                        break;
×
55
                                case CadDictionary dictionary:
56
                                        this.writeDictionary(dictionary);
570✔
57
                                        break;
570✔
58
                                case DictionaryVariable dictionaryVariable:
59
                                        this.writeDictionaryVariable(dictionaryVariable);
×
60
                                        break;
×
61
                                case Group group:
62
                                        this.writeGroup(group);
×
63
                                        break;
×
64
                                case ImageDefinitionReactor definitionReactor:
65
                                        this.writeImageDefinitionReactor(definitionReactor);
×
66
                                        break;
×
67
                                case ImageDefinition definition:
68
                                        this.writeImageDefinition(definition);
×
69
                                        break;
×
70
                                case Layout layout:
71
                                        this.writeLayout(layout);
76✔
72
                                        break;
76✔
73
                                case MLineStyle style:
74
                                        this.writeMLineStyle(style);
38✔
75
                                        break;
38✔
76
                                case MultiLeaderStyle multiLeaderStyle:
77
                                        this.writeMultiLeaderStyle(multiLeaderStyle);
×
78
                                        break;
×
79
                                case PlotSettings plotsettings:
80
                                        this.writePlotSettings(plotsettings);
×
81
                                        break;
×
82
                                case Scale scale:
83
                                        this.writeScale(scale);
646✔
84
                                        break;
646✔
85
                                case SortEntitiesTable sorttables:
86
                                        this.writeSortEntitiesTable(sorttables);
×
87
                                        break;
×
88
                                case XRecord record:
89
                                        this.writeXRecord(record);
×
90
                                        break;
×
91
                                default:
92
                                        throw new NotImplementedException($"Object not implemented : {obj.GetType().FullName}");
×
93
                        }
94

95
                        this.registerObject(obj);
1,330✔
96
                }
1,368✔
97

98
                private void writeAcdbPlaceHolder(AcdbPlaceHolder acdbPlaceHolder)
99
                {
×
100
                }
×
101

102
                private void writeBookColor(BookColor color)
NEW
103
                {
×
NEW
104
                        this._writer.WriteBitShort(0);
×
105

NEW
106
                        if (this.R2004Plus)
×
NEW
107
                        {
×
NEW
108
                                byte[] arr = new byte[]
×
NEW
109
                                {
×
NEW
110
                                        color.Color.B,
×
NEW
111
                                        color.Color.G,
×
NEW
112
                                        color.Color.R,
×
NEW
113
                                        0b11000010
×
NEW
114
                                };
×
115

NEW
116
                                uint rgb = LittleEndianConverter.Instance.ToUInt32(arr);
×
117

NEW
118
                                this._writer.WriteBitLong((int)rgb);
×
119

NEW
120
                                byte flags = 0;
×
NEW
121
                                if (!string.IsNullOrEmpty(color.ColorName))
×
NEW
122
                                {
×
NEW
123
                                        flags = (byte)(flags | 1u);
×
NEW
124
                                }
×
125

NEW
126
                                if (!string.IsNullOrEmpty(color.BookName))
×
NEW
127
                                {
×
NEW
128
                                        flags = (byte)(flags | 2u);
×
NEW
129
                                }
×
130

NEW
131
                                this._writer.WriteByte(flags);
×
NEW
132
                                if (!string.IsNullOrEmpty(color.ColorName))
×
NEW
133
                                {
×
NEW
134
                                        this._writer.WriteVariableText(color.ColorName);
×
NEW
135
                                }
×
136

NEW
137
                                if (!string.IsNullOrEmpty(color.BookName))
×
NEW
138
                                {
×
NEW
139
                                        this._writer.WriteVariableText(color.BookName);
×
NEW
140
                                }
×
NEW
141
                        }
×
NEW
142
                }
×
143

144
                private void writeCadDictionaryWithDefault(CadDictionaryWithDefault dictionary)
145
                {
×
146
                        this.writeDictionary(dictionary);
×
147

148
                        //H 7 Default entry (hard pointer)
149
                        this._writer.HandleReference(DwgReferenceType.HardPointer, dictionary.DefaultEntry);
×
150
                }
×
151

152
                private void writeDictionary(CadDictionary dictionary)
153
                {
570✔
154
                        //Common:
155
                        //Numitems L number of dictonary items
156
                        this._writer.WriteBitLong(dictionary.Count());
570✔
157

158
                        //R14 Only:
159
                        if (this._version == ACadVersion.AC1014)
570✔
160
                        {
75✔
161
                                //Unknown R14 RC Unknown R14 byte, has always been 0
162
                                this._writer.WriteByte(0);
75✔
163
                        }
75✔
164

165
                        //R2000 +:
166
                        if (this.R2000Plus)
570✔
167
                        {
465✔
168
                                //Cloning flag BS 281
169
                                this._writer.WriteBitShort((short)dictionary.ClonningFlags);
465✔
170
                                this._writer.WriteByte((byte)(dictionary.HardOwnerFlag ? 1u : 0u));
465!
171
                        }
465✔
172

173
                        //Common:
174
                        foreach (var item in dictionary)
4,370✔
175
                        {
1,330✔
176
                                if (item is XRecord && !this.WriteXRecords)
1,330!
UNCOV
177
                                {
×
UNCOV
178
                                        return;
×
179
                                }
180

181
                                if (item is UnknownNonGraphicalObject)
1,330!
182
                                {
×
183
                                        return;
×
184
                                }
185

186
                                this._writer.WriteVariableText(item.Name);
1,330✔
187
                                this._writer.HandleReference(DwgReferenceType.SoftOwnership, item.Handle);
1,330✔
188
                        }
1,330✔
189

190
                        this.addEntriesToWriter(dictionary);
570✔
191
                }
570✔
192

193
                private void addEntriesToWriter(CadDictionary dictionary)
194
                {
570✔
195
                        foreach (CadObject e in dictionary)
4,370✔
196
                        {
1,330✔
197
                                this._objects.Enqueue(e);
1,330✔
198
                        }
1,330✔
199
                }
570✔
200

201
                private void writeDictionaryVariable(DictionaryVariable dictionaryVariable)
202
                {
×
203
                        //Intval RC an integer value
204
                        this._writer.WriteByte(0);
×
205

206
                        //BS a string
207
                        this._writer.WriteVariableText(dictionaryVariable.Value);
×
208
                }
×
209

210
                private void writeGroup(Group group)
211
                {
×
212
                        //Str TV name of group
213
                        this._writer.WriteVariableText(group.Description);
×
214

215
                        //Unnamed BS 1 if group has no name
216
                        this._writer.WriteBitShort((short)(group.IsUnnamed ? 1 : 0));
×
217
                        //Selectable BS 1 if group selectable
218
                        this._writer.WriteBitShort((short)(group.Selectable ? 1 : 0));
×
219

220
                        //Numhandles BL # objhandles in this group
221
                        this._writer.WriteBitLong(group.Entities.Count);
×
222
                        foreach (ulong h in group.Entities.Keys)
×
223
                        {
×
224
                                //the entries in the group(hard pointer)
225
                                this._writer.HandleReference(DwgReferenceType.HardPointer, h);
×
226
                        }
×
227
                }
×
228

229
                private void writeImageDefinitionReactor(ImageDefinitionReactor definitionReactor)
230
                {
×
231
                        //Common:
232
                        //Classver BL 90 class version
233
                        this._writer.WriteBitLong(definitionReactor.ClassVersion);
×
234
                }
×
235

236
                private void writeImageDefinition(ImageDefinition definition)
237
                {
×
238
                        //Common:
239
                        //Clsver BL 0 class version
240
                        this._writer.WriteBitLong(definition.ClassVersion);
×
241
                        //Imgsize 2RD 10 size of image in pixels
242
                        this._writer.Write2RawDouble(definition.Size);
×
243
                        //Filepath TV 1 path to file
244
                        this._writer.WriteVariableText(definition.FileName);
×
245
                        //Isloaded B 280 0==no, 1==yes
246
                        this._writer.WriteBit(definition.IsLoaded);
×
247
                        //Resunits RC 281 0==none, 2==centimeters, 5==inches
248
                        this._writer.WriteByte((byte)definition.Units);
×
249
                        //Pixelsize 2RD 11 size of one pixel in AutoCAD units
250
                        this._writer.Write2RawDouble(definition.DefaultSize);
×
251
                }
×
252

253
                private void writeLayout(Layout layout)
254
                {
76✔
255
                        this.writePlotSettings(layout);
76✔
256

257
                        //Common:
258
                        //Layout name TV 1 layout name
259
                        this._writer.WriteVariableText(layout.Name);
76✔
260
                        //Tab order BL 71 layout tab order
261
                        this._writer.WriteBitLong(layout.TabOrder);
76✔
262
                        //Flag BS 70 layout flags
263
                        this._writer.WriteBitShort((short)layout.LayoutFlags);
76✔
264
                        //Ucs origin 3BD 13 layout ucs origin
265
                        this._writer.Write3BitDouble(layout.Origin);
76✔
266
                        //Limmin 2RD 10 layout minimum limits
267
                        this._writer.Write2RawDouble(layout.MinLimits);
76✔
268
                        //Limmax 2RD 11 layout maximum limits
269
                        this._writer.Write2RawDouble(layout.MinLimits);
76✔
270
                        //Inspoint 3BD 12 layout insertion base point
271
                        this._writer.Write3BitDouble(layout.InsertionBasePoint);
76✔
272
                        this._writer.Write3BitDouble(layout.XAxis);
76✔
273
                        this._writer.Write3BitDouble(layout.YAxis);
76✔
274
                        this._writer.WriteBitDouble(layout.Elevation);
76✔
275
                        this._writer.WriteBitShort((short)layout.UcsOrthographicType);
76✔
276
                        this._writer.Write3BitDouble(layout.MinExtents);
76✔
277
                        this._writer.Write3BitDouble(layout.MaxExtents);
76✔
278

279
                        //R2004 +:
280
                        if (this.R2004Plus)
76✔
281
                        {
52✔
282
                                //Viewport count RL # of viewports in this layout
283
                                this._writer.WriteBitLong(layout.Viewports.Count());
52✔
284
                        }
52✔
285

286
                        //Common:
287
                        //330 associated paperspace block record handle(soft pointer)
288
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, layout.AssociatedBlock);
76✔
289
                        //331 last active viewport handle(soft pointer)
290
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, layout.Viewport);
76✔
291

292
                        //If not present and 76 code is non-zero, then base UCS is taken to be WORLD
293
                        if (layout.UcsOrthographicType == OrthographicType.None)
76!
294
                        {
76✔
295
                                //346 base ucs handle(hard pointer)
296
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
76✔
297
                                //345 named ucs handle(hard pointer)
298
                                this._writer.HandleReference(DwgReferenceType.HardPointer, layout.UCS);
76✔
299
                        }
76✔
300
                        else
301
                        {
×
302
                                //346 base ucs handle(hard pointer)
303
                                this._writer.HandleReference(DwgReferenceType.HardPointer, layout.BaseUCS);
×
304
                                //345 named ucs handle(hard pointer)
305
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
×
306
                        }
×
307

308
                        //R2004+:
309
                        if (this.R2004Plus)
76✔
310
                        {
52✔
311
                                foreach (Entities.Viewport viewport in layout.Viewports)
156!
312
                                {
×
313
                                        //Viewport handle(repeats Viewport count times) (soft pointer)
314
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, viewport);
×
315
                                }
×
316
                        }
52✔
317
                }
76✔
318

319
                private void writeMLineStyle(MLineStyle mlineStyle)
320
                {
38✔
321
                        //Common:
322
                        //Name TV Name of this style
323
                        this._writer.WriteVariableText(mlineStyle.Name);
38✔
324
                        //Desc TV Description of this style
325
                        this._writer.WriteVariableText(mlineStyle.Description);
38✔
326

327
                        short flags = 0;
38✔
328
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.DisplayJoints))
38!
329
                        {
×
330
                                flags = (short)(flags | 1U);
×
331
                        }
×
332
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.FillOn))
38!
333
                        {
×
334
                                flags = (short)(flags | 2U);
×
335
                        }
×
336
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartSquareCap))
38!
337
                        {
×
338
                                flags = (short)(flags | 16U);
×
339
                        }
×
340
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartRoundCap))
38!
341
                        {
×
342
                                flags = (short)(flags | 0x20);
×
343
                        }
×
344
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartInnerArcsCap))
38!
345
                        {
×
346
                                flags = (short)(flags | 0x40);
×
347
                        }
×
348
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndSquareCap))
38!
349
                        {
×
350
                                flags = (short)(flags | 0x100);
×
351
                        }
×
352
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndRoundCap))
38!
353
                        {
×
354
                                flags = (short)(flags | 0x200);
×
355
                        }
×
356
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndInnerArcsCap))
38!
357
                        {
×
358
                                flags = (short)(flags | 0x400);
×
359
                        }
×
360

361
                        //Flags BS A short which reconstitutes the mlinestyle flags as defined in DXF.
362
                        this._writer.WriteBitShort(flags);
38✔
363

364
                        //fillcolor CMC Fill color for this style
365
                        this._writer.WriteCmColor(mlineStyle.FillColor);
38✔
366
                        //startang BD Start angle
367
                        this._writer.WriteBitDouble(mlineStyle.StartAngle);
38✔
368
                        //endang BD End angle
369
                        this._writer.WriteBitDouble(mlineStyle.EndAngle);
38✔
370

371
                        //linesinstyle RC Number of lines in this style
372
                        this._writer.WriteByte((byte)mlineStyle.Elements.Count);
38✔
373
                        foreach (MLineStyle.Element element in mlineStyle.Elements)
114!
374
                        {
×
375
                                //Offset BD Offset of this segment
376
                                this._writer.WriteBitDouble(element.Offset);
×
377
                                //Color CMC Color of this segment
378
                                this._writer.WriteCmColor(element.Color);
×
379
                                //R2018+:
380
                                if (this.R2018Plus)
×
381
                                {
×
382
                                        //Line type handle H Line type handle (hard pointer)
383
                                        this._writer.HandleReference(DwgReferenceType.HardPointer, element.LineType);
×
384
                                }
×
385
                                //Before R2018:
386
                                else
387
                                {
×
388
                                        //TODO: Fix the Linetype index for dwgReader and DwgWriter
389
                                        //Ltindex BS Linetype index (yes, index)
390
                                        this._writer.WriteBitShort(0);
×
391
                                }
×
392
                        }
×
393
                }
38✔
394

395
                private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
396
                {
×
397
                        //TODO: Remove this line when MultiLeaderStyle is fixed for writing
398
                        return;
×
399

400
                        if (!R2010Plus)
401
                        {
402
                                return;
403
                        }
404

405
                        //        BS        179        Version expected: 2
406
                        this._writer.WriteBitShort(2);
407

408
                        //        BS        170        Content type (see paragraph on LEADER for more details).
409
                        this._writer.WriteBitShort((short)mLeaderStyle.ContentType);
410
                        //        BS        171        Draw multi-leader order (0 = draw content first, 1 = draw leader first)
411
                        this._writer.WriteBitShort((short)mLeaderStyle.MultiLeaderDrawOrder);
412
                        //        BS        172        Draw leader order (0 = draw leader head first, 1 = draw leader tail first)
413
                        this._writer.WriteBitShort((short)mLeaderStyle.LeaderDrawOrder);
414
                        //        BL        90        Maximum number of points for leader
415
                        this._writer.WriteBitShort((short)mLeaderStyle.MaxLeaderSegmentsPoints);
416
                        //        BD        40        First segment angle (radians)
417
                        this._writer.WriteBitDouble(mLeaderStyle.FirstSegmentAngleConstraint);
418
                        //        BD        41        Second segment angle (radians)
419
                        this._writer.WriteBitDouble(mLeaderStyle.SecondSegmentAngleConstraint);
420
                        //        BS        173        Leader type (see paragraph on LEADER for more details).
421
                        this._writer.WriteBitShort((short)mLeaderStyle.PathType);
422
                        //        CMC        91        Leader line color
423
                        this._writer.WriteCmColor(mLeaderStyle.LineColor);
424
                        //        H        340        Leader line type handle (hard pointer)
425
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.LeaderLineType);
426
                        //        BL        92        Leader line weight
427
                        this._writer.WriteBitLong((short)mLeaderStyle.LeaderLineWeight);
428
                        //        B        290        Is landing enabled?
429
                        this._writer.WriteBit(mLeaderStyle.EnableLanding);
430
                        //        BD        42        Landing gap
431
                        this._writer.WriteBitDouble(mLeaderStyle.LandingGap);
432
                        //        B        291        Auto include landing (is dog-leg enabled?)
433
                        this._writer.WriteBit(mLeaderStyle.EnableDogleg);
434
                        //        BD        43        Landing distance
435
                        this._writer.WriteBitDouble(mLeaderStyle.LandingDistance);
436
                        //        TV        3        Style description
437
                        this._writer.WriteVariableText(mLeaderStyle.Description);
438
                        //        H        341        Arrow head block handle (hard pointer)
439
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.Arrowhead);
440
                        //        BD        44        Arrow head size
441
                        this._writer.WriteBitDouble(mLeaderStyle.ArrowheadSize);
442
                        //        TV        300        Text default
443
                        this._writer.WriteVariableText(mLeaderStyle.DefaultTextContents);
444
                        //        H        342        Text style handle (hard pointer)
445
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.TextStyle);
446
                        //        BS        174        Left attachment (see paragraph on LEADER for more details).
447
                        this._writer.WriteBitShort((short)mLeaderStyle.TextLeftAttachment);
448
                        //        BS        178        Right attachment (see paragraph on LEADER for more details).
449
                        this._writer.WriteBitShort((short)mLeaderStyle.TextRightAttachment);
450
                        if (R2010Plus)
451
                        {
452
                                //        IF IsNewFormat OR DXF file
453
                                //        BS        175        Text angle type (see paragraph on LEADER for more details).
454
                                this._writer.WriteBitShort((short)mLeaderStyle.TextAngle);
455
                                //        END IF IsNewFormat OR DXF file
456
                        }
457
                        //        BS        176        Text alignment type
458
                        this._writer.WriteBitShort((short)mLeaderStyle.TextAlignment);
459
                        //        CMC        93        Text color
460
                        this._writer.WriteCmColor(mLeaderStyle.TextColor);
461
                        //        BD        45        Text height
462
                        this._writer.WriteBitDouble(mLeaderStyle.TextHeight);
463
                        //        B        292        Text frame enabled
464
                        this._writer.WriteBit(mLeaderStyle.TextFrame);
465
                        if (R2010Plus)
466
                        {
467
                                //        IF IsNewFormat OR DXF file
468
                                //        B        297        Always align text left
469
                                this._writer.WriteBit(mLeaderStyle.TextAlignAlwaysLeft);
470
                                //        END IF IsNewFormat OR DXF file
471
                        }
472
                        //        BD        46        Align space
473
                        this._writer.WriteBitDouble(mLeaderStyle.AlignSpace);
474
                        //        H        343        Block handle (hard pointer)
475
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.BlockContent);
476
                        //        CMC        94        Block color
477
                        this._writer.WriteCmColor(mLeaderStyle.BlockContentColor);
478
                        //        3BD        47,49,140        Block scale vector
479
                        this._writer.Write3BitDouble(mLeaderStyle.BlockContentScale);
480
                        //        B        293        Is block scale enabled
481
                        this._writer.WriteBit(mLeaderStyle.EnableBlockContentScale);
482
                        //        BD        141        Block rotation (radians)
483
                        this._writer.WriteBitDouble(mLeaderStyle.BlockContentRotation);
484
                        //        B        294        Is block rotation enabled
485
                        this._writer.WriteBit(mLeaderStyle.EnableBlockContentRotation);
486
                        //        BS        177        Block connection type (0 = MLeader connects to the block extents, 1 = MLeader connects to the block base point)
487
                        this._writer.WriteBitShort((short)mLeaderStyle.BlockContentConnection);
488
                        //        BD        142        Scale factor
489
                        this._writer.WriteBitDouble(mLeaderStyle.ScaleFactor);
490
                        //        B        295        Property changed, meaning not totally clear
491
                        //        might be set to true if something changed after loading,
492
                        //        or might be used to trigger updates in dependent MLeaders.
493
                        //        sequence seems to be different in DXF
494
                        this._writer.WriteBit(mLeaderStyle.OverwritePropertyValue);
495
                        //        B        296        Is annotative?
496
                        this._writer.WriteBit(mLeaderStyle.IsAnnotative);
497
                        //        BD        143        Break size
498
                        this._writer.WriteBitDouble(mLeaderStyle.BreakGapSize);
499

500
                        //        BS        271        Attachment direction (see paragraph on LEADER for more details).
501
                        this._writer.WriteBitShort((short)mLeaderStyle.TextAttachmentDirection);
502
                        //        BS        273        Top attachment (see paragraph on LEADER for more details).
503
                        this._writer.WriteBitShort((short)mLeaderStyle.TextBottomAttachment);
504
                        //        BS        272        Bottom attachment (see paragraph on LEADER for more details).
505
                        this._writer.WriteBitShort((short)mLeaderStyle.TextTopAttachment);
506
                }
×
507

508
                private void writePlotSettings(PlotSettings plot)
509
                {
76✔
510
                        //Common:
511
                        //Page setup name TV 1 plotsettings page setup name
512
                        this._writer.WriteVariableText(plot.PageName);
76✔
513
                        //Printer / Config TV 2 plotsettings printer or configuration file
514
                        this._writer.WriteVariableText(plot.SystemPrinterName);
76✔
515
                        //Plot layout flags BS 70 plotsettings plot layout flag
516
                        this._writer.WriteBitShort((short)plot.Flags);
76✔
517

518
                        //Left Margin BD 40 plotsettings left margin in millimeters
519
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Left);
76✔
520
                        //Bottom Margin BD 41 plotsettings bottom margin in millimeters
521
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Bottom);
76✔
522
                        //Right Margin BD 42 plotsettings right margin in millimeters
523
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Right);
76✔
524
                        //Top Margin BD 43 plotsettings top margin in millimeters
525
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Top);
76✔
526

527
                        //Paper Width BD 44 plotsettings paper width in millimeters
528
                        this._writer.WriteBitDouble(plot.PaperWidth);
76✔
529
                        //Paper Height BD 45 plotsettings paper height in millimeters
530
                        this._writer.WriteBitDouble(plot.PaperHeight);
76✔
531

532
                        //Paper Size TV 4 plotsettings paper size
533
                        this._writer.WriteVariableText(plot.PaperSize);
76✔
534

535
                        //Plot origin 2BD 46,47 plotsettings origin offset in millimeters
536
                        this._writer.WriteBitDouble(plot.PlotOriginX);
76✔
537
                        this._writer.WriteBitDouble(plot.PlotOriginY);
76✔
538

539
                        //Paper units BS 72 plotsettings plot paper units
540
                        this._writer.WriteBitShort((short)plot.PaperUnits);
76✔
541
                        //Plot rotation BS 73 plotsettings plot rotation
542
                        this._writer.WriteBitShort((short)plot.PaperRotation);
76✔
543
                        //Plot type BS 74 plotsettings plot type
544
                        this._writer.WriteBitShort((short)plot.PlotType);
76✔
545

546
                        //Window min 2BD 48,49 plotsettings plot window area lower left
547
                        this._writer.WriteBitDouble(plot.WindowLowerLeftX);
76✔
548
                        this._writer.WriteBitDouble(plot.WindowLowerLeftY);
76✔
549
                        //Window max 2BD 140,141 plotsettings plot window area upper right
550
                        this._writer.WriteBitDouble(plot.WindowUpperLeftX);
76✔
551
                        this._writer.WriteBitDouble(plot.WindowUpperLeftY);
76✔
552

553
                        //R13 - R2000 Only:
554
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
76!
555
                        {
24✔
556
                                //Plot view name T 6 plotsettings plot view name
557
                                this._writer.WriteVariableText(plot.PlotViewName);
24✔
558
                        }
24✔
559

560
                        //Common:
561
                        //Real world units BD 142 plotsettings numerator of custom print scale
562
                        this._writer.WriteBitDouble(plot.NumeratorScale);
76✔
563
                        //Drawing units BD 143 plotsettings denominator of custom print scale
564
                        this._writer.WriteBitDouble(plot.DenominatorScale);
76✔
565
                        //Current style sheet TV 7 plotsettings current style sheet
566
                        this._writer.WriteVariableText(plot.StyleSheet);
76✔
567
                        //Scale type BS 75 plotsettings standard scale type
568
                        this._writer.WriteBitShort((short)plot.ScaledFit);
76✔
569
                        //Scale factor BD 147 plotsettings scale factor
570
                        this._writer.WriteBitDouble(plot.StandardScale);
76✔
571
                        //Paper image origin 2BD 148,149 plotsettings paper image origin
572
                        this._writer.Write2BitDouble(plot.PaperImageOrigin);
76✔
573

574
                        //R2004+:
575
                        if (this.R2004Plus)
76✔
576
                        {
52✔
577
                                //Shade plot mode BS 76
578
                                this._writer.WriteBitShort((short)plot.ShadePlotMode);
52✔
579
                                //Shade plot res.Level BS 77
580
                                this._writer.WriteBitShort((short)plot.ShadePlotResolutionMode);
52✔
581
                                //Shade plot custom DPI BS 78
582
                                this._writer.WriteBitShort(plot.ShadePlotDPI);
52✔
583

584
                                //6 plot view handle(hard pointer)
585
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
52✔
586
                        }
52✔
587

588
                        //R2007 +:
589
                        if (this.R2007Plus)
76✔
590
                        {
40✔
591
                                //Visual Style handle(soft pointer)
592
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, null);
40✔
593
                        }
40✔
594
                }
76✔
595

596
                private void writeScale(Scale scale)
597
                {
646✔
598
                        //BS        70        Unknown(ODA writes 0).
599
                        this._writer.WriteBitShort(0);
646✔
600
                        //TV        300        Name
601
                        this._writer.WriteVariableText(scale.Name);
646✔
602
                        //BD        140        Paper units(numerator)
603
                        this._writer.WriteBitDouble(scale.PaperUnits);
646✔
604
                        //BD        141        Drawing units(denominator, divided by 10).
605
                        this._writer.WriteBitDouble(scale.DrawingUnits);
646✔
606
                        //B        290        Has unit scale
607
                        this._writer.WriteBit(scale.IsUnitScale);
646✔
608
                }
646✔
609

610
                private void writeSortEntitiesTable(SortEntitiesTable sortEntitiesTable)
611
                {
×
612
                        //parenthandle (soft pointer)
613
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, sortEntitiesTable.BlockOwner);
×
614

615
                        //Common:
616
                        //Numentries BL number of entries
617
                        this._writer.WriteBitLong(sortEntitiesTable.Sorters.Count());
×
618

619
                        foreach (var item in sortEntitiesTable.Sorters)
×
620
                        {
×
621
                                //Sort handle(numentries of these, CODE 0, i.e.part of the main bit stream, not of the handle bit stream!).
622
                                //The sort handle does not have to point to an entity (but it can).
623
                                //This is just the handle used for determining the drawing order of the entity specified by the entity handle in the handle bit stream.
624
                                //When the sortentstable doesn’t have a
625
                                //mapping from entity handle to sort handle, then the entity’s own handle is used for sorting.
626
                                this._writer.HandleReference(item.Handle);
×
627
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, item.Entity);
×
628
                        }
×
629
                }
×
630

631
                private void writeXRecord(XRecord xrecord)
632
                {
×
633
                        MemoryStream stream = new MemoryStream();
×
634
                        StreamIO ms = new StreamIO(stream);
×
635
                        ms.EndianConverter = new LittleEndianConverter();
×
636

637
                        foreach (XRecord.Entry entry in xrecord.Entries)
×
638
                        {
×
639
                                if (entry.Value == null)
×
640
                                {
×
641
                                        continue;
×
642
                                }
643

644
                                ms.Write<short>((short)entry.Code);
×
645
                                GroupCodeValueType groupValueType = GroupCodeValue.TransformValue(entry.Code);
×
646

647
                                switch (groupValueType)
×
648
                                {
649
                                        case GroupCodeValueType.Byte:
650
                                        case GroupCodeValueType.Bool:
651
                                                ms.Write(Convert.ToByte(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
652
                                                break;
×
653
                                        case GroupCodeValueType.Int16:
654
                                        case GroupCodeValueType.ExtendedDataInt16:
655
                                                ms.Write(Convert.ToInt16(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
656
                                                break;
×
657
                                        case GroupCodeValueType.Int32:
658
                                        case GroupCodeValueType.ExtendedDataInt32:
659
                                                ms.Write(Convert.ToInt32(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
660
                                                break;
×
661
                                        case GroupCodeValueType.Int64:
662
                                                ms.Write(Convert.ToInt64(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
663
                                                break;
×
664
                                        case GroupCodeValueType.Double:
665
                                        case GroupCodeValueType.ExtendedDataDouble:
666
                                                double d = (entry.Value as double?).Value;
×
667
                                                ms.Write<double, LittleEndianConverter>(d);
×
668
                                                break;
×
669
                                        case GroupCodeValueType.Point3D:
670
                                                XYZ xyz = (entry.Value as XYZ?).Value;
×
671
                                                ms.Write<double, LittleEndianConverter>(xyz.X);
×
672
                                                ms.Write<double, LittleEndianConverter>(xyz.Y);
×
673
                                                ms.Write<double, LittleEndianConverter>(xyz.Z);
×
674
                                                break;
×
675
                                        case GroupCodeValueType.Chunk:
676
                                        case GroupCodeValueType.ExtendedDataChunk:
677
                                                byte[] array = (byte[])entry.Value;
×
678
                                                ms.Write((byte)array.Length);
×
679
                                                ms.WriteBytes(array);
×
680
                                                break;
×
681
                                        case GroupCodeValueType.String:
682
                                        case GroupCodeValueType.ExtendedDataString:
683
                                        case GroupCodeValueType.Handle:
684
                                                string text = (string)entry.Value;
×
685

686
                                                if (this.R2007Plus)
×
687
                                                {
×
688
                                                        if (string.IsNullOrEmpty(text))
×
689
                                                        {
×
690
                                                                ms.Write<short, LittleEndianConverter>(0);
×
691
                                                                return;
×
692
                                                        }
693

694
                                                        ms.Write<short, LittleEndianConverter>((short)text.Length);
×
695
                                                        ms.Write(text, System.Text.Encoding.Unicode);
×
696
                                                }
×
697
                                                else if (string.IsNullOrEmpty(text))
×
698
                                                {
×
699
                                                        ms.Write<short, LittleEndianConverter>(0);
×
700
                                                        ms.Write((byte)this._writer.Encoding.CodePage);
×
701
                                                }
×
702
                                                else
703
                                                {
×
704
                                                        ms.Write<short, LittleEndianConverter>((short)text.Length);
×
705
                                                        ms.Write((byte)this._writer.Encoding.CodePage);
×
706
                                                        ms.Write(text, this._writer.Encoding);
×
707
                                                }
×
708
                                                break;
×
709
                                        case GroupCodeValueType.ObjectId:
710
                                        case GroupCodeValueType.ExtendedDataHandle:
711
                                                ulong u = (entry.Value as ulong?).Value;
×
712
                                                ms.Write<ulong, LittleEndianConverter>(u);
×
713
                                                break;
×
714
                                        default:
715
                                                throw new NotSupportedException();
×
716
                                }
717
                        }
×
718

719
                        //Common:
720
                        //Numdatabytes BL number of databytes
721
                        this._writer.WriteBitLong((int)ms.Length);
×
722
                        this._writer.WriteBytes(stream.GetBuffer());
×
723

724
                        //R2000+:
725
                        if (this.R2000Plus)
×
726
                        {
×
727
                                //Cloning flag BS 280
728
                                this._writer.WriteBitShort((short)xrecord.CloningFlags);
×
729
                        }
×
730

731
                }
×
732
        }
733
}
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