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

DomCR / ACadSharp / 16398608965

20 Jul 2025 09:50AM UTC coverage: 74.718% (-0.3%) from 75.043%
16398608965

Pull #715

github

web-flow
Merge 7702a1e13 into 402a39408
Pull Request #715: Issue 712 pdfunderlay writer

5873 of 8639 branches covered (67.98%)

Branch coverage included in aggregate %.

111 of 253 new or added lines in 18 files covered. (43.87%)

40 existing lines in 3 files now uncovered.

23382 of 30515 relevant lines covered (76.62%)

80843.38 hits per line

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

42.51
/src/ACadSharp/IO/DWG/DwgStreamWriters/DwgObjectWriter.Objects.cs
1
using ACadSharp.Objects;
2
using ACadSharp.Objects.Evaluations;
3
using CSMath;
4
using CSUtilities.Converters;
5
using CSUtilities.IO;
6
using CSUtilities.Text;
7
using System;
8
using System.Collections.Generic;
9
using System.IO;
10
using System.Linq;
11

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

22
                                this.writeObject(obj);
1,406✔
23
                        }
1,406✔
24
                }
38✔
25

26
                private void writeObject(CadObject obj)
27
                {
1,406✔
28
                        switch (obj)
1,406!
29
                        {
30
                                case EvaluationGraph:
31
                                case Material:
32
                                case UnknownNonGraphicalObject:
33
                                case VisualStyle:
34
                                        this.notify($"Object type not implemented {obj.GetType().FullName}", NotificationType.NotImplemented);
×
35
                                        return;
×
36
                        }
37

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

43
                        this.writeCommonNonEntityData(obj);
1,406✔
44

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

105
                        this.registerObject(obj);
1,406✔
106
                }
1,406✔
107

108
                private void writeAcdbPlaceHolder(AcdbPlaceHolder acdbPlaceHolder)
109
                {
×
110
                }
×
111

112
                private void writeBookColor(BookColor color)
113
                {
×
114
                        this._writer.WriteBitShort(0);
×
115

116
                        if (this.R2004Plus)
×
117
                        {
×
118
                                byte[] arr = new byte[]
×
119
                                {
×
120
                                        color.Color.B,
×
121
                                        color.Color.G,
×
122
                                        color.Color.R,
×
123
                                        0b11000010
×
124
                                };
×
125

126
                                uint rgb = LittleEndianConverter.Instance.ToUInt32(arr);
×
127

128
                                this._writer.WriteBitLong((int)rgb);
×
129

130
                                byte flags = 0;
×
131
                                if (!string.IsNullOrEmpty(color.ColorName))
×
132
                                {
×
133
                                        flags = (byte)(flags | 1u);
×
134
                                }
×
135

136
                                if (!string.IsNullOrEmpty(color.BookName))
×
137
                                {
×
138
                                        flags = (byte)(flags | 2u);
×
139
                                }
×
140

141
                                this._writer.WriteByte(flags);
×
142
                                if (!string.IsNullOrEmpty(color.ColorName))
×
143
                                {
×
144
                                        this._writer.WriteVariableText(color.ColorName);
×
145
                                }
×
146

147
                                if (!string.IsNullOrEmpty(color.BookName))
×
148
                                {
×
149
                                        this._writer.WriteVariableText(color.BookName);
×
150
                                }
×
151
                        }
×
152
                }
×
153

154
                private void writeCadDictionaryWithDefault(CadDictionaryWithDefault dictionary)
155
                {
×
156
                        this.writeDictionary(dictionary);
×
157

158
                        //H 7 Default entry (hard pointer)
159
                        this._writer.HandleReference(DwgReferenceType.HardPointer, dictionary.DefaultEntry);
×
160
                }
×
161

162
                private void writeDictionary(CadDictionary dictionary)
163
                {
608✔
164
                        //Common:
165
                        //Numitems L number of dictionary items
166
                        List<NonGraphicalObject> entries = new List<NonGraphicalObject>();
608✔
167
                        foreach (var item in dictionary)
4,560✔
168
                        {
1,368✔
169
                                if (item is XRecord && !this.WriteXRecords)
1,368!
170
                                {
×
171
                                        continue;
×
172
                                }
173

174
                                if (item is UnknownNonGraphicalObject)
1,368!
175
                                {
×
176
                                        continue;
×
177
                                }
178

179
                                entries.Add(item);
1,368✔
180
                        }
1,368✔
181

182
                        this._writer.WriteBitLong(entries.Count);
608✔
183

184
                        //R14 Only:
185
                        if (this._version == ACadVersion.AC1014)
608✔
186
                        {
80✔
187
                                //Unknown R14 RC Unknown R14 byte, has always been 0
188
                                this._writer.WriteByte(0);
80✔
189
                        }
80✔
190

191
                        //R2000 +:
192
                        if (this.R2000Plus)
608✔
193
                        {
496✔
194
                                //Cloning flag BS 281
195
                                this._writer.WriteBitShort((short)dictionary.ClonningFlags);
496✔
196
                                this._writer.WriteByte((byte)(dictionary.HardOwnerFlag ? 1u : 0u));
496!
197
                        }
496✔
198

199
                        //Common:
200
                        foreach (var item in entries)
4,560✔
201
                        {
1,368✔
202
                                if (item is XRecord && !this.WriteXRecords)
1,368!
203
                                {
×
204
                                        continue;
×
205
                                }
206

207
                                if (item is UnknownNonGraphicalObject)
1,368!
208
                                {
×
209
                                        continue;
×
210
                                }
211

212
                                this._writer.WriteVariableText(item.Name);
1,368✔
213
                                this._writer.HandleReference(DwgReferenceType.SoftOwnership, item.Handle);
1,368✔
214
                        }
1,368✔
215

216
                        this.addEntriesToWriter(dictionary);
608✔
217
                }
