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

DomCR / ACadSharp / 19269943512

11 Nov 2025 03:11PM UTC coverage: 78.156% (+0.2%) from 78.002%
19269943512

push

github

web-flow
Merge pull request #831 from DomCR/table-entity-refactor

Table entity refactor

7383 of 10235 branches covered (72.13%)

Branch coverage included in aggregate %.

731 of 859 new or added lines in 16 files covered. (85.1%)

14 existing lines in 4 files now uncovered.

27606 of 34533 relevant lines covered (79.94%)

98649.31 hits per line

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

71.13
/src/ACadSharp/IO/DWG/DwgStreamReaders/DwgObjectReader.Entities.cs
1
using ACadSharp.Entities;
2
using ACadSharp.IO.Templates;
3
using ACadSharp.Objects;
4
using CSMath;
5
using CSUtilities.Converters;
6
using System;
7
using static ACadSharp.Entities.TableEntity;
8
using static ACadSharp.Entities.TableEntity.BreakData;
9
using static ACadSharp.IO.Templates.CadTableEntityTemplate;
10

11
namespace ACadSharp.IO.DWG
12
{
13
        internal partial class DwgObjectReader : DwgSectionIO
14
        {
15
                private CadTemplate readTableEntity()
16
                {
266✔
17
                        TableEntity table = new TableEntity();
266✔
18
                        CadTableEntityTemplate template = new CadTableEntityTemplate(table);
266✔
19

20
                        if (!this.R2010Plus)
266✔
21
                        {
152✔
22
                                return null;
152✔
23
                        }
24

25
                        this.readInsertCommonData(template);
114✔
26
                        this.readInsertCommonHandles(template);
114✔
27

28
                        if (this.R2010Plus)
114!
29
                        {
114✔
30
                                //RC Unknown (default 0)
31
                                this._mergedReaders.ReadByte();
114✔
32
                                //H Unknown (soft pointer, default NULL)
33
                                template.NullHandle = this.handleReference();
114✔
34

35
                                //BL Unknown (default 0)
36
                                long longZero = this._mergedReaders.ReadBitLong();
114✔
37
                                if (this.R2013Plus)
114✔
38
                                {
76✔
39
                                        //R2013
40
                                        //Unknown (default 0)
41
                                        this._mergedReaders.ReadBitLong();
76✔
42
                                }
76✔
43
                                else
44
                                {
38✔
45
                                        //R2010
46
                                        //B Unknown (default true)
47
                                        this._mergedReaders.ReadBit();
38✔
48
                                }
38✔
49

50
                                //Here the table content is present (see TABLECONTENT object),
51
                                //without the common OBJECT data.
52
                                //See paragraph 20.4.97.
53
                                this.readTableContent(table.Content, template);
114✔
54

55
                                //BS Unknown (default 38)
56
                                this._mergedReaders.ReadBitShort();
114✔
57
                                //3BD 11 Horizontal direction
58
                                table.HorizontalDirection = this._mergedReaders.Read3BitDouble();
114✔
59

60
                                //BL Has break data flag (0 = no break data, 1 = has break data)
61
                                //Begin break data(optional)
62
                                bool hasBreakData = this._mergedReaders.ReadBitLong() == 1;
114✔
63
                                if (hasBreakData)
114!
64
                                {
×
65
                                        TableEntity.BreakData breakData = table.TableBreakData;
×
66
                                        //BL Option flags:
67
                                        breakData.Flags = (BreakOptionFlags)this._mergedReaders.ReadBitLong();
×
68
                                        //BL Flow direction:
69
                                        breakData.FlowDirection = (BreakFlowDirection)this._mergedReaders.ReadBitLong();
×
70
                                        //BD Break spacing
71
                                        breakData.BreakSpacing = this._mergedReaders.ReadBitDouble();
×
72
                                        //BL Unknown flags
73
                                        this._mergedReaders.ReadBitLong();
×
74
                                        //BL Unknown flags
75
                                        this._mergedReaders.ReadBitLong();
×
76

77
                                        //BL Number of manual positions (break heights)
78
                                        int num = this._mergedReaders.ReadBitLong();
×
79
                                        //Begin repeat manual positions (break heights)
80
                                        for (int i = 0; i < num; i++)
×
81
                                        {
×
82
                                                BreakHeight breakHeight = new();
×
83
                                                //3BD Position
84
                                                breakHeight.Position = this._mergedReaders.Read3BitDouble();
×
85
                                                //BD Height
86
                                                breakHeight.Height = this._mergedReaders.ReadBitDouble();
×
87
                                                //BL Flags(meaning unknown)
88
                                                this._mergedReaders.ReadBitLong();
×
89
                                                breakData.Heights.Add(breakHeight);
×
90
                                        }
×
91
                                }
×
92

93
                                //End break data
94

95
                                //BL Number of break row ranges (there is always at least 1)
96
                                int rowRanges = this._mergedReaders.ReadBitLong();
114✔
97
                                for (int i = 0; i < rowRanges; i++)
456✔
98
                                {
114✔
99
                                        TableEntity.BreakRowRange breakRowRange = new();
114✔
100
                                        //3BD Position
101
                                        breakRowRange.Position = this._mergedReaders.Read3BitDouble();
114✔
102
                                        //BL Start row index
103
                                        breakRowRange.StartRowIndex = this._mergedReaders.ReadBitLong();
114✔
104
                                        //BL End row index
105
                                        breakRowRange.EndRowIndex = this._mergedReaders.ReadBitLong();
114✔
106
                                        table.BreakRowRanges.Add(breakRowRange);
114✔
107
                                }
114✔
108

109
                                return template;
114✔
110
                        }
111

112
                        //Until R2007
113

114
                        //Common:
115
                        //Flag for table value BS 90
116
                        //        Bit flags, 0x06(0x02 + 0x04): has block,
117
                        //        0x10: table direction, 0 = up, 1 = down,
118
                        //        0x20: title suppressed.
119
                        //        Normally 0x06 is always set.
120
                        table.ValueFlag = (int)this._mergedReaders.ReadBitShort();
×
121

122
                        //Hor.Dir.Vector 3BD 11
123
                        table.HorizontalDirection = this._mergedReaders.Read3BitDouble();
×
124

125
                        //Number of columns BL 92
126
                        var ncols = this._mergedReaders.ReadBitLong();
×
127
                        //Number of rows BL 91
128
                        var nrows = this._mergedReaders.ReadBitLong();
×
129

130
                        //Column widths BD 142 Repeats “# of columns” times
131
                        for (int i = 0; i < ncols; i++)
×
132
                        {
×
133
                                TableEntity.Column c = new TableEntity.Column();
×
134
                                //Column widths BD 142 Repeats “# of columns” times
135
                                c.Width = this._mergedReaders.ReadBitDouble();
×
136

137
                                table.Columns.Add(c);
×
138
                        }
×
139

140
                        //Row heights BD 141 Repeats “# of rows” times
141
                        for (int i = 0; i < nrows; i++)
×
142
                        {
×
143
                                TableEntity.Row r = new TableEntity.Row();
×
144
                                //Row heights BD 141 Repeats “# of rows” times
145
                                r.Height = this._mergedReaders.ReadBitDouble();
×
146

147
                                table.Rows.Add(r);
×
148
                        }
×
149

150
                        //Cells have more handles
151
                        //H 342 Table Style ID (hard pointer)
152
                        template.StyleHandle = this.handleReference();
×
153

154
                        for (int n = 0; n < table.Rows.Count; n++)
×
155
                        {
×
156
                                for (int m = 0; m < table.Columns.Count; m++)
×
157
                                {
×
158
                                        //Cell data, repeats for all cells in n x m table:
159
                                        TableEntity.Cell cell = new TableEntity.Cell();
×
160
                                        CadTableCellTemplate cellTemplate = new CadTableCellTemplate(cell);
×
161

162
                                        table.Rows[n].Cells.Add(cell);
×
163

164
                                        this.readTableCellData(cellTemplate);
×
165
                                }
×
166
                        }
×
167

168
                        return template;
×
169
                }
266✔
170

171
                private void readTableCellData(CadTableCellTemplate template)
172
                {
×
173
                        TableEntity.Cell cellPlaceholder = template.Cell;
×
174

175
                        //Cell type BS 171 1 = text, 2 = block.
176
                        //In AutoCAD 2007 a cell can contain either 1 text
177
                        //or 1 block.In AutoCAD 2008 this changed(TODO).
178
                        cellPlaceholder.Type = (CellType)this._mergedReaders.ReadBitShort();
×
179

180
                        throw new NotImplementedException();
×
181
                }
182

183
                private void readTableContent(TableContent content, CadTableEntityTemplate template)
184
                {
114✔
185
                        //See paragraph 20.4.97.
186
                        TableEntity tableEntity = template.TableEntity;
114✔
187

188
                        //TV 1 Name
189
                        content.Name = this._mergedReaders.ReadVariableText();
114✔
190
                        //TV 300 Description AcDbLinkedTableData fields
191
                        content.Description = this._mergedReaders.ReadVariableText();
114✔
192

193
                        //BL 90 Number of columns
194
                        int cols = this._mergedReaders.ReadBitLong();
114✔
195
                        //Begin repeat columns
196
                        for (int i = 0; i < cols; i++)
1,140✔
197
                        {
456✔
198
                                TableEntity.Column column = new TableEntity.Column();
456✔
199
                                tableEntity.Columns.Add(column);
456✔
200

201
                                //TV 300 Column name
202
                                column.Name = this._mergedReaders.ReadVariableText();
456✔
203
                                //BL 91 32 bit integer containing custom data
204
                                column.CustomData = this._mergedReaders.ReadBitLong();
456✔
205

206
                                //BL 90 Number of custom data items
207
                                int dataItems = this._mergedReaders.ReadBitLong();
456✔
208
                                //Begin repeat custom data items
209
                                for (int j = 0; j < dataItems; j++)
912!
210
                                {
×
211
                                        CustomDataEntry entry = new();
×
212

213
                                        //Custom data collection, see paragraph 20.4.100
214
                                        this.readCustomTableData(entry);
×
215

216
                                        column.CustomDataCollection.Add(entry);
×
217
                                }
×
218

219
                                //Cell style data, see paragraph 20.4.101.4, this contains cell style overrides for the column.
220
                                CadCellStyleTemplate colStyleTemplate = new(column.CellStyleOverride);
456✔
221
                                this.readCellStyle(colStyleTemplate);
456✔
222

223
                                //BL 90 Cell style ID, points to the cell style in the table’s table style that is used as the
224
                                //base cell style for the column. 0 if not present.
225
                                this._mergedReaders.ReadBitLong();
456✔
226

227
                                //BD 40 Column width.
228
                                column.Width = this._mergedReaders.ReadBitDouble();
456✔
229
                                //End repeat columns
230
                        }
456✔
231

232
                        //BL 91 Number of rows.
233
                        int nrows = this._mergedReaders.ReadBitLong();
114✔
234
                        for (int i = 0; i < nrows; i++)
1,482✔
235
                        {
627✔
236
                                //Begin repeat rows.
237
                                Row row = new Row();
627✔
238
                                tableEntity.Rows.Add(row);
627✔
239

240
                                //BL 90 Number of cells in row.
241
                                int ncells = this._mergedReaders.ReadBitLong();
627✔
242
                                //Begin repeat cells
243
                                for (int j = 0; j < ncells; j++)
5,928✔
244
                                {
2,337✔
245
                                        Cell cell = new();
2,337✔
246
                                        CadTableCellTemplate cellTemplate = new CadTableCellTemplate(cell);
2,337✔
247

248
                                        this.readTableCell(cellTemplate);
2,337✔
249

250
                                        row.Cells.Add(cell);
2,337✔
251
                                }
2,337✔
252

253
                                //BL 91 32 bit integer containing custom data
254
                                row.CustomData = this._mergedReaders.ReadBitLong();
627✔
255

256
                                //BL 90 Number of custom data items
257
                                int dataItems = this._mergedReaders.ReadBitLong();
627✔
258
                                //Begin repeat custom data items
259
                                for (int j = 0; j < dataItems; j++)
1,254!
260
                                {
×
261
                                        CustomDataEntry entry = new();
×
262

263
                                        //Custom data collection, see paragraph 20.4.100
264
                                        this.readCustomTableData(entry);
×
265

266
                                        row.CustomDataCollection.Add(entry);
×
267
                                }
×
268

269
                                //Cell style data, see paragraph 20.4.101.4, this contains cell style overrides for the column.
270
                                CadCellStyleTemplate colStyleTemplate = new(row.CellStyleOverride);
627✔
271
                                this.readCellStyle(colStyleTemplate);
627✔
272

273
                                //BL 90 Cell style ID, points to the cell style in the table’s table style that is used as the
274
                                //base cell style for the column. 0 if not present.
275
                                this._mergedReaders.ReadBitLong();
627✔
276

277
                                //40 Row height
278
                                row.Height = this._mergedReaders.ReadBitDouble();
627✔
279
                        }
627✔
280

281
                        //BL Number of cell contents that contain a field reference.
282
                        int nfields = this._mergedReaders.ReadBitLong();
114✔
283
                        //Begin repeat field references
284
                        for (int n = 0; n < nfields; n++)
228!
285
                        {
×
286
                                //H Handle to field (AcDbField), hard owner.
287
                                this._mergedReaders.HandleReference();
×
288
                        }
×
289

290
                        //The table’s cell style override fields (see paragraph 20.4.101.4). The table’s
291
                        //base cell style is the table style’s overall cell style (present from R2010 onwards).
292
                        this.readCellStyle(new CadCellStyleTemplate(content.CellStyleOverride));
114✔
293

294
                        //Bl 90 Number of merged cell ranges
295
                        int nranges = this._mergedReaders.ReadBitLong();
114✔
296
                        for (int i = 0; i < nranges; i++)
570✔
297
                        {
171✔
298
                                CellRange dxfTableCellRange = new();
171✔
299
                                //BL 91 Top row index
300
                                dxfTableCellRange.TopRowIndex = this._mergedReaders.ReadBitLong();
171✔
301
                                //BL 92 Left column index
302
                                dxfTableCellRange.LeftColumnIndex = this._mergedReaders.ReadBitLong();
171✔
303
                                //BL 93 Bottom row index
304
                                dxfTableCellRange.BottomRowIndex = this._mergedReaders.ReadBitLong();
171✔
305
                                //BL 94 Right column index
306
                                dxfTableCellRange.RightColumnIndex = this._mergedReaders.ReadBitLong();
171✔
307

308
                                content.MergedCellRanges.Add(dxfTableCellRange);
171✔
309
                        }
171✔
310

311
                        //H 340 Handle to table style(hard pointer).
312
                        template.StyleHandle = this.handleReference();
114✔
313
                }
114✔
314

315
                private void readCustomTableData(CustomDataEntry entry)
316
                {
2,280✔
317
                        //TV 300 Item name
318
                        entry.Name = this._mergedReaders.ReadVariableText();
2,280✔
319
                        this.readCustomTableDataValue(entry.Value);
2,280✔
320
                }
2,280✔
321

322
                private void readCustomTableDataValue(CellValue value)
323
                {
4,161✔
324
                        //R2007+:
325
                        if (this.R2007Plus)
4,161✔
326
                        {
4,161✔
327
                                //Flags BL 93 Flags & 0x01 => type is kGeneral
328
                                value.Flags = this._mergedReaders.ReadBitLong();
4,161✔
329
                        }
4,161✔
330

331
                        //Common:
332
                        //Data type BL 90
333
                        value.ValueType = (CellValueType)this._mergedReaders.ReadBitLong();
4,161✔
334
                        if (!this.R2007Plus || !value.IsEmpty)
4,161!
335
                        {
3,363✔
336
                                //Varies by type: Not present in case bit 1 in Flags is set
337
                                switch (value.ValueType)
3,363!
338
                                {
339
                                        case CellValueType.Unknown:
340
                                        case CellValueType.Long:
341
                                                value.Value = this._mergedReaders.ReadBitLong();
57✔
342
                                                break;
57✔
343
                                        case CellValueType.Double:
344
                                                value.Value = this._mergedReaders.ReadBitDouble();
2,508✔
345
                                                break;
2,508✔
346
                                        case CellValueType.General:
347
                                        case CellValueType.String:
348
                                                value.Value = this.readStringCellValue();
684✔
349
                                                break;
684✔
350
                                        case CellValueType.Date:
351
                                                System.DateTime? dateTime = this.readDateCellValue();
57✔
352
                                                if (dateTime.HasValue)
57!
353
                                                {
×
354
                                                        value.Value = dateTime.Value;
×
355
                                                }
×
356
                                                break;
57✔
357
                                        case CellValueType.Point2D:
358
                                                value.Value = this.readCellValueXY();
×
359
                                                break;
×
360
                                        case CellValueType.Point3D:
361
                                                value.Value = this.readCellValueXYZ();
57✔
362
                                                break;
57✔
363
                                        case CellValueType.Handle:
364
                                                value.Value = this.handleReference();
×
365
                                                break;
×
366
                                        case CellValueType.Buffer:
367
                                        case CellValueType.ResultBuffer:
368
                                        default:
369
                                                throw new NotImplementedException();
×
370
                                }
371
                        }
3,363✔
372

373
                        //R2007+:
374
                        if (this.R2007Plus)
4,161✔
375
                        {
4,161✔
376
                                //Unit type BL 94 0 = no units, 1 = distance, 2 = angle, 4 = area, 8 = volume
377
                                value.Units = (ValueUnitType)this._mergedReaders.ReadBitLong();
4,161✔
378
                                //Format String TV 300
379
                                value.Format = this._mergedReaders.ReadVariableText();
4,161✔
380
                                //Value String TV 302
381
                                value.FormattedValue = this._mergedReaders.ReadVariableText();
4,161✔
382
                        }
4,161✔
383
                }
4,161✔
384

385
                private string readStringCellValue()
386
                {
684✔
387
                        //General, BL containing the byte count followed by a
388
                        //byte array. (introduced in R2007, use Unknown before
389
                        //R2007).
390

391
                        //NOTE: It also seems to be valid for the string values
392

393
                        int length = this._mergedReaders.ReadBitLong();
684✔
394
                        byte[] arr = this._mergedReaders.ReadBytes(length);
684✔
395

396
                        if (this.R2007Plus)
684!
397
                        {
684✔
398
                                return System.Text.Encoding.Unicode.GetString(arr, 0, length - 2);
684✔
399
                        }
400
                        else
401
                        {
×
402
                                return this._mergedReaders.Encoding.GetString(arr, 0, length);
×
403
                        }
404
                }
684✔
405

406
                private System.DateTime? readDateCellValue()
407
                {
57✔
408
                        //data size N, 
409
                        int data = this._mergedReaders.ReadBitLong();
57✔
410

411
                        if (data > 0)
57✔
412
                        {
57✔
413
                                byte[] array = this._mergedReaders.ReadBytes(data);
57✔
414
                        }
57✔
415

416
                        //TODO: Finish implementation
417
                        return null;
57✔
418
                }
57✔
419

420
                private XY? readCellValueXY()
421
                {
×
422
                        XY? result = null;
×
423
                        int length = this._mergedReaders.ReadBitLong();
×
424
                        if (length > 0)
×
425
                        {
×
426
                                result = this._mergedReaders.Read2RawDouble();
×
427
                        }
×
428
                        return result;
×
429
                }
×
430

431
                private XYZ? readCellValueXYZ()
432
                {
57✔
433
                        XYZ? result = null;
57✔
434
                        int length = this._mergedReaders.ReadBitLong();
57✔
435
                        if (length > 0)
57✔
436
                        {
57✔
437
                                result = this._mergedReaders.Read3RawDouble();
57✔
438
                        }
57✔
439
                        return result;
57✔
440
                }
57✔
441

442
                private void readCellStyle(CadCellStyleTemplate template)
443
                {
3,534✔
444
                        //20.4.101.4
445
                        CellStyle cellStyle = (CellStyle)template.Format;
3,534✔
446

447
                        //BL 90 Cell style type
448
                        cellStyle.Type = (CellStyleTypeType)this._mergedReaders.ReadBitLong();
3,534✔
449

450
                        //BS 170 Data flags, 0 = no data, 1 = data is present
451
                        //If data is present
452
                        cellStyle.HasData = this._mergedReaders.ReadBitShortAsBool();
3,534✔
453
                        if (!cellStyle.HasData)
3,534✔
454
                        {
1,083✔
455
                                return;
1,083✔
456
                        }
457

458
                        //BL 91 Property override flags. The definition is the same as the content format
459
                        //propery override flags, see paragraph 20.4.101.3.
460
                        cellStyle.PropertyOverrideFlags = (TableCellStylePropertyFlags)this._mergedReaders.ReadBitLong();
2,451✔
461
                        //BL  92 Merge flags, but may only for bits 0x8000 and 0x10000.
462
                        cellStyle.TableCellStylePropertyFlags = (TableCellStylePropertyFlags)this._mergedReaders.ReadBitLong();
2,451✔
463
                        //TC 62 Background color
464
                        cellStyle.BackgroundColor = this._mergedReaders.ReadCmColor();
2,451✔
465

466
                        //BL 93 Content layout flags
467
                        cellStyle.ContentLayoutFlags = (TableCellContentLayoutFlags)this._mergedReaders.ReadBitLong();
2,451✔
468

469
                        //Content format fields (see paragraph 20.4.101.3)
470
                        this.readCellContentFormat(template, cellStyle);
2,451✔
471

472
                        //BS 171 Margin override flags, bit 1 is set if margin overrides are present
473
                        //If margin overrides are present
474
                        cellStyle.MarginOverrideFlags = (MarginFlags)this._mergedReaders.ReadBitShort();
2,451✔
475
                        if (cellStyle.MarginOverrideFlags.HasFlag(MarginFlags.Override))
2,451✔
476
                        {
1,254✔
477
                                //BD 40 Vertical margin
478
                                cellStyle.VerticalMargin = this._mergedReaders.ReadBitDouble();
1,254✔
479
                                //BD 40 Horizontal margin
480
                                cellStyle.HorizontalMargin = this._mergedReaders.ReadBitDouble();
1,254✔
481
                                //BD 40 Bottom margin
482
                                cellStyle.BottomMargin = this._mergedReaders.ReadBitDouble();
1,254✔
483
                                //BD 40 Right margin
484
                                cellStyle.RightMargin = this._mergedReaders.ReadBitDouble();
1,254✔
485
                                //BD 40 Margin horizontal spacing
486
                                cellStyle.MarginHorizontalSpacing = this._mergedReaders.ReadBitDouble();
1,254✔
487
                                //BD 40 Margin vertical spacing
488
                                cellStyle.MarginVerticalSpacing = this._mergedReaders.ReadBitDouble();
1,254✔
489
                        }
1,254✔
490

491
                        //BL 94 Number of borders present (0-6)
492
                        int nborders = this._mergedReaders.ReadBitLong();
2,451✔
493
                        //Begin repeat borders
494
                        for (int i = 0; i < nborders; i++)
15,390✔
495
                        {
5,244✔
496
                                //BL 95 Edge flags
497
                                CellEdgeFlags edgeFlags = (CellEdgeFlags)this._mergedReaders.ReadBitLong();
5,244✔
498
                                // If edge flags is non - zero
499
                                if (edgeFlags != 0)
5,244✔
500
                                {
5,244✔
501
                                        CellBorder border = new CellBorder(edgeFlags);
5,244✔
502
                                        cellStyle.Borders.Add(border);
5,244✔
503

504
                                        this.readBorder(template, border);
5,244✔
505
                                }
5,244✔
506
                        }
5,244✔
507
                }
3,534✔
508

509
                private void readBorder(CadCellStyleTemplate template, CellBorder border)
510
                {
5,244✔
511
                        //BL 90 Border property override flags
512
                        border.PropertyOverrideFlags = (TableBorderPropertyFlags)this._mergedReaders.ReadBitLong();
5,244✔
513
                        //BL 91 Border type
514
                        border.Type = ((BorderType)this._mergedReaders.ReadBitLong());
5,244✔
515
                        //TC 62 Color
516
                        border.Color = this._mergedReaders.ReadCmColor();
5,244✔
517
                        //BL 92 Line weight
518
                        border.LineWeight = ((LineWeightType)this._mergedReaders.ReadBitLong());
5,244✔
519
                        //H 40 Line type (hard pointer)
520
                        template.BorderLinetypePairs.Add(new Tuple<CellBorder, ulong>(border, this.handleReference()));
5,244✔
521
                        //BL 93 Invisibility: 1 = invisible, 0 = visible.
522
                        border.IsInvisible = (this._mergedReaders.ReadBitLong() == 1);
5,244✔
523
                        //BD 40 Double line spacing
524
                        border.DoubleLineSpacing = (this._mergedReaders.ReadBitDouble());
5,244✔
525
                }
5,244✔
526

527
                private void readTableCell(CadTableCellTemplate template)
528
                {
2,337✔
529
                        Cell cell = template.Cell;
2,337✔
530

531
                        //BL 90 Cell state flags:
532
                        cell.StateFlags = (TableCellStateFlags)this._mergedReaders.ReadBitLong();
2,337✔
533
                        //TV 300 Tooltip
534
                        cell.ToolTip = this._mergedReaders.ReadVariableText();
2,337✔
535
                        //BL 91 32 bit integer containing custom data
536
                        cell.CustomData = this._mergedReaders.ReadBitLong();
2,337✔
537

538
                        //... Custom data collection, see paragraph 20.4.100.
539
                        int ndata = this._mergedReaders.ReadBitLong();
2,337✔
540
                        for (int i = 0; i < ndata; i++)
9,234✔
541
                        {
2,280✔
542
                                CustomDataEntry customData = new CustomDataEntry();
2,280✔
543
                                this.readCustomTableData(customData);
2,280✔
544
                                cell.CustomDataCollection.Add(customData);
2,280✔
545
                        }
2,280✔
546

547
                        //BL 92 Has linked data flags, 0 = false, 1 = true If has linked data
548
                        cell.HasLinkedData = this._mergedReaders.ReadBitLong() == 1;
2,337✔
549
                        if (cell.HasLinkedData)
2,337!
550
                        {
×
551
                                //H 340 Handle to data link object (hard pointer).
NEW
552
                                template.BlockRecordHandle = this._mergedReaders.HandleReference();
×
553
                                //BL 93 Row count.
554
                                this._mergedReaders.ReadBitLong();
×
555
                                //BL 94 Column count.
556
                                this._mergedReaders.ReadBitLong();
×
557
                                //BL 96 Unknown.
558
                                this._mergedReaders.ReadBitLong();
×
559
                                //End if has linked data
560
                        }
×
561

562
                        //BL 95 Number of cell contents
563
                        int cellContents = this._mergedReaders.ReadBitLong();
2,337✔
564
                        for (int j = 0; j < cellContents; j++)
8,664✔
565
                        {
1,995✔
566
                                //Begin repeat cell contents
567
                                TableEntity.CellContent cellContent = new();
1,995✔
568
                                cell.Contents.Add(cellContent);
1,995✔
569

570
                                CadTableCellContentTemplate cellContentTemplate = new CadTableCellContentTemplate(cellContent);
1,995✔
571
                                template.ContentTemplates.Add(cellContentTemplate);
1,995✔
572

573
                                this.readTableCellContent(cellContentTemplate);
1,995✔
574
                        }
1,995✔
575

576
                        CadCellStyleTemplate formatTemplate = new(cell.StyleOverride);
2,337✔
577
                        this.readCellStyle(formatTemplate);
2,337✔
578

579
                        //BL 90 Cell style ID, points to the cell style in the table’s table style that is used as the
580
                        //base cell style for the cell. 0 if not present.
581
                        template.StyleId = this._mergedReaders.ReadBitLong();
2,337✔
582

583
                        //BL 91 Unknown flag
584
                        var unknownFlag = this._mergedReaders.ReadBitLong();
2,337✔
585
                        if (unknownFlag != 0)
2,337✔
586
                        {
2,337✔
587
                                //If unknown flag is non-zero
588
                                //BL 91 Unknown
589
                                this._mergedReaders.ReadBitLong();
2,337✔
590
                                //BD 40 Unknown
591
                                this._mergedReaders.ReadBitDouble();
2,337✔
592
                                //BD 40 Unknown
593
                                this._mergedReaders.ReadBitDouble();
2,337✔
594
                                //BL Geometry data flags
595
                                var geomFlags = this._mergedReaders.ReadBitLong();
2,337✔
596

597
                                //H Unknown ()
598
                                template.UnknownHandle = this.handleReference();
2,337✔
599
                                if (geomFlags != 0)
2,337✔
600
                                {
1,995✔
601
                                        cell.Geometry = new CellContentGeometry();
1,995✔
602
                                        this.readCellContentGeometry(cell.Geometry);
1,995✔
603
                                }
1,995✔
604
                        }
2,337✔
605
                }
2,337✔
606

607
                private void readCellContentGeometry(CellContentGeometry geometry)
608
                {
1,995✔
609
                        // Cell content geometry, see paragraph 20.4.98.
610

611
                        //3BD        Distance to top left
612
                        geometry.DistanceTopLeft = this._mergedReaders.Read3BitDouble();
1,995✔
613
                        //3BD        Distance to center
614
                        geometry.DistanceCenter = this._mergedReaders.Read3BitDouble();
1,995✔
615
                        //BD        Content width
616
                        geometry.ContentWidth = this._mergedReaders.ReadBitDouble();
1,995✔
617
                        //BD        Content height
618
                        geometry.ContentHeight = this._mergedReaders.ReadBitDouble();
1,995✔
619
                        //BD        Width
620
                        geometry.Width = this._mergedReaders.ReadBitDouble();
1,995✔
621
                        //BD        Height
622
                        geometry.Height = this._mergedReaders.ReadBitDouble();
1,995✔
623
                        //BL        Unknown flags
624
                        geometry.Flags = this._mergedReaders.ReadBitLong();
1,995✔
625
                }
1,995✔
626

627
                private void readTableCellContent(CadTableCellContentTemplate template)
628
                {
1,995✔
629
                        //BL 90 Cell content type:
630
                        template.Content.ContentType = (TableCellContentType)this._mergedReaders.ReadBitLong();
1,995✔
631

632
                        switch (template.Content.ContentType)
1,995!
633
                        {
634
                                case TableCellContentType.Unknown:
635
                                        break;
×
636
                                case TableCellContentType.Value:
637
                                        this.readCustomTableDataValue(template.Content.Value);
1,881✔
638
                                        break;
1,881✔
639
                                case TableCellContentType.Field:
640
                                        //H 340 Handle to AcDbField object (hard pointer).
641
                                        template.FieldHandle = this.handleReference();
×
642
                                        break;
×
643
                                case TableCellContentType.Block:
644
                                        //H 340 Handle to block record (hard pointer).
645
                                        template.BlockRecordHandle = this.handleReference();
114✔
646
                                        break;
114✔
647
                        }
648

649
                        //BL 91 Number of attributes
650
                        int natts = this._mergedReaders.ReadBitLong();
1,995✔
651
                        for (int i = 0; i < natts; i++)
3,990!
652
                        {
×
653
                                TableAttribute tableAttribute = new TableAttribute();
×
654
                                CadTableAttributeTemplate attTemplate = new CadTableAttributeTemplate(tableAttribute);
×
655

656
                                //H 330 Handle to attribute definition (ATTDEF), soft pointer.
657
                                attTemplate.AttDefHandle = this.handleReference();
×
658
                                //TV 301 Attribute value.
659
                                tableAttribute.Value = this._mergedReaders.ReadVariableText();
×
660
                                //BL 92 Index (starts at 1).
661
                                this._mergedReaders.ReadBitLong();
×
662
                                //End repeat attributes
663
                        }
×
664

665
                        //BS 170 Has content format overrides flag
666
                        template.Content.Format.HasData = this._mergedReaders.ReadBitShortAsBool();
1,995✔
667
                        if (template.Content.Format.HasData)
1,995✔
668
                        {
1,995✔
669
                                CadTableCellContentFormatTemplate formatTemplate = new CadTableCellContentFormatTemplate(template.Content.Format);
1,995✔
670
                                this.readCellContentFormat(formatTemplate, template.Content.Format);
1,995✔
671
                        }
1,995✔
672
                }
1,995✔
673

674
                private void readCellContentFormat(CadTableCellContentFormatTemplate template, ContentFormat format)
675
                {
4,446✔
676
                        //Cell.ContentFormat format = template.Content.Format;
677

678
                        //20.4.101.3 Content format
679

680
                        //BL 90 Property override flags
681
                        format.PropertyOverrideFlags = (TableCellStylePropertyFlags)this._mergedReaders.ReadBitLong();
4,446✔
682
                        //BL 91 Property flags. Contains property bit values for property Auto Scale only
683
                        format.PropertyFlags = this._mergedReaders.ReadBitLong();
4,446✔
684
                        //BL 92 Value data type, see also paragraph 20.4.98.
685
                        format.ValueDataType = this._mergedReaders.ReadBitLong();
4,446✔
686
                        //BL 93 Value unit type, see also paragraph 20.4.98.
687
                        format.ValueUnitType = this._mergedReaders.ReadBitLong();
4,446✔
688
                        //TV 300 Value format string
689
                        format.ValueFormatString = this._mergedReaders.ReadVariableText();
4,446✔
690
                        //BD 40 Rotation
691
                        format.Rotation = this._mergedReaders.ReadBitDouble();
4,446✔
692
                        //BD 140 Block scale
693
                        format.Scale = this._mergedReaders.ReadBitDouble();
4,446✔
694
                        //BL  94 Cell alignment
695
                        format.Alignment = this._mergedReaders.ReadBitLong();
4,446✔
696
                        //TC 62 Content color
697
                        format.Color = this._mergedReaders.ReadCmColor();
4,446✔
698
                        //H 340 Text style handle (hard pointer)
699
                        template.TextStyleHandle = this.handleReference();
4,446✔
700
                        //BD 144 Text height
701
                        format.TextHeight = this._mergedReaders.ReadBitDouble();
4,446✔
702
                }
4,446✔
703
        }
704
}
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