608✔
218

219
                private void addEntriesToWriter(CadDictionary dictionary)
220
                {
608✔
221
                        foreach (CadObject e in dictionary)
4,560✔
222
                        {
1,368✔
223
                                this._objects.Enqueue(e);
1,368✔
224
                        }
1,368✔
225
                }
608✔
226

227
                private void writeDictionaryVariable(DictionaryVariable dictionaryVariable)
228
                {
×
229
                        //Intval RC an integer value
230
                        this._writer.WriteByte(0);
×
231

232
                        //BS a string
233
                        this._writer.WriteVariableText(dictionaryVariable.Value);
×
234
                }
×
235

236
                private void writeGeoData(GeoData geodata)
237
                {
×
238
                        //BL Object version formats
239
                        this._writer.WriteBitLong((int)geodata.Version);
×
240

241
                        //H Soft pointer to host block
242
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, geodata.HostBlock);
×
243

244
                        //BS Design coordinate type
245
                        this._writer.WriteBitShort((short)geodata.CoordinatesType);
×
246

247
                        switch (geodata.Version)
×
248
                        {
249
                                case GeoDataVersion.R2009:
250
                                        //3BD  Reference point 
251
                                        this._writer.Write3BitDouble(geodata.ReferencePoint);
×
252

253
                                        //BL  Units value horizontal
254
                                        this._writer.WriteBitLong((int)geodata.HorizontalUnits);
×
255

256
                                        //3BD  Design point
257
                                        this._writer.Write3BitDouble(geodata.DesignPoint);
×
258

259
                                        //3BD  Obsolete, ODA writes (0, 0, 0) 
260
                                        this._writer.Write3BitDouble(XYZ.Zero);
×
261

262
                                        //3BD  Up direction
263
                                        this._writer.Write3BitDouble(geodata.UpDirection);
×
264

265
                                        //BD Angle of north direction (radians, angle measured clockwise from the (0, 1) vector). 
266
                                        this._writer.WriteBitDouble(System.Math.PI / 2.0 - geodata.NorthDirection.GetAngle());
×
267

268
                                        //3BD  Obsolete, ODA writes(1, 1, 1)
269
                                        this._writer.Write3BitDouble(new XYZ(1, 1, 1));
×
270

271
                                        //VT  Coordinate system definition. In AutoCAD 2009 this is a “Well known text” (WKT)string containing a projected coordinate system(PROJCS).
272
                                        this._writer.WriteVariableText(geodata.CoordinateSystemDefinition);
×
273
                                        //VT  Geo RSS tag.
274
                                        this._writer.WriteVariableText(geodata.GeoRssTag);
×
275

276
                                        //BD Unit scale factor horizontal
277
                                        this._writer.WriteBitDouble(geodata.HorizontalUnitScale);
×
278
                                        geodata.VerticalUnitScale = geodata.HorizontalUnitScale;
×
279

280
                                        //VT  Obsolete, coordinate system datum name 
281
                                        this._writer.WriteVariableText(string.Empty);
×
282
                                        //VT  Obsolete: coordinate system WKT 
283
                                        this._writer.WriteVariableText(string.Empty);
×
284
                                        break;
×
285
                                case GeoDataVersion.R2010:
286
                                case GeoDataVersion.R2013:
287
                                        //3BD  Design point
288
                                        this._writer.Write3BitDouble(geodata.DesignPoint);
×
289
                                        //3BD  Reference point
290
                                        this._writer.Write3BitDouble(geodata.ReferencePoint);
×
291
                                        //BD  Unit scale factor horizontal
292
                                        this._writer.WriteBitDouble(geodata.HorizontalUnitScale);
×
293
                                        //BL  Units value horizontal
294
                                        this._writer.WriteBitLong((int)geodata.HorizontalUnits);
×
295
                                        //BD  Unit scale factor vertical 
296
                                        this._writer.WriteBitDouble(geodata.VerticalUnitScale);
×
297
                                        //BL  Units value vertical
298
                                        this._writer.WriteBitLong((int)geodata.HorizontalUnits);
×
299
                                        //3RD  Up direction
300
                                        this._writer.Write3BitDouble(geodata.UpDirection);
×
301
                                        //3RD  North direction
302
                                        this._writer.Write2RawDouble(geodata.NorthDirection);
×
303
                                        //BL Scale estimation method.
304
                                        this._writer.WriteBitLong((int)geodata.ScaleEstimationMethod);
×
305
                                        //BD  User specified scale factor
306
                                        this._writer.WriteBitDouble(geodata.UserSpecifiedScaleFactor);
×
307
                                        //B  Do sea level correction
308
                                        this._writer.WriteBit(geodata.EnableSeaLevelCorrection);
×
309
                                        //BD  Sea level elevation
310
                                        this._writer.WriteBitDouble(geodata.SeaLevelElevation);
×
311
                                        //BD  Coordinate projection radius
312
                                        this._writer.WriteBitDouble(geodata.CoordinateProjectionRadius);
×
313
                                        //VT  Coordinate system definition . In AutoCAD 2010 this is a map guide XML string.
314
                                        this._writer.WriteVariableText(geodata.CoordinateSystemDefinition);
×
315
                                        //VT  Geo RSS tag.
316
                                        this._writer.WriteVariableText(geodata.GeoRssTag);
×
317
                                        break;
×
318
                                default:
319
                                        break;
×
320
                        }
321

322
                        //VT  Observation from tag
323
                        this._writer.WriteVariableText(geodata.ObservationFromTag);
×
324
                        //VT  Observation to tag
325
                        this._writer.WriteVariableText(geodata.ObservationToTag);
×
326
                        //VT  Observation coverage tag
327
                        this._writer.WriteVariableText(geodata.ObservationCoverageTag);
×
328

329
                        //BL Number of geo mesh points
330
                        this._writer.WriteBitLong(geodata.Points.Count);
×
331
                        foreach (var pt in geodata.Points)
×
332
                        {
×
333
                                //2RD Source point 
334
                                this._writer.Write2RawDouble(pt.Source);
×
335
                                //2RD Destination point 
336
                                this._writer.Write2RawDouble(pt.Destination);
×
337
                        }
×
338

339
                        //BL Number of geo mesh faces
340
                        this._writer.WriteBitLong(geodata.Faces.Count);
×
341
                        foreach (var face in geodata.Faces)
×
342
                        {
×
343
                                //BL Face index 1
344
                                this._writer.WriteBitLong(face.Index1);
×
345
                                //BL Face index 2
346
                                this._writer.WriteBitLong(face.Index2);
×
347
                                //BL Face index 3
348
                                this._writer.WriteBitLong(face.Index3);
×
349
                        }
×
350
                }
×
351

352
                private void writeGroup(Group group)
353
                {
×
354
                        //Str TV name of group
355
                        this._writer.WriteVariableText(group.Description);
×
356

357
                        //Unnamed BS 1 if group has no name
358
                        this._writer.WriteBitShort((short)(group.IsUnnamed ? 1 : 0));
×
359
                        //Selectable BS 1 if group selectable
360
                        this._writer.WriteBitShort((short)(group.Selectable ? 1 : 0));
×
361

362
                        //Numhandles BL # objhandles in this group
363
                        this._writer.WriteBitLong(group.Entities.Count());
×
364
                        foreach (var e in group.Entities)
×
365
                        {
×
366
                                //the entries in the group(hard pointer)
367
                                this._writer.HandleReference(DwgReferenceType.HardPointer, e);
×
368
                        }
×
369
                }
×
370

371
                private void writeImageDefinitionReactor(ImageDefinitionReactor definitionReactor)
372
                {
×
373
                        //Common:
374
                        //Classver BL 90 class version
375
                        this._writer.WriteBitLong(definitionReactor.ClassVersion);
×
376
                }
×
377

378
                private void writePdfDefinition(PdfUnderlayDefinition definition)
NEW
379
                {
×
NEW
380
                        this._writer.WriteVariableText(definition.File);
×
NEW
381
                        this._writer.WriteVariableText(definition.Page);
×
NEW
382
                }
×
383

384
                private void writeImageDefinition(ImageDefinition definition)
385
                {
×
386
                        //Common:
387
                        //Clsver BL 0 class version
388
                        this._writer.WriteBitLong(definition.ClassVersion);
×
389
                        //Imgsize 2RD 10 size of image in pixels
390
                        this._writer.Write2RawDouble(definition.Size);
×
391
                        //Filepath TV 1 path to file
392
                        this._writer.WriteVariableText(definition.FileName);
×
393
                        //Isloaded B 280 0==no, 1==yes
394
                        this._writer.WriteBit(definition.IsLoaded);
×
395
                        //Resunits RC 281 0==none, 2==centimeters, 5==inches
396
                        this._writer.WriteByte((byte)definition.Units);
×
397
                        //Pixelsize 2RD 11 size of one pixel in AutoCAD units
398
                        this._writer.Write2RawDouble(definition.DefaultSize);
×
399
                }
×
400

401
                private void writeLayout(Layout layout)
402
                {
76✔
403
                        this.writePlotSettings(layout);
76✔
404

405
                        //Common:
406
                        //Layout name TV 1 layout name
407
                        this._writer.WriteVariableText(layout.Name);
76✔
408
                        //Tab order BL 71 layout tab order
409
                        this._writer.WriteBitLong(layout.TabOrder);
76✔
410
                        //Flag BS 70 layout flags
411
                        this._writer.WriteBitShort((short)layout.LayoutFlags);
76✔
412
                        //Ucs origin 3BD 13 layout ucs origin
413
                        this._writer.Write3BitDouble(layout.Origin);
76✔
414
                        //Limmin 2RD 10 layout minimum limits
415
                        this._writer.Write2RawDouble(layout.MinLimits);
76✔
416
                        //Limmax 2RD 11 layout maximum limits
417
                        this._writer.Write2RawDouble(layout.MinLimits);
76✔
418
                        //Inspoint 3BD 12 layout insertion base point
419
                        this._writer.Write3BitDouble(layout.InsertionBasePoint);
76✔
420
                        this._writer.Write3BitDouble(layout.XAxis);
76✔
421
                        this._writer.Write3BitDouble(layout.YAxis);
76✔
422
                        this._writer.WriteBitDouble(layout.Elevation);
76✔
423
                        this._writer.WriteBitShort((short)layout.UcsOrthographicType);
76✔
424
                        this._writer.Write3BitDouble(layout.MinExtents);
76✔
425
                        this._writer.Write3BitDouble(layout.MaxExtents);
76✔
426

427
                        //R2004 +:
428
                        if (this.R2004Plus)
76✔
429
                        {
52✔
430
                                //Viewport count RL # of viewports in this layout
431
                                this._writer.WriteBitLong(layout.Viewports.Count());
52✔
432
                        }
52✔
433

434
                        //Common:
435
                        //330 associated paperspace block record handle(soft pointer)
436
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, layout.AssociatedBlock);
76✔
437
                        //331 last active viewport handle(soft pointer)
438
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, layout.Viewport);
76✔
439

440
                        //If not present and 76 code is non-zero, then base UCS is taken to be WORLD
441
                        if (layout.UcsOrthographicType == OrthographicType.None)
76!
442
                        {
76✔
443
                                //346 base ucs handle(hard pointer)
444
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
76✔
445
                                //345 named ucs handle(hard pointer)
446
                                this._writer.HandleReference(DwgReferenceType.HardPointer, layout.UCS);
76✔
447
                        }
76✔
448
                        else
449
                        {
×
450
                                //346 base ucs handle(hard pointer)
451
                                this._writer.HandleReference(DwgReferenceType.HardPointer, layout.BaseUCS);
×
452
                                //345 named ucs handle(hard pointer)
453
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
×
454
                        }
×
455

456
                        //R2004+:
457
                        if (this.R2004Plus)
76✔
458
                        {
52✔
459
                                foreach (Entities.Viewport viewport in layout.Viewports)
156!
460
                                {
×
461
                                        //Viewport handle(repeats Viewport count times) (soft pointer)
462
                                        this._writer.HandleReference(DwgReferenceType.SoftPointer, viewport);
×
463
                                }
×
464
                        }
52✔
465
                }
76✔
466

467
                private void writeMLineStyle(MLineStyle mlineStyle)
468
                {
38✔
469
                        //Common:
470
                        //Name TV Name of this style
471
                        this._writer.WriteVariableText(mlineStyle.Name);
38✔
472
                        //Desc TV Description of this style
473
                        this._writer.WriteVariableText(mlineStyle.Description);
38✔
474

475
                        short flags = 0;
38✔
476
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.DisplayJoints))
38!
477
                        {
×
478
                                flags = (short)(flags | 1U);
×
479
                        }
×
480
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.FillOn))
38!
481
                        {
×
482
                                flags = (short)(flags | 2U);
×
483
                        }
×
484
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartSquareCap))
38!
485
                        {
×
486
                                flags = (short)(flags | 16U);
×
487
                        }
×
488
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartRoundCap))
38!
489
                        {
×
490
                                flags = (short)(flags | 0x20);
×
491
                        }
×
492
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.StartInnerArcsCap))
38!
493
                        {
×
494
                                flags = (short)(flags | 0x40);
×
495
                        }
×
496
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndSquareCap))
38!
497
                        {
×
498
                                flags = (short)(flags | 0x100);
×
499
                        }
×
500
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndRoundCap))
38!
501
                        {
×
502
                                flags = (short)(flags | 0x200);
×
503
                        }
×
504
                        if (mlineStyle.Flags.HasFlag(MLineStyleFlags.EndInnerArcsCap))
38!
505
                        {
×
506
                                flags = (short)(flags | 0x400);
×
507
                        }
×
508

509
                        //Flags BS A short which reconstitutes the mlinestyle flags as defined in DXF.
510
                        this._writer.WriteBitShort(flags);
38✔
511

512
                        //fillcolor CMC Fill color for this style
513
                        this._writer.WriteCmColor(mlineStyle.FillColor);
38✔
514
                        //startang BD Start angle
515
                        this._writer.WriteBitDouble(mlineStyle.StartAngle);
38✔
516
                        //endang BD End angle
517
                        this._writer.WriteBitDouble(mlineStyle.EndAngle);
38✔
518

519
                        //linesinstyle RC Number of lines in this style
520
                        this._writer.WriteByte((byte)mlineStyle.Elements.Count);
38✔
521
                        foreach (MLineStyle.Element element in mlineStyle.Elements)
114!
522
                        {
×
523
                                //Offset BD Offset of this segment
524
                                this._writer.WriteBitDouble(element.Offset);
×
525
                                //Color CMC Color of this segment
526
                                this._writer.WriteCmColor(element.Color);
×
527
                                //R2018+:
528
                                if (this.R2018Plus)
×
529
                                {
×
530
                                        //Line type handle H Line type handle (hard pointer)
531
                                        this._writer.HandleReference(DwgReferenceType.HardPointer, element.LineType);
×
532
                                }
×
533
                                //Before R2018:
534
                                else
535
                                {
×
536
                                        //TODO: Fix the Linetype index for dwgReader and DwgWriter
537
                                        //Ltindex BS Linetype index (yes, index)
538
                                        this._writer.WriteBitShort(0);
×
539
                                }
×
540
                        }
×
541
                }
38✔
542

543
                private void writeMultiLeaderStyle(MultiLeaderStyle mLeaderStyle)
544
                {
38✔
545
                        if (this.R2010Plus)
38✔
546
                        {
18✔
547
                                //        BS        179        Version expected: 2
548
                                this._writer.WriteBitShort(2);
18✔
549
                        }
18✔
550

551
                        //        BS        170        Content type (see paragraph on LEADER for more details).
552
                        this._writer.WriteBitShort((short)mLeaderStyle.ContentType);
38✔
553
                        //        BS        171        Draw multi-leader order (0 = draw content first, 1 = draw leader first)
554
                        this._writer.WriteBitShort((short)mLeaderStyle.MultiLeaderDrawOrder);
38✔
555
                        //        BS        172        Draw leader order (0 = draw leader head first, 1 = draw leader tail first)
556
                        this._writer.WriteBitShort((short)mLeaderStyle.LeaderDrawOrder);
38✔
557
                        //        BL        90        Maximum number of points for leader
558
                        this._writer.WriteBitLong((short)mLeaderStyle.MaxLeaderSegmentsPoints);
38✔
559
                        //        BD        40        First segment angle (radians)
560
                        this._writer.WriteBitDouble(mLeaderStyle.FirstSegmentAngleConstraint);
38✔
561
                        //        BD        41        Second segment angle (radians)
562
                        this._writer.WriteBitDouble(mLeaderStyle.SecondSegmentAngleConstraint);
38✔
563
                        //        BS        173        Leader type (see paragraph on LEADER for more details).
564
                        this._writer.WriteBitShort((short)mLeaderStyle.PathType);
38✔
565
                        //        CMC        91        Leader line color
566
                        this._writer.WriteCmColor(mLeaderStyle.LineColor);
38✔
567

568
                        //        H        340        Leader line type handle (hard pointer)
569
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.LeaderLineType);
38✔
570

571
                        //        BL        92        Leader line weight
572
                        this._writer.WriteBitLong((short)mLeaderStyle.LeaderLineWeight);
38✔
573
                        //        B        290        Is landing enabled?
574
                        this._writer.WriteBit(mLeaderStyle.EnableLanding);
38✔
575
                        //        BD        42        Landing gap
576
                        this._writer.WriteBitDouble(mLeaderStyle.LandingGap);
38✔
577
                        //        B        291        Auto include landing (is dog-leg enabled?)
578
                        this._writer.WriteBit(mLeaderStyle.EnableDogleg);
38✔
579
                        //        BD        43        Landing distance
580
                        this._writer.WriteBitDouble(mLeaderStyle.LandingDistance);
38✔
581
                        //        TV        3        Style description
582
                        this._writer.WriteVariableText(mLeaderStyle.Description);
38✔
583

584
                        //        H        341        Arrow head block handle (hard pointer)
585
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.Arrowhead);
38✔
586

587
                        //        BD        44        Arrow head size
588
                        this._writer.WriteBitDouble(mLeaderStyle.ArrowheadSize);
38✔
589
                        //        TV        300        Text default
590
                        this._writer.WriteVariableText(mLeaderStyle.DefaultTextContents);
38✔
591

592
                        //        H        342        Text style handle (hard pointer)
593
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.TextStyle);
38✔
594

595
                        //        BS        174        Left attachment (see paragraph on LEADER for more details).
596
                        this._writer.WriteBitShort((short)mLeaderStyle.TextLeftAttachment);
38✔
597
                        //        BS        178        Right attachment (see paragraph on LEADER for more details).
598
                        this._writer.WriteBitShort((short)mLeaderStyle.TextRightAttachment);
38✔
599
                        //        BS        175        Text angle type (see paragraph on LEADER for more details).
600
                        this._writer.WriteBitShort((short)mLeaderStyle.TextAngle);
38✔
601
                        //        BS        176        Text alignment type
602
                        this._writer.WriteBitShort((short)mLeaderStyle.TextAlignment);
38✔
603
                        //        CMC        93        Text color
604
                        this._writer.WriteCmColor(mLeaderStyle.TextColor);
38✔
605
                        //        BD        45        Text height
606
                        this._writer.WriteBitDouble(mLeaderStyle.TextHeight);
38✔
607
                        //        B        292        Text frame enabled
608
                        this._writer.WriteBit(mLeaderStyle.TextFrame);
38✔
609
                        //        B        297        Always align text left
610
                        this._writer.WriteBit(mLeaderStyle.TextAlignAlwaysLeft);
38✔
611
                        //        BD        46        Align space
612
                        this._writer.WriteBitDouble(mLeaderStyle.AlignSpace);
38✔
613

614
                        //        H        343        Block handle (hard pointer)
615
                        this._writer.HandleReference(DwgReferenceType.HardPointer, mLeaderStyle.BlockContent);
38✔
616

617
                        //        CMC        94        Block color
618
                        this._writer.WriteCmColor(mLeaderStyle.BlockContentColor);
38✔
619
                        //        3BD        47,49,140        Block scale vector
620
                        this._writer.Write3BitDouble(mLeaderStyle.BlockContentScale);
38✔
621
                        //        B        293        Is block scale enabled
622
                        this._writer.WriteBit(mLeaderStyle.EnableBlockContentScale);
38✔
623
                        //        BD        141        Block rotation (radians)
624
                        this._writer.WriteBitDouble(mLeaderStyle.BlockContentRotation);
38✔
625
                        //        B        294        Is block rotation enabled
626
                        this._writer.WriteBit(mLeaderStyle.EnableBlockContentRotation);
38✔
627
                        //        BS        177        Block connection type (0 = MLeader connects to the block extents, 1 = MLeader connects to the block base point)
628
                        this._writer.WriteBitShort((short)mLeaderStyle.BlockContentConnection);
38✔
629
                        //        BD        142        Scale factor
630
                        this._writer.WriteBitDouble(mLeaderStyle.ScaleFactor);
38✔
631
                        //        B        295        Property changed, meaning not totally clear
632
                        //        might be set to true if something changed after loading,
633
                        //        or might be used to trigger updates in dependent MLeaders.
634
                        //        sequence seems to be different in DXF
635
                        this._writer.WriteBit(mLeaderStyle.OverwritePropertyValue);
38✔
636
                        //        B        296        Is annotative?
637
                        this._writer.WriteBit(mLeaderStyle.IsAnnotative);
38✔
638
                        //        BD        143        Break size
639
                        this._writer.WriteBitDouble(mLeaderStyle.BreakGapSize);
38✔
640

641
                        if (this.R2010Plus)
38✔
642
                        {
18✔
643
                                //        BS        271        Attachment direction (see paragraph on LEADER for more details).
644
                                this._writer.WriteBitShort((short)mLeaderStyle.TextAttachmentDirection);
18✔
645
                                //        BS        273        Top attachment (see paragraph on LEADER for more details).
646
                                this._writer.WriteBitShort((short)mLeaderStyle.TextBottomAttachment);
18✔
647
                                //        BS        272        Bottom attachment (see paragraph on LEADER for more details).
648
                                this._writer.WriteBitShort((short)mLeaderStyle.TextTopAttachment);
18✔
649
                        }
18✔
650

651
                        if (this.R2013Plus)
38✔
652
                        {
12✔
653
                                //        B        298 Undocumented, found in DXF
654
                                this._writer.WriteBit(mLeaderStyle.UnknownFlag298);
12✔
655
                        }
12✔
656
                }
38✔
657

658
                private void writePlotSettings(PlotSettings plot)
659
                {
76✔
660
                        //Common:
661
                        //Page setup name TV 1 plotsettings page setup name
662
                        this._writer.WriteVariableText(plot.PageName);
76✔
663
                        //Printer / Config TV 2 plotsettings printer or configuration file
664
                        this._writer.WriteVariableText(plot.SystemPrinterName);
76✔
665
                        //Plot layout flags BS 70 plotsettings plot layout flag
666
                        this._writer.WriteBitShort((short)plot.Flags);
76✔
667

668
                        //Left Margin BD 40 plotsettings left margin in millimeters
669
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Left);
76✔
670
                        //Bottom Margin BD 41 plotsettings bottom margin in millimeters
671
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Bottom);
76✔
672
                        //Right Margin BD 42 plotsettings right margin in millimeters
673
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Right);
76✔
674
                        //Top Margin BD 43 plotsettings top margin in millimeters
675
                        this._writer.WriteBitDouble(plot.UnprintableMargin.Top);
76✔
676

677
                        //Paper Width BD 44 plotsettings paper width in millimeters
678
                        this._writer.WriteBitDouble(plot.PaperWidth);
76✔
679
                        //Paper Height BD 45 plotsettings paper height in millimeters
680
                        this._writer.WriteBitDouble(plot.PaperHeight);
76✔
681

682
                        //Paper Size TV 4 plotsettings paper size
683
                        this._writer.WriteVariableText(plot.PaperSize);
76✔
684

685
                        //Plot origin 2BD 46,47 plotsettings origin offset in millimeters
686
                        this._writer.WriteBitDouble(plot.PlotOriginX);
76✔
687
                        this._writer.WriteBitDouble(plot.PlotOriginY);
76✔
688

689
                        //Paper units BS 72 plotsettings plot paper units
690
                        this._writer.WriteBitShort((short)plot.PaperUnits);
76✔
691
                        //Plot rotation BS 73 plotsettings plot rotation
692
                        this._writer.WriteBitShort((short)plot.PaperRotation);
76✔
693
                        //Plot type BS 74 plotsettings plot type
694
                        this._writer.WriteBitShort((short)plot.PlotType);
76✔
695

696
                        //Window min 2BD 48,49 plotsettings plot window area lower left
697
                        this._writer.WriteBitDouble(plot.WindowLowerLeftX);
76✔
698
                        this._writer.WriteBitDouble(plot.WindowLowerLeftY);
76✔
699
                        //Window max 2BD 140,141 plotsettings plot window area upper right
700
                        this._writer.WriteBitDouble(plot.WindowUpperLeftX);
76✔
701
                        this._writer.WriteBitDouble(plot.WindowUpperLeftY);
76✔
702

703
                        //R13 - R2000 Only:
704
                        if (this._version >= ACadVersion.AC1012 && this._version <= ACadVersion.AC1015)
76!
705
                        {
24✔
706
                                //Plot view name T 6 plotsettings plot view name
707
                                this._writer.WriteVariableText(plot.PlotViewName);
24✔
708
                        }
24✔
709

710
                        //Common:
711
                        //Real world units BD 142 plotsettings numerator of custom print scale
712
                        this._writer.WriteBitDouble(plot.NumeratorScale);
76✔
713
                        //Drawing units BD 143 plotsettings denominator of custom print scale
714
                        this._writer.WriteBitDouble(plot.DenominatorScale);
76✔
715
                        //Current style sheet TV 7 plotsettings current style sheet
716
                        this._writer.WriteVariableText(plot.StyleSheet);
76✔
717
                        //Scale type BS 75 plotsettings standard scale type
718
                        this._writer.WriteBitShort((short)plot.ScaledFit);
76✔
719
                        //Scale factor BD 147 plotsettings scale factor
720
                        this._writer.WriteBitDouble(plot.StandardScale);
76✔
721
                        //Paper image origin 2BD 148,149 plotsettings paper image origin
722
                        this._writer.Write2BitDouble(plot.PaperImageOrigin);
76✔
723

724
                        //R2004+:
725
                        if (this.R2004Plus)
76✔
726
                        {
52✔
727
                                //Shade plot mode BS 76
728
                                this._writer.WriteBitShort((short)plot.ShadePlotMode);
52✔
729
                                //Shade plot res.Level BS 77
730
                                this._writer.WriteBitShort((short)plot.ShadePlotResolutionMode);
52✔
731
                                //Shade plot custom DPI BS 78
732
                                this._writer.WriteBitShort(plot.ShadePlotDPI);
52✔
733

734
                                //6 plot view handle(hard pointer)
735
                                this._writer.HandleReference(DwgReferenceType.HardPointer, null);
52✔
736
                        }
52✔
737

738
                        //R2007 +:
739
                        if (this.R2007Plus)
76✔
740
                        {
40✔
741
                                //Visual Style handle(soft pointer)
742
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, null);
40✔
743
                        }
40✔
744
                }
76✔
745

746
                private void writeRasterVariables(RasterVariables vars)
NEW
747
                {
×
748
                        //Common:
749
                        //Classver BL 90 classversion
NEW
750
                        this._writer.WriteBitLong(vars.ClassVersion);
×
751
                        //Dispfrm BS 70 displayframe
NEW
752
                        this._writer.WriteBitShort(vars.IsDisplayFrameShown ? (short)1 : (short)0);
×
753
                        //Dispqual BS 71 display quality
NEW
754
                        this._writer.WriteBitShort((short)vars.DisplayQuality);
×
755
                        //Units BS 72 units
NEW
756
                        this._writer.WriteBitShort((short)vars.Units);
×
NEW
757
                }
×
758

759
                private void writeScale(Scale scale)
760
                {
646✔
761
                        //BS        70        Unknown(ODA writes 0).
762
                        this._writer.WriteBitShort(0);
646✔
763
                        //TV        300        Name
764
                        this._writer.WriteVariableText(scale.Name);
646✔
765
                        //BD        140        Paper units(numerator)
766
                        this._writer.WriteBitDouble(scale.PaperUnits);
646✔
767
                        //BD        141        Drawing units(denominator, divided by 10).
768
                        this._writer.WriteBitDouble(scale.DrawingUnits);
646✔
769
                        //B        290        Has unit scale
770
                        this._writer.WriteBit(scale.IsUnitScale);
646✔
771
                }
646✔
772

773
                private void writeSortEntitiesTable(SortEntitiesTable sortEntitiesTable)
774
                {
×
775
                        //parenthandle (soft pointer)
776
                        this._writer.HandleReference(DwgReferenceType.SoftPointer, sortEntitiesTable.BlockOwner);
×
777

778
                        //Common:
779
                        //Numentries BL number of entries
780
                        this._writer.WriteBitLong(sortEntitiesTable.Count());
×
781
                        foreach (var item in sortEntitiesTable)
×
782
                        {
×
783
                                //Sort handle(numentries of these, CODE 0, i.e.part of the main bit stream, not of the handle bit stream!).
784
                                //The sort handle does not have to point to an entity (but it can).
785
                                //This is just the handle used for determining the drawing order of the entity specified by the entity handle in the handle bit stream.
786
                                //When the sortentstable doesn’t have a
787
                                //mapping from entity handle to sort handle, then the entity’s own handle is used for sorting.
788
                                this._writer.Main.HandleReference(item.SortHandle);
×
789
                                this._writer.HandleReference(DwgReferenceType.SoftPointer, item.Entity);
×
790
                        }
×
791
                }
×
792

793
                private void writeXRecord(XRecord xrecord)
794
                {
×
795
                        MemoryStream stream = new MemoryStream();
×
796
                        StreamIO ms = new StreamIO(stream);
×
797
                        ms.EndianConverter = new LittleEndianConverter();
×
798

799
                        foreach (XRecord.Entry entry in xrecord.Entries)
×
800
                        {
×
801
                                if (entry.Value == null)
×
802
                                {
×
803
                                        continue;
×
804
                                }
805

806
                                ms.Write<short>((short)entry.Code);
×
807
                                GroupCodeValueType groupValueType = GroupCodeValue.TransformValue(entry.Code);
×
808

809
                                switch (groupValueType)
×
810
                                {
811
                                        case GroupCodeValueType.Byte:
812
                                        case GroupCodeValueType.Bool:
813
                                                ms.Write(Convert.ToByte(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
814
                                                break;
×
815
                                        case GroupCodeValueType.Int16:
816
                                        case GroupCodeValueType.ExtendedDataInt16:
817
                                                ms.Write(Convert.ToInt16(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
818
                                                break;
×
819
                                        case GroupCodeValueType.Int32:
820
                                        case GroupCodeValueType.ExtendedDataInt32:
821
                                                ms.Write(Convert.ToInt32(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
822
                                                break;
×
823
                                        case GroupCodeValueType.Int64:
824
                                                ms.Write(Convert.ToInt64(entry.Value, System.Globalization.CultureInfo.InvariantCulture));
×
825
                                                break;
×
826
                                        case GroupCodeValueType.Double:
827
                                        case GroupCodeValueType.ExtendedDataDouble:
828
                                                double d = (entry.Value as double?).Value;
×
829
                                                ms.Write<double, LittleEndianConverter>(d);
×
830
                                                break;
×
831
                                        case GroupCodeValueType.Point3D:
832
                                                XYZ xyz = (entry.Value as XYZ?).Value;
×
833
                                                ms.Write<double, LittleEndianConverter>(xyz.X);
×
834
                                                ms.Write<double, LittleEndianConverter>(xyz.Y);
×
835
                                                ms.Write<double, LittleEndianConverter>(xyz.Z);
×
836
                                                break;
×
837
                                        case GroupCodeValueType.Chunk:
838
                                        case GroupCodeValueType.ExtendedDataChunk:
839
                                                byte[] array = (byte[])entry.Value;
×
840
                                                ms.Write((byte)array.Length);
×
841
                                                ms.WriteBytes(array);
×
842
                                                break;
×
843
                                        case GroupCodeValueType.String:
844
                                        case GroupCodeValueType.ExtendedDataString:
845
                                        case GroupCodeValueType.Handle:
846
                                                string text = (string)entry.Value;
×
847

848
                                                if (this.R2007Plus)
×
849
                                                {
×
850
                                                        if (string.IsNullOrEmpty(text))
×
851
                                                        {
×
852
                                                                ms.Write<short, LittleEndianConverter>(0);
×
853
                                                                return;
×
854
                                                        }
855

856
                                                        ms.Write<short, LittleEndianConverter>((short)text.Length);
×
857
                                                        ms.Write(text, System.Text.Encoding.Unicode);
×
858
                                                }
×
859
                                                else if (string.IsNullOrEmpty(text))
×
860
                                                {
×
861
                                                        ms.Write<short, LittleEndianConverter>(0);
×
862
                                                        ms.Write((byte)CadUtils.GetCodeIndex((CodePage)this._writer.Encoding.CodePage));
×
863
                                                }
×
864
                                                else
865
                                                {
×
866
                                                        ms.Write<short, LittleEndianConverter>((short)text.Length);
×
867
                                                        ms.Write((byte)CadUtils.GetCodeIndex((CodePage)this._writer.Encoding.CodePage));
×
868
                                                        ms.Write(text, this._writer.Encoding);
×
869
                                                }
×
870
                                                break;
×
871
                                        case GroupCodeValueType.ObjectId:
872
                                        case GroupCodeValueType.ExtendedDataHandle:
873
                                                ulong u = (entry.Value as ulong?).Value;
×
874
                                                ms.Write<ulong, LittleEndianConverter>(u);
×
875
                                                break;
×
876
                                        default:
877
                                                throw new NotSupportedException();
×
878
                                }
879
                        }
×
880

881
                        //Common:
882
                        //Numdatabytes BL number of databytes
883
                        this._writer.WriteBitLong((int)ms.Length);
×
884
                        this._writer.WriteBytes(stream.GetBuffer());
×
885

886
                        //R2000+:
887
                        if (this.R2000Plus)
×
888
                        {
×
889
                                //Cloning flag BS 280
890
                                this._writer.WriteBitShort((short)xrecord.CloningFlags);
×
891
                        }
×
892

893
                }
×
894
        }
895
}
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