@bill_nee/dwg-reader 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +615 -0
  2. package/README.md +23 -2
  3. package/cordis.patch.yml +3 -0
  4. package/icon.svg +15 -0
  5. package/lib/index.js +355 -0
  6. package/locale/en.json +6 -0
  7. package/locale/zh.json +6 -0
  8. package/package.json +33 -4
  9. package/vendor/libredwg-web/lib/converter/converter.js +1102 -0
  10. package/vendor/libredwg-web/lib/converter/dwgColorToMLeaderRawColor.js +55 -0
  11. package/vendor/libredwg-web/lib/converter/entityConverter.js +2050 -0
  12. package/vendor/libredwg-web/lib/converter/index.js +3 -0
  13. package/vendor/libredwg-web/lib/converter/utils.js +46 -0
  14. package/vendor/libredwg-web/lib/database/classes/class.js +2 -0
  15. package/vendor/libredwg-web/lib/database/classes/index.js +2 -0
  16. package/vendor/libredwg-web/lib/database/codepage.js +101 -0
  17. package/vendor/libredwg-web/lib/database/common.js +2 -0
  18. package/vendor/libredwg-web/lib/database/database.js +2 -0
  19. package/vendor/libredwg-web/lib/database/entities/3dface.js +2 -0
  20. package/vendor/libredwg-web/lib/database/entities/arc.js +2 -0
  21. package/vendor/libredwg-web/lib/database/entities/arcAlignedText.js +2 -0
  22. package/vendor/libredwg-web/lib/database/entities/attdef.js +2 -0
  23. package/vendor/libredwg-web/lib/database/entities/attrib.js +2 -0
  24. package/vendor/libredwg-web/lib/database/entities/circle.js +2 -0
  25. package/vendor/libredwg-web/lib/database/entities/dimension.js +70 -0
  26. package/vendor/libredwg-web/lib/database/entities/ellipse.js +2 -0
  27. package/vendor/libredwg-web/lib/database/entities/entity.js +2 -0
  28. package/vendor/libredwg-web/lib/database/entities/hatch.js +54 -0
  29. package/vendor/libredwg-web/lib/database/entities/image.js +2 -0
  30. package/vendor/libredwg-web/lib/database/entities/index.js +38 -0
  31. package/vendor/libredwg-web/lib/database/entities/insert.js +2 -0
  32. package/vendor/libredwg-web/lib/database/entities/leader.js +2 -0
  33. package/vendor/libredwg-web/lib/database/entities/line.js +2 -0
  34. package/vendor/libredwg-web/lib/database/entities/lwpolyline.js +2 -0
  35. package/vendor/libredwg-web/lib/database/entities/mline.js +2 -0
  36. package/vendor/libredwg-web/lib/database/entities/mtext.js +2 -0
  37. package/vendor/libredwg-web/lib/database/entities/multileader.js +2 -0
  38. package/vendor/libredwg-web/lib/database/entities/ole2frame.js +2 -0
  39. package/vendor/libredwg-web/lib/database/entities/oleframe.js +2 -0
  40. package/vendor/libredwg-web/lib/database/entities/point.js +2 -0
  41. package/vendor/libredwg-web/lib/database/entities/polyline.js +19 -0
  42. package/vendor/libredwg-web/lib/database/entities/proxy.js +10 -0
  43. package/vendor/libredwg-web/lib/database/entities/ray.js +2 -0
  44. package/vendor/libredwg-web/lib/database/entities/section.js +2 -0
  45. package/vendor/libredwg-web/lib/database/entities/shape.js +2 -0
  46. package/vendor/libredwg-web/lib/database/entities/solid.js +2 -0
  47. package/vendor/libredwg-web/lib/database/entities/solid3d.js +2 -0
  48. package/vendor/libredwg-web/lib/database/entities/spline.js +2 -0
  49. package/vendor/libredwg-web/lib/database/entities/table.js +2 -0
  50. package/vendor/libredwg-web/lib/database/entities/text.js +23 -0
  51. package/vendor/libredwg-web/lib/database/entities/tolerance.js +2 -0
  52. package/vendor/libredwg-web/lib/database/entities/trace.js +2 -0
  53. package/vendor/libredwg-web/lib/database/entities/vertex.js +2 -0
  54. package/vendor/libredwg-web/lib/database/entities/viewport.js +2 -0
  55. package/vendor/libredwg-web/lib/database/entities/wipeout.js +2 -0
  56. package/vendor/libredwg-web/lib/database/entities/xline.js +2 -0
  57. package/vendor/libredwg-web/lib/database/header/header.js +2 -0
  58. package/vendor/libredwg-web/lib/database/header/index.js +3 -0
  59. package/vendor/libredwg-web/lib/database/header/variables.js +217 -0
  60. package/vendor/libredwg-web/lib/database/index.js +12 -0
  61. package/vendor/libredwg-web/lib/database/objects/common.js +2 -0
  62. package/vendor/libredwg-web/lib/database/objects/dictionary.js +19 -0
  63. package/vendor/libredwg-web/lib/database/objects/imageDef.js +2 -0
  64. package/vendor/libredwg-web/lib/database/objects/index.js +11 -0
  65. package/vendor/libredwg-web/lib/database/objects/layerFilter.js +2 -0
  66. package/vendor/libredwg-web/lib/database/objects/layerIndex.js +2 -0
  67. package/vendor/libredwg-web/lib/database/objects/layout.js +2 -0
  68. package/vendor/libredwg-web/lib/database/objects/mleaderStyle.js +2 -0
  69. package/vendor/libredwg-web/lib/database/objects/plotSetting.js +2 -0
  70. package/vendor/libredwg-web/lib/database/objects/spatialFilter.js +2 -0
  71. package/vendor/libredwg-web/lib/database/objects/xrecord.js +2 -0
  72. package/vendor/libredwg-web/lib/database/shared/index.js +2 -0
  73. package/vendor/libredwg-web/lib/database/shared/xdata.js +2 -0
  74. package/vendor/libredwg-web/lib/database/tables/appId.js +2 -0
  75. package/vendor/libredwg-web/lib/database/tables/blockRecord.js +2 -0
  76. package/vendor/libredwg-web/lib/database/tables/dimStyle.js +2 -0
  77. package/vendor/libredwg-web/lib/database/tables/index.js +9 -0
  78. package/vendor/libredwg-web/lib/database/tables/layer.js +2 -0
  79. package/vendor/libredwg-web/lib/database/tables/ltype.js +2 -0
  80. package/vendor/libredwg-web/lib/database/tables/style.js +2 -0
  81. package/vendor/libredwg-web/lib/database/tables/table.js +2 -0
  82. package/vendor/libredwg-web/lib/database/tables/vport.js +2 -0
  83. package/vendor/libredwg-web/lib/database/textEscapes.js +19 -0
  84. package/vendor/libredwg-web/lib/database/version.js +260 -0
  85. package/vendor/libredwg-web/lib/index.js +4 -0
  86. package/vendor/libredwg-web/lib/libredwg.js +1271 -0
  87. package/vendor/libredwg-web/lib/svg/box2d.js +104 -0
  88. package/vendor/libredwg-web/lib/svg/bspline.js +95 -0
  89. package/vendor/libredwg-web/lib/svg/color.js +371 -0
  90. package/vendor/libredwg-web/lib/svg/index.js +2 -0
  91. package/vendor/libredwg-web/lib/svg/polyline.js +70 -0
  92. package/vendor/libredwg-web/lib/svg/svgConverter.js +540 -0
  93. package/vendor/libredwg-web/lib/svg/transformBoundingBoxAndElement.js +20 -0
  94. package/vendor/libredwg-web/lib/svg/vector.js +27 -0
  95. package/vendor/libredwg-web/lib/types/common.js +2 -0
  96. package/vendor/libredwg-web/lib/types/enums.js +390 -0
  97. package/vendor/libredwg-web/lib/types/index.js +3 -0
  98. package/vendor/libredwg-web/wasm/libredwg-web.js +2 -0
  99. package/vendor/libredwg-web/wasm/libredwg-web.wasm +0 -0
@@ -0,0 +1,2050 @@
1
+ import { DwgBoundaryPathEdgeType, DwgHatchAssociativity, DwgHatchGradientColorFlag, DwgHatchGradientFlag, DwgHatchSolidFill } from '../database/index.js';
2
+ import { Dwg_Hatch_Edge_Type, Dwg_Object_Type } from '../types/index.js';
3
+ import { dwgColorToMLeaderRawColor } from './dwgColorToMLeaderRawColor.js';
4
+ import { decodeOle2FrameCornersFromData, idToString, uint8ArrayToHexString } from './utils.js';
5
+ export class LibreEntityConverter {
6
+ libredwg;
7
+ layers = new Map();
8
+ ltypes = new Map();
9
+ classes = [];
10
+ unknownEntityCount;
11
+ constructor(instance) {
12
+ this.libredwg = instance;
13
+ this.unknownEntityCount = 0;
14
+ }
15
+ prepare(db, force = false) {
16
+ if (force || this.layers.size == 0) {
17
+ this.layers.clear();
18
+ db.tables.LAYER.entries.forEach(layer => {
19
+ this.layers.set(layer.handle, layer.name);
20
+ });
21
+ }
22
+ if (force || this.ltypes.size == 0) {
23
+ this.ltypes.clear();
24
+ db.tables.LTYPE.entries.forEach(ltype => {
25
+ this.ltypes.set(ltype.handle, ltype.name);
26
+ });
27
+ }
28
+ this.classes = db.classes;
29
+ this.unknownEntityCount = 0;
30
+ }
31
+ setClasses(classes) {
32
+ this.classes = classes;
33
+ }
34
+ clear() {
35
+ this.layers.clear();
36
+ this.ltypes.clear();
37
+ this.classes = [];
38
+ this.unknownEntityCount = 0;
39
+ }
40
+ convert(object_ptr) {
41
+ const libredwg = this.libredwg;
42
+ // Get values of the common attributes of one entity
43
+ const entity = libredwg.dwg_object_to_entity(object_ptr);
44
+ const entity_tio = libredwg.dwg_object_to_entity_tio(object_ptr);
45
+ if (entity && entity_tio) {
46
+ // Get values of the common attributes of one entity
47
+ const commonAttrs = this.getCommonAttrs(entity);
48
+ const fixedtype = libredwg.dwg_object_get_fixedtype(object_ptr);
49
+ if (fixedtype == Dwg_Object_Type.DWG_TYPE_3DFACE) {
50
+ return this.convert3dFace(entity_tio, commonAttrs);
51
+ }
52
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_3DSOLID) {
53
+ return this.convert3dSolid(entity_tio, commonAttrs);
54
+ }
55
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_ARC) {
56
+ return this.convertArc(entity_tio, commonAttrs);
57
+ }
58
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_ARCALIGNEDTEXT) {
59
+ return this.convertArcAlignedText(entity_tio, commonAttrs);
60
+ }
61
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_ATTDEF) {
62
+ return this.convertAttdef(entity_tio, commonAttrs);
63
+ // libredwg stores ATTRIB as children of one INSERT entity.
64
+ // It does not exist in iterator of dwg data.
65
+ // } else if (fixedtype == Dwg_Object_Type.DWG_TYPE_ATTRIB) {
66
+ // return this.convertAttrib(entity_tio, commonAttrs)
67
+ }
68
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_CIRCLE) {
69
+ return this.convertCircle(entity_tio, commonAttrs);
70
+ }
71
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_DIMENSION_ALIGNED ||
72
+ fixedtype == Dwg_Object_Type.DWG_TYPE_DIMENSION_LINEAR) {
73
+ return this.convertAlignedDimension(entity_tio, commonAttrs);
74
+ }
75
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_DIMENSION_ANG3PT) {
76
+ return this.convert3PointAngularDimension(entity_tio, commonAttrs);
77
+ }
78
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_DIMENSION_ANG2LN) {
79
+ return this.convert2LineAngularDimension(entity_tio, commonAttrs);
80
+ }
81
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_DIMENSION_DIAMETER) {
82
+ return this.convertDiameterDimension(entity_tio, commonAttrs);
83
+ }
84
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_DIMENSION_ORDINATE) {
85
+ return this.convertOrdinateDimension(entity_tio, commonAttrs);
86
+ }
87
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_DIMENSION_RADIUS) {
88
+ return this.convertRadiusDimension(entity_tio, commonAttrs);
89
+ }
90
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_ELLIPSE) {
91
+ return this.convertEllise(entity_tio, commonAttrs);
92
+ }
93
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_HATCH) {
94
+ return this.convertHatch(entity_tio, commonAttrs);
95
+ }
96
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_IMAGE) {
97
+ return this.convertImage(entity_tio, commonAttrs);
98
+ }
99
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_INSERT) {
100
+ return this.convertInsert(entity_tio, commonAttrs);
101
+ }
102
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_LEADER) {
103
+ return this.convertLeader(entity_tio, commonAttrs);
104
+ }
105
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_LINE) {
106
+ return this.convertLine(entity_tio, commonAttrs);
107
+ }
108
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_LWPOLYLINE) {
109
+ return this.convertLWPolyline(entity_tio, commonAttrs);
110
+ }
111
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_MLINE) {
112
+ return this.convertMLine(entity_tio, commonAttrs);
113
+ }
114
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_MULTILEADER) {
115
+ return this.convertMultiLeader(entity_tio, commonAttrs);
116
+ }
117
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_MTEXT) {
118
+ return this.convertMText(entity_tio, commonAttrs);
119
+ }
120
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_OLE2FRAME) {
121
+ return this.convertOle2Frame(entity_tio, commonAttrs);
122
+ }
123
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_OLEFRAME) {
124
+ return this.convertOleFrame(entity_tio, commonAttrs);
125
+ }
126
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_POINT) {
127
+ return this.convertPoint(entity_tio, commonAttrs);
128
+ }
129
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_POLYLINE_2D) {
130
+ return this.convertPolyline2d(entity_tio, commonAttrs, object_ptr);
131
+ }
132
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_POLYLINE_3D) {
133
+ return this.convertPolyline3d(entity_tio, commonAttrs, object_ptr);
134
+ }
135
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_PROXY_ENTITY) {
136
+ return this.convertProxyEntity(entity_tio, commonAttrs, object_ptr);
137
+ }
138
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_RAY) {
139
+ return this.convertRay(entity_tio, commonAttrs);
140
+ }
141
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_SECTIONOBJECT) {
142
+ return this.convertSection(entity_tio, commonAttrs);
143
+ }
144
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_SHAPE) {
145
+ return this.convertShape(entity_tio, commonAttrs);
146
+ }
147
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_SOLID) {
148
+ return this.convertSolid(entity_tio, commonAttrs);
149
+ }
150
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_TRACE) {
151
+ return this.convertTrace(entity_tio, commonAttrs);
152
+ }
153
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_SPLINE) {
154
+ return this.convertSpline(entity_tio, commonAttrs);
155
+ }
156
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_TABLE) {
157
+ return this.convertTable(entity_tio, commonAttrs);
158
+ }
159
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_TEXT) {
160
+ return this.convertText(entity_tio, commonAttrs);
161
+ }
162
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_TOLERANCE) {
163
+ return this.convertTolerance(entity_tio, commonAttrs);
164
+ }
165
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_VIEWPORT) {
166
+ return this.convertViewport(entity_tio, commonAttrs);
167
+ }
168
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_WIPEOUT) {
169
+ return this.convertWipeout(entity_tio, commonAttrs);
170
+ }
171
+ else if (fixedtype == Dwg_Object_Type.DWG_TYPE_XLINE) {
172
+ return this.convertXline(entity_tio, commonAttrs);
173
+ }
174
+ else if (fixedtype === Dwg_Object_Type.DWG_TYPE_UNKNOWN_ENT) {
175
+ this.unknownEntityCount++;
176
+ }
177
+ }
178
+ return undefined;
179
+ }
180
+ convert3dFace(entity, commonAttrs) {
181
+ const libredwg = this.libredwg;
182
+ const corner1 = libredwg.dwg_dynapi_entity_data(entity, 'corner1');
183
+ const corner2 = libredwg.dwg_dynapi_entity_data(entity, 'corner2');
184
+ const corner3 = libredwg.dwg_dynapi_entity_data(entity, 'corner3');
185
+ const corner4 = libredwg.dwg_dynapi_entity_data(entity, 'corner4');
186
+ const flag = libredwg.dwg_dynapi_entity_data(entity, 'invis_flags');
187
+ return {
188
+ type: '3DFACE',
189
+ ...commonAttrs,
190
+ corner1: corner1,
191
+ corner2: corner2,
192
+ corner3: corner3,
193
+ corner4: corner4,
194
+ flag: flag
195
+ };
196
+ }
197
+ convert3dSolid(entity, commonAttrs) {
198
+ const libredwg = this.libredwg;
199
+ const version = libredwg.dwg_dynapi_entity_data(entity, 'version');
200
+ const satCache = libredwg.dwg_dynapi_entity_data(entity, 'acis_empty');
201
+ const data = libredwg.dwg_dynapi_entity_data(entity, 'acis_data');
202
+ const hasRevisionGuid = libredwg.dwg_dynapi_entity_data(entity, 'has_revision_guid');
203
+ const historyRef = libredwg.dwg_dynapi_entity_data(entity, 'history_id');
204
+ const historyObjectSoftId = libredwg.dwg_ref_get_id(historyRef);
205
+ const result = {
206
+ type: '3DSOLID',
207
+ subclassMarker: 'AcDb3dSolid',
208
+ ...commonAttrs
209
+ };
210
+ if (version) {
211
+ result.version = version;
212
+ }
213
+ result.satCache = satCache;
214
+ if (data) {
215
+ result.data = data;
216
+ }
217
+ if (hasRevisionGuid) {
218
+ const guidOffset = libredwg.dwg_dynapi_entity_field_offset(entity, 'revision_guid');
219
+ if (guidOffset >= 0) {
220
+ const guid = libredwg.UTF8ToString(entity + guidOffset, 38);
221
+ if (guid) {
222
+ result.guid = guid;
223
+ }
224
+ }
225
+ }
226
+ if (historyObjectSoftId) {
227
+ result.historyObjectSoftId = historyObjectSoftId;
228
+ }
229
+ return result;
230
+ }
231
+ convertArc(entity, commonAttrs) {
232
+ const libredwg = this.libredwg;
233
+ const center = libredwg.dwg_dynapi_entity_data(entity, 'center');
234
+ const radius = libredwg.dwg_dynapi_entity_data(entity, 'radius');
235
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
236
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
237
+ const startAngle = libredwg.dwg_dynapi_entity_data(entity, 'start_angle');
238
+ const endAngle = libredwg.dwg_dynapi_entity_data(entity, 'end_angle');
239
+ return {
240
+ type: 'ARC',
241
+ ...commonAttrs,
242
+ thickness: thickness,
243
+ center: center,
244
+ radius: radius,
245
+ startAngle: startAngle,
246
+ endAngle: endAngle,
247
+ extrusionDirection: extrusionDirection
248
+ };
249
+ }
250
+ convertArcAlignedText(entity, commonAttrs) {
251
+ const libredwg = this.libredwg;
252
+ const numberField = (field, fallback = 0) => {
253
+ const value = libredwg.dwg_dynapi_entity_data(entity, field);
254
+ if (typeof value === 'number' && Number.isFinite(value))
255
+ return value;
256
+ if (typeof value === 'string' && value.trim() !== '') {
257
+ const parsed = Number(value);
258
+ if (Number.isFinite(parsed))
259
+ return parsed;
260
+ }
261
+ return fallback;
262
+ };
263
+ const center = libredwg.dwg_dynapi_entity_data(entity, 'center');
264
+ const extrusion = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
265
+ const arcRef = libredwg.dwg_dynapi_entity_data(entity, 'arc_handle');
266
+ const xScale = numberField('xscale', 1);
267
+ return {
268
+ type: 'ARCALIGNEDTEXT',
269
+ ...commonAttrs,
270
+ text: libredwg.dwg_dynapi_entity_data(entity, 'text_value') ?? '',
271
+ textSize: numberField('text_size'),
272
+ xScale: xScale > 0 ? xScale : 1,
273
+ characterSpacing: numberField('char_spacing'),
274
+ styleName: libredwg.dwg_dynapi_entity_data(entity, 'style') ?? '',
275
+ fontName: libredwg.dwg_dynapi_entity_data(entity, 'font_name') ?? '',
276
+ bigFontName: libredwg.dwg_dynapi_entity_data(entity, 'bigfont_name') ?? '',
277
+ offsetFromArc: numberField('offset_from_arc'),
278
+ rightOffset: numberField('right_offset'),
279
+ leftOffset: numberField('left_offset'),
280
+ center: center ?? { x: 0, y: 0, z: 0 },
281
+ radius: libredwg.dwg_dynapi_entity_data(entity, 'radius') ?? 0,
282
+ startAngle: libredwg.dwg_dynapi_entity_data(entity, 'start_angle') ?? 0,
283
+ endAngle: libredwg.dwg_dynapi_entity_data(entity, 'end_angle') ?? 0,
284
+ extrusionDirection: extrusion ?? { x: 0, y: 0, z: 1 },
285
+ rawTextColor: libredwg.dwg_dynapi_entity_data(entity, 'color') ?? 256,
286
+ characterSet: libredwg.dwg_dynapi_entity_data(entity, 'character_set') ?? 0,
287
+ pitchAndFamily: libredwg.dwg_dynapi_entity_data(entity, 'pitch_and_family') ?? 0,
288
+ isShx: (libredwg.dwg_dynapi_entity_data(entity, 'is_shx') ?? 0) !== 0,
289
+ isBold: (libredwg.dwg_dynapi_entity_data(entity, 'is_bold') ?? 0) !== 0,
290
+ isItalic: (libredwg.dwg_dynapi_entity_data(entity, 'is_italic') ?? 0) !== 0,
291
+ isUnderlined: (libredwg.dwg_dynapi_entity_data(entity, 'is_underlined') ?? 0) !== 0,
292
+ alignment: libredwg.dwg_dynapi_entity_data(entity, 'alignment') ?? 0,
293
+ isReverse: (libredwg.dwg_dynapi_entity_data(entity, 'is_reverse') ?? 0) !== 0,
294
+ wizardFlag: libredwg.dwg_dynapi_entity_data(entity, 'wizard_flag') ?? 0,
295
+ textPosition: libredwg.dwg_dynapi_entity_data(entity, 'text_position') ?? 1,
296
+ textDirection: libredwg.dwg_dynapi_entity_data(entity, 'text_direction') ?? 1,
297
+ arcHandle: arcRef ? (libredwg.dwg_ref_get_id(arcRef) ?? '') : ''
298
+ };
299
+ }
300
+ convertEmbeddedMText(entity, subclassName) {
301
+ const libredwg = this.libredwg;
302
+ const attachmentPoint = libredwg.dwg_dynapi_subclass_data(entity, subclassName, 'attachment');
303
+ const insertionPoint = libredwg.dwg_dynapi_subclass_data(entity, subclassName, 'ins_pt');
304
+ const direction = libredwg.dwg_dynapi_subclass_data(entity, subclassName, 'x_axis_dir');
305
+ const rectHeight = libredwg.dwg_dynapi_subclass_data(entity, subclassName, 'rect_height');
306
+ const rectWidth = libredwg.dwg_dynapi_subclass_data(entity, subclassName, 'rect_width');
307
+ const extentsHeight = libredwg.dwg_dynapi_subclass_data(entity, subclassName, 'extents_height');
308
+ const extentsWidth = libredwg.dwg_dynapi_subclass_data(entity, subclassName, 'extents_width');
309
+ // const columnType = libredwg.dwg_dynapi_subclass_value(entity, subclassName, 'column_type')
310
+ // .data as number
311
+ // const columnWidth = libredwg.dwg_dynapi_subclass_value(entity, subclassName, 'column_width')
312
+ // .data as number
313
+ // const columnGutter = libredwg.dwg_dynapi_subclass_value(entity, subclassName, 'gutter')
314
+ // .data as number
315
+ // const columnAutoHeight = libredwg.dwg_dynapi_subclass_value(
316
+ // entity,
317
+ // subclassName,
318
+ // 'auto_height'
319
+ // ).data as number
320
+ // const columnFlowReversed = libredwg.dwg_dynapi_subclass_value(
321
+ // entity,
322
+ // subclassName,
323
+ // 'flow_reversed'
324
+ // ).data as number
325
+ // const columnHeightCount = libredwg.dwg_dynapi_subclass_value(
326
+ // entity,
327
+ // subclassName,
328
+ // 'num_column_heights'
329
+ // ).data as number
330
+ // const columnHeights_ptr = libredwg.dwg_dynapi_subclass_value(
331
+ // entity,
332
+ // subclassName,
333
+ // 'column_heights'
334
+ // ).data as number
335
+ // const columnHeights = libredwg.dwg_ptr_to_double_array(
336
+ // columnHeights_ptr,
337
+ // columnHeightCount
338
+ // )
339
+ return {
340
+ insertionPoint: insertionPoint,
341
+ rectHeight: rectHeight,
342
+ rectWidth: rectWidth,
343
+ extentsHeight: extentsHeight,
344
+ extentsWidth: extentsWidth,
345
+ attachmentPoint: attachmentPoint,
346
+ direction: direction
347
+ // columnType: columnType,
348
+ // columnFlowReversed: columnFlowReversed,
349
+ // columnAutoHeight: columnAutoHeight,
350
+ // columnWidth: columnWidth,
351
+ // columnGutter: columnGutter,
352
+ // columnHeightCount: columnHeightCount,
353
+ // columnHeights: columnHeights
354
+ };
355
+ }
356
+ convertAttdef(entity, commonAttrs) {
357
+ const libredwg = this.libredwg;
358
+ // Because the field name of text string in Dwg_Entity_ATTDEF is 'default_value'
359
+ // instead of 'text_value'. So we need to get its value again using the correct
360
+ // field name.
361
+ const textValue = libredwg.dwg_dynapi_entity_data(entity, 'default_value');
362
+ const text = this.convertTextBase(entity);
363
+ text.text = textValue;
364
+ const prompt = libredwg.dwg_dynapi_entity_data(entity, 'prompt');
365
+ const tag = libredwg.dwg_dynapi_entity_data(entity, 'tag');
366
+ const flags = libredwg.dwg_dynapi_entity_data(entity, 'flags');
367
+ const fieldLength = libredwg.dwg_dynapi_entity_data(entity, 'field_length');
368
+ const lockPositionFlag = libredwg.dwg_dynapi_entity_data(entity, 'lock_position_flag');
369
+ const duplicateRecordCloningFlag = libredwg.dwg_dynapi_entity_data(entity, 'keep_duplicate_records');
370
+ const isReallyLocked = libredwg.dwg_dynapi_entity_data(entity, 'is_really_locked');
371
+ // TODO: double check whether 'mtext_type' is 'mtextFlag'
372
+ const mtextFlag = libredwg.dwg_dynapi_entity_data(entity, 'mtext_type');
373
+ const alignmentPoint = libredwg.dwg_dynapi_entity_data(entity, 'alignment_pt');
374
+ return {
375
+ type: 'ATTDEF',
376
+ ...commonAttrs,
377
+ text: this.convertTextBase(entity),
378
+ prompt: prompt,
379
+ tag: tag,
380
+ flags: flags,
381
+ fieldLength: fieldLength,
382
+ lockPositionFlag: lockPositionFlag > 0,
383
+ duplicateRecordCloningFlag: duplicateRecordCloningFlag > 0,
384
+ mtextFlag: mtextFlag,
385
+ isReallyLocked: isReallyLocked > 0,
386
+ alignmentPoint: alignmentPoint,
387
+ annotationScale: 1, // TODO: Set the correct value
388
+ attrTag: '', // TODO: Set the correct value
389
+ mtext: this.convertEmbeddedMText(entity, 'ATTDEF_mtext')
390
+ };
391
+ }
392
+ convertAttrib(entity, commonAttrs) {
393
+ const libredwg = this.libredwg;
394
+ const text = this.convertTextBase(entity);
395
+ const tag = libredwg.dwg_dynapi_entity_data(entity, 'tag');
396
+ const flags = libredwg.dwg_dynapi_entity_data(entity, 'flags');
397
+ const fieldLength = libredwg.dwg_dynapi_entity_data(entity, 'field_length');
398
+ const lockPositionFlag = libredwg.dwg_dynapi_entity_data(entity, 'lock_position_flag');
399
+ const duplicateRecordCloningFlag = libredwg.dwg_dynapi_entity_data(entity, 'keep_duplicate_records');
400
+ // TODO: double check whether 'mtext_type' is 'mtextFlag'
401
+ const mtextFlag = libredwg.dwg_dynapi_entity_data(entity, 'mtext_type');
402
+ const isReallyLocked = libredwg.dwg_dynapi_entity_data(entity, 'is_really_locked');
403
+ const alignmentPoint = libredwg.dwg_dynapi_entity_data(entity, 'alignment_pt');
404
+ return {
405
+ type: 'ATTRIB',
406
+ ...commonAttrs,
407
+ text: text,
408
+ tag: tag,
409
+ flags: flags,
410
+ fieldLength: fieldLength,
411
+ lockPositionFlag: !!lockPositionFlag,
412
+ duplicateRecordCloningFlag: !!duplicateRecordCloningFlag,
413
+ mtextFlag: mtextFlag,
414
+ isReallyLocked: !!isReallyLocked,
415
+ numberOfSecondaryAttrs: 0, // TODO: libredwg doesn't support it yet.
416
+ secondaryAttrsHardId: '0', // TODO: libredwg doesn't support it yet.
417
+ alignmentPoint: { ...alignmentPoint, z: 0 },
418
+ annotationScale: 1, // TODO: Set the correct value
419
+ attrTag: '', // TODO: Set the correct value
420
+ mtext: this.convertEmbeddedMText(entity, 'ATTDEF_mtext')
421
+ };
422
+ }
423
+ convertCircle(entity, commonAttrs) {
424
+ const libredwg = this.libredwg;
425
+ const center = libredwg.dwg_dynapi_entity_data(entity, 'center');
426
+ const radius = libredwg.dwg_dynapi_entity_data(entity, 'radius');
427
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
428
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
429
+ return {
430
+ type: 'CIRCLE',
431
+ ...commonAttrs,
432
+ thickness: thickness,
433
+ center: center,
434
+ radius: radius,
435
+ extrusionDirection: extrusionDirection
436
+ };
437
+ }
438
+ convertAlignedDimension(entity, commonAttrs) {
439
+ const libredwg = this.libredwg;
440
+ const dimensionCommonAttrs = this.getDimensionCommonAttrs(entity);
441
+ // TODO: Not sure whether 'clone_ins_pt' is same as 'insertionPoint'
442
+ const insertionPoint = libredwg.dwg_dynapi_entity_data(entity, 'clone_ins_pt');
443
+ const subDefinitionPoint1 = libredwg.dwg_dynapi_entity_data(entity, 'xline1_pt');
444
+ const subDefinitionPoint2 = libredwg.dwg_dynapi_entity_data(entity, 'xline2_pt');
445
+ const rotationAngle = libredwg.dwg_dynapi_entity_data(entity, 'ins_rotation');
446
+ const obliqueAngle = libredwg.dwg_dynapi_entity_data(entity, 'oblique_angle');
447
+ return {
448
+ subclassMarker: 'AcDbAlignedDimension',
449
+ ...commonAttrs,
450
+ ...dimensionCommonAttrs,
451
+ insertionPoint: insertionPoint,
452
+ subDefinitionPoint1: subDefinitionPoint1,
453
+ subDefinitionPoint2: subDefinitionPoint2,
454
+ rotationAngle: rotationAngle == null ? 0 : rotationAngle,
455
+ obliqueAngle: obliqueAngle
456
+ };
457
+ }
458
+ convert3PointAngularDimension(entity, commonAttrs) {
459
+ const libredwg = this.libredwg;
460
+ const dimensionCommonAttrs = this.getDimensionCommonAttrs(entity);
461
+ const subDefinitionPoint1 = libredwg.dwg_dynapi_entity_data(entity, 'xline1_pt');
462
+ const subDefinitionPoint2 = libredwg.dwg_dynapi_entity_data(entity, 'xline2_pt');
463
+ const centerPoint = libredwg.dwg_dynapi_entity_data(entity, 'center_pt');
464
+ const arcPoint = libredwg.dwg_dynapi_entity_data(entity, 'xline2end_pt');
465
+ return {
466
+ subclassMarker: 'AcDb3PointAngularDimension',
467
+ ...commonAttrs,
468
+ ...dimensionCommonAttrs,
469
+ subDefinitionPoint1: subDefinitionPoint1,
470
+ subDefinitionPoint2: subDefinitionPoint2,
471
+ centerPoint: centerPoint,
472
+ arcPoint: arcPoint
473
+ };
474
+ }
475
+ convert2LineAngularDimension(entity, commonAttrs) {
476
+ const libredwg = this.libredwg;
477
+ const dimensionCommonAttrs = this.getDimensionCommonAttrs(entity);
478
+ const xline1Start = libredwg.dwg_dynapi_entity_data(entity, 'xline1start_pt');
479
+ const xline1End = libredwg.dwg_dynapi_entity_data(entity, 'xline1end_pt');
480
+ const xline2Start = libredwg.dwg_dynapi_entity_data(entity, 'xline2start_pt');
481
+ const xline2End = libredwg.dwg_dynapi_entity_data(entity, 'xline2end_pt');
482
+ const vertexPoint = libredwg.dwg_dynapi_entity_data(entity, 'def_pt');
483
+ // For 2-line angular dimensions DXF group 10 is the arc location (xline2end_pt),
484
+ // not def_pt which stores the dimension line location (DXF group 16).
485
+ if (xline2End) {
486
+ dimensionCommonAttrs.definitionPoint = xline2End;
487
+ }
488
+ return {
489
+ subclassMarker: 'AcDb2LineAngularDimension',
490
+ ...commonAttrs,
491
+ ...dimensionCommonAttrs,
492
+ subDefinitionPoint1: xline1Start ?? xline1End ?? vertexPoint ?? xline2End,
493
+ subDefinitionPoint2: xline2Start ?? xline2End ?? vertexPoint ?? xline1End,
494
+ centerPoint: vertexPoint ?? xline2Start ?? xline1End ?? xline2End,
495
+ arcPoint: xline2End ?? dimensionCommonAttrs.definitionPoint
496
+ };
497
+ }
498
+ convertDiameterDimension(entity, commonAttrs) {
499
+ const libredwg = this.libredwg;
500
+ const dimensionCommonAttrs = this.getDimensionCommonAttrs(entity);
501
+ // TODO: Not sure whether 'first_arc_pt' is same as 'centerPoint'
502
+ const centerPoint = libredwg.dwg_dynapi_entity_data(entity, 'first_arc_pt');
503
+ const leaderLength = libredwg.dwg_dynapi_entity_data(entity, 'leader_len');
504
+ return {
505
+ subclassMarker: 'AcDbDiametricDimension',
506
+ ...commonAttrs,
507
+ ...dimensionCommonAttrs,
508
+ centerPoint: centerPoint,
509
+ leaderLength: leaderLength
510
+ };
511
+ }
512
+ convertOrdinateDimension(entity, commonAttrs) {
513
+ const libredwg = this.libredwg;
514
+ const dimensionCommonAttrs = this.getDimensionCommonAttrs(entity);
515
+ // TODO: Not sure whether 'feature_location_pt' is same as 'subDefinitionPoint1'
516
+ const subDefinitionPoint1 = libredwg.dwg_dynapi_entity_data(entity, 'feature_location_pt');
517
+ // TODO: Not sure whether 'leader_endpt' is same as 'subDefinitionPoint2'
518
+ const subDefinitionPoint2 = libredwg.dwg_dynapi_entity_data(entity, 'leader_endpt');
519
+ return {
520
+ subclassMarker: 'AcDbOrdinateDimension',
521
+ ...commonAttrs,
522
+ ...dimensionCommonAttrs,
523
+ subDefinitionPoint1: subDefinitionPoint1,
524
+ subDefinitionPoint2: subDefinitionPoint2
525
+ };
526
+ }
527
+ convertRadiusDimension(entity, commonAttrs) {
528
+ const libredwg = this.libredwg;
529
+ const dimensionCommonAttrs = this.getDimensionCommonAttrs(entity);
530
+ // TODO: Not sure whether 'first_arc_pt' is same as 'centerPoint'
531
+ const centerPoint = libredwg.dwg_dynapi_entity_data(entity, 'first_arc_pt');
532
+ const leaderLength = libredwg.dwg_dynapi_entity_data(entity, 'leader_len');
533
+ return {
534
+ subclassMarker: 'AcDbRadialDimension',
535
+ ...commonAttrs,
536
+ ...dimensionCommonAttrs,
537
+ centerPoint: centerPoint,
538
+ leaderLength: leaderLength
539
+ };
540
+ }
541
+ convertEllise(entity, commonAttrs) {
542
+ const libredwg = this.libredwg;
543
+ const center = libredwg.dwg_dynapi_entity_data(entity, 'center');
544
+ const majorAxisEndPoint = libredwg.dwg_dynapi_entity_data(entity, 'sm_axis');
545
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
546
+ const axisRatio = libredwg.dwg_dynapi_entity_data(entity, 'axis_ratio');
547
+ const startAngle = libredwg.dwg_dynapi_entity_data(entity, 'start_angle');
548
+ const endAngle = libredwg.dwg_dynapi_entity_data(entity, 'end_angle');
549
+ return {
550
+ type: 'ELLIPSE',
551
+ ...commonAttrs,
552
+ center: center,
553
+ majorAxisEndPoint: majorAxisEndPoint,
554
+ extrusionDirection: extrusionDirection,
555
+ axisRatio: axisRatio,
556
+ startAngle: startAngle,
557
+ endAngle: endAngle
558
+ };
559
+ }
560
+ convertHatch(entity, commonAttrs) {
561
+ const libredwg = this.libredwg;
562
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
563
+ const patternName = libredwg.dwg_dynapi_entity_data(entity, 'name');
564
+ const isSolidFill = libredwg.dwg_dynapi_entity_data(entity, 'is_solid_fill');
565
+ const isAssociative = libredwg.dwg_dynapi_entity_data(entity, 'is_associative');
566
+ const numberOfBoundaryPaths = libredwg.dwg_dynapi_entity_data(entity, 'num_paths');
567
+ const paths_ptr = libredwg.dwg_dynapi_entity_data(entity, 'paths');
568
+ const boundaryPaths = libredwg.dwg_ptr_to_hatch_path_array(paths_ptr, numberOfBoundaryPaths);
569
+ const patternStyle = libredwg.dwg_dynapi_entity_data(entity, 'style');
570
+ const patternType = libredwg.dwg_dynapi_entity_data(entity, 'pattern_type');
571
+ const patternAngle = libredwg.dwg_dynapi_entity_data(entity, 'angle');
572
+ const patternScale = libredwg.dwg_dynapi_entity_data(entity, 'scale_spacing');
573
+ const numberOfDefinitionLines = libredwg.dwg_dynapi_entity_data(entity, 'num_deflines');
574
+ const definitionLines_ptr = libredwg.dwg_dynapi_entity_data(entity, 'deflines');
575
+ const definitionLines = libredwg.dwg_ptr_to_hatch_defline_array(definitionLines_ptr, numberOfDefinitionLines);
576
+ const pixelSize = libredwg.dwg_dynapi_entity_data(entity, 'pixel_size');
577
+ const numberOfSeedPoints = libredwg.dwg_dynapi_entity_data(entity, 'num_seeds');
578
+ const seedPoints_ptr = libredwg.dwg_dynapi_entity_data(entity, 'seeds');
579
+ const seedPoints = libredwg.dwg_ptr_to_point2d_array(seedPoints_ptr, numberOfSeedPoints);
580
+ const result = {
581
+ ...commonAttrs,
582
+ // elevationPoint: DwgPoint3D
583
+ extrusionDirection: extrusionDirection,
584
+ patternName: patternName,
585
+ solidFill: isSolidFill
586
+ ? DwgHatchSolidFill.SolidFill
587
+ : DwgHatchSolidFill.PatternFill,
588
+ // patternFillColor: number
589
+ associativity: isAssociative
590
+ ? DwgHatchAssociativity.Associative
591
+ : DwgHatchAssociativity.NonAssociative,
592
+ numberOfBoundaryPaths: numberOfBoundaryPaths,
593
+ boundaryPaths: this.convertHatchBoundaryPaths(boundaryPaths),
594
+ hatchStyle: patternStyle,
595
+ patternType: patternType,
596
+ patternAngle: patternAngle,
597
+ patternScale: patternScale,
598
+ numberOfDefinitionLines: numberOfDefinitionLines,
599
+ definitionLines: definitionLines.map(value => {
600
+ return {
601
+ angle: value.angle,
602
+ base: value.pt0,
603
+ offset: value.offset,
604
+ numberOfDashLengths: value.dashes.length,
605
+ dashLengths: value.dashes
606
+ };
607
+ }),
608
+ pixelSize: pixelSize,
609
+ numberOfSeedPoints: numberOfSeedPoints,
610
+ // offsetVector?: DwgPoint3D
611
+ seedPoints: seedPoints
612
+ // gradientFlag?: DwgHatchGradientFlag
613
+ };
614
+ const gradientFlag = libredwg.dwg_dynapi_entity_data(entity, 'is_gradient_fill');
615
+ if (gradientFlag > 0) {
616
+ const gradientName = libredwg.dwg_dynapi_entity_data(entity, 'gradient_name');
617
+ const gradientRotation = libredwg.dwg_dynapi_entity_data(entity, 'gradient_angle');
618
+ const gradientDefinition = libredwg.dwg_dynapi_entity_data(entity, 'gradient_shift');
619
+ const colorTint = libredwg.dwg_dynapi_entity_data(entity, 'gradient_tint');
620
+ const gradientColorFlag = libredwg.dwg_dynapi_entity_data(entity, 'single_color_gradient');
621
+ // const numberOfColors = libredwg.dwg_dynapi_entity_value(entity, 'num_colors')
622
+ // .data as number
623
+ const gradientColors_ptr = libredwg.dwg_dynapi_entity_data(entity, 'colors');
624
+ const gradientColors = libredwg.dwg_ptr_to_hatch_gradient_color_array(gradientColors_ptr, (gradientColorFlag == 1) ? 1 : 2);
625
+ return {
626
+ type: 'HATCH',
627
+ ...result,
628
+ gradientFlag: DwgHatchGradientFlag.Gradient,
629
+ gradientColorFlag: gradientColorFlag == 1 ? DwgHatchGradientColorFlag.OneColor : DwgHatchGradientColorFlag.TwoColor,
630
+ gradientName,
631
+ gradientRotation,
632
+ gradientDefinition,
633
+ colorTint,
634
+ gradientColors
635
+ };
636
+ }
637
+ else {
638
+ return {
639
+ type: 'HATCH',
640
+ ...result
641
+ };
642
+ }
643
+ }
644
+ convertHatchBoundaryPaths(paths) {
645
+ const converted = paths
646
+ .filter(path => path.num_segs_or_paths > 0)
647
+ .map(path => {
648
+ const commonAttrs = {
649
+ boundaryPathTypeFlag: path.flag
650
+ };
651
+ // Check whether it is a polyline
652
+ if (path.flag & 0x02) {
653
+ return {
654
+ ...commonAttrs,
655
+ hasBulge: path.bulges_present,
656
+ isClosed: path.closed,
657
+ numberOfVertices: path.num_segs_or_paths,
658
+ vertices: path.polyline_paths.map(vertex => {
659
+ return {
660
+ x: vertex.point.x,
661
+ y: vertex.point.y,
662
+ bulge: vertex.bulge
663
+ };
664
+ })
665
+ };
666
+ }
667
+ else {
668
+ const edges = path.segs
669
+ .map(seg => {
670
+ if (seg.curve_type == Dwg_Hatch_Edge_Type.Line) {
671
+ return {
672
+ type: DwgBoundaryPathEdgeType.Line,
673
+ start: seg.first_endpoint,
674
+ end: seg.second_endpoint
675
+ };
676
+ }
677
+ else if (seg.curve_type == Dwg_Hatch_Edge_Type.CircularArc) {
678
+ return {
679
+ type: DwgBoundaryPathEdgeType.Circular,
680
+ center: seg.center,
681
+ radius: seg.radius,
682
+ startAngle: seg.start_angle,
683
+ endAngle: seg.end_angle,
684
+ isCCW: seg.is_ccw
685
+ };
686
+ }
687
+ else if (seg.curve_type == Dwg_Hatch_Edge_Type.EllipticArc) {
688
+ return {
689
+ type: DwgBoundaryPathEdgeType.Elliptic,
690
+ center: seg.center,
691
+ end: seg.endpoint,
692
+ lengthOfMinorAxis: seg.minor_major_ratio,
693
+ startAngle: seg.start_angle,
694
+ endAngle: seg.end_angle,
695
+ isCCW: seg.is_ccw
696
+ };
697
+ }
698
+ else if (seg.curve_type == Dwg_Hatch_Edge_Type.Spline) {
699
+ return {
700
+ type: DwgBoundaryPathEdgeType.Spline,
701
+ degree: seg.degree,
702
+ isRational: seg.is_rational,
703
+ isPeriodic: seg.is_periodic,
704
+ numberOfKnots: seg.num_knots,
705
+ numberOfControlPoints: seg.num_control_points,
706
+ knots: seg.knots,
707
+ controlPoints: seg.control_points,
708
+ numberOfFitData: seg.num_fitpts,
709
+ fitDatum: seg.fitpts,
710
+ startTangent: seg.start_tangent,
711
+ endTangent: seg.end_tangent
712
+ };
713
+ }
714
+ return undefined;
715
+ })
716
+ .filter((edge) => edge != null);
717
+ return {
718
+ ...commonAttrs,
719
+ numberOfEdges: edges.length,
720
+ edges: edges
721
+ };
722
+ }
723
+ });
724
+ return converted;
725
+ }
726
+ convertImage(entity, commonAttrs) {
727
+ const libredwg = this.libredwg;
728
+ const version = libredwg.dwg_dynapi_entity_data(entity, 'class_version');
729
+ const position = libredwg.dwg_dynapi_entity_data(entity, 'pt0');
730
+ const uPixel = libredwg.dwg_dynapi_entity_data(entity, 'uvec');
731
+ const vPixel = libredwg.dwg_dynapi_entity_data(entity, 'vvec');
732
+ const imageSize = libredwg.dwg_dynapi_entity_data(entity, 'image_size');
733
+ const flags = libredwg.dwg_dynapi_entity_data(entity, 'display_props');
734
+ const clipping = libredwg.dwg_dynapi_entity_data(entity, 'clipping');
735
+ const brightness = libredwg.dwg_dynapi_entity_data(entity, 'brightness');
736
+ const contrast = libredwg.dwg_dynapi_entity_data(entity, 'contrast');
737
+ const fade = libredwg.dwg_dynapi_entity_data(entity, 'fade');
738
+ const clipMode = libredwg.dwg_dynapi_entity_data(entity, 'clip_mode');
739
+ const clippingBoundaryType = libredwg.dwg_dynapi_entity_data(entity, 'clip_boundary_type');
740
+ const countBoundaryPoints = libredwg.dwg_dynapi_entity_data(entity, 'num_clip_verts');
741
+ const clip_verts = libredwg.dwg_dynapi_entity_data(entity, 'clip_verts');
742
+ const clippingBoundaryPath = libredwg.dwg_ptr_to_point3d_array(clip_verts, countBoundaryPoints);
743
+ const imagedef_ref = libredwg.dwg_dynapi_entity_data(entity, 'imagedef');
744
+ const imageDefHandle = (libredwg.dwg_ref_get_id(imagedef_ref) ?? '');
745
+ const imagedefreactor_ref = libredwg.dwg_dynapi_entity_data(entity, 'imagedefreactor');
746
+ const imageDefReactorHandle = (libredwg.dwg_ref_get_id(imagedefreactor_ref) ?? '');
747
+ return {
748
+ type: 'IMAGE',
749
+ ...commonAttrs,
750
+ version: version,
751
+ position: position,
752
+ uPixel: uPixel,
753
+ vPixel: vPixel,
754
+ imageSize: imageSize,
755
+ imageDefHandle: imageDefHandle,
756
+ flags: flags,
757
+ clipping: clipping,
758
+ brightness: brightness,
759
+ contrast: contrast,
760
+ fade: fade,
761
+ imageDefReactorHandle: imageDefReactorHandle,
762
+ clippingBoundaryType: clippingBoundaryType,
763
+ countBoundaryPoints: countBoundaryPoints,
764
+ clippingBoundaryPath: clippingBoundaryPath,
765
+ clipMode: clipMode
766
+ };
767
+ }
768
+ convertInsert(entity, commonAttrs) {
769
+ const libredwg = this.libredwg;
770
+ // Get block name
771
+ let name = '';
772
+ const block_header_ref = libredwg.dwg_dynapi_entity_data(entity, 'block_header');
773
+ if (block_header_ref) {
774
+ const block_header_obj = libredwg.dwg_ref_get_object(block_header_ref);
775
+ if (block_header_obj) {
776
+ const block_header_tio = libredwg.dwg_object_to_object_tio(block_header_obj);
777
+ if (block_header_tio) {
778
+ name =
779
+ libredwg.dwg_entity_block_header_get_block(block_header_tio).name;
780
+ }
781
+ }
782
+ }
783
+ if (!name) {
784
+ /* pre-R2.0 */
785
+ name = libredwg.dwg_dynapi_entity_data(entity, 'block_name');
786
+ }
787
+ const insertionPoint = libredwg.dwg_dynapi_entity_data(entity, 'ins_pt');
788
+ const scale = libredwg.dwg_dynapi_entity_data(entity, 'scale');
789
+ const rotation = libredwg.dwg_dynapi_entity_data(entity, 'rotation');
790
+ const columnCount = libredwg.dwg_dynapi_entity_data(entity, 'num_cols');
791
+ const rowCount = libredwg.dwg_dynapi_entity_data(entity, 'num_rows');
792
+ const columnSpacing = libredwg.dwg_dynapi_entity_data(entity, 'col_spacing');
793
+ const rowSpacing = libredwg.dwg_dynapi_entity_data(entity, 'row_spacing');
794
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
795
+ const attrib_ptr_array = libredwg.dwg_entity_insert_get_attribs(entity);
796
+ const attribs = [];
797
+ attrib_ptr_array.forEach(object_ptr => {
798
+ const entity = libredwg.dwg_object_to_entity(object_ptr);
799
+ const entity_tio = libredwg.dwg_object_to_entity_tio(object_ptr);
800
+ if (entity && entity_tio) {
801
+ // Get values of the common attributes of ATTRIB entity
802
+ const commonAttrs = this.getCommonAttrs(entity);
803
+ const fixedtype = libredwg.dwg_object_get_fixedtype(object_ptr);
804
+ if (fixedtype == Dwg_Object_Type.DWG_TYPE_ATTRIB) {
805
+ attribs.push(this.convertAttrib(entity_tio, commonAttrs));
806
+ }
807
+ }
808
+ });
809
+ // TODO: convert block attributes
810
+ return {
811
+ type: 'INSERT',
812
+ ...commonAttrs,
813
+ name: name,
814
+ insertionPoint: insertionPoint,
815
+ xScale: scale ? scale.x : 1,
816
+ yScale: scale ? scale.y : 1,
817
+ zScale: scale ? scale.z : 1,
818
+ rotation: rotation,
819
+ columnCount: columnCount,
820
+ rowCount: rowCount,
821
+ columnSpacing: columnSpacing,
822
+ rowSpacing: rowSpacing,
823
+ extrusionDirection: extrusionDirection,
824
+ attribs: attribs
825
+ };
826
+ }
827
+ convertLeader(entity, commonAttrs) {
828
+ const libredwg = this.libredwg;
829
+ const styleName = libredwg.dwg_entity_mtext_get_style_name(entity);
830
+ const isArrowheadEnabled = libredwg.dwg_dynapi_entity_data(entity, 'arrowhead_type');
831
+ const isSpline = libredwg.dwg_dynapi_entity_data(entity, 'path_type');
832
+ const leaderCreationFlag = libredwg.dwg_dynapi_entity_data(entity, 'annot_type');
833
+ const isHooklineSameDirection = libredwg.dwg_dynapi_entity_data(entity, 'hookline_dir');
834
+ const isHooklineExists = libredwg.dwg_dynapi_entity_data(entity, 'hookline_on');
835
+ const textHeight = libredwg.dwg_dynapi_entity_data(entity, 'box_height');
836
+ const textWidth = libredwg.dwg_dynapi_entity_data(entity, 'box_width');
837
+ const numberOfVertices = libredwg.dwg_dynapi_entity_data(entity, 'num_points');
838
+ const vertices_ptr = libredwg.dwg_dynapi_entity_data(entity, 'points');
839
+ const vertices = numberOfVertices > 0
840
+ ? libredwg.dwg_ptr_to_point3d_array(vertices_ptr, numberOfVertices)
841
+ : [];
842
+ const byBlockColor = libredwg.dwg_dynapi_entity_data(entity, 'byblock_color');
843
+ const normal = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
844
+ const horizontalDirection = libredwg.dwg_dynapi_entity_data(entity, 'x_direction');
845
+ const offsetFromBlock = libredwg.dwg_dynapi_entity_data(entity, 'inspt_offset');
846
+ const offsetFromAnnotation = libredwg.dwg_dynapi_entity_data(entity, 'endptproj');
847
+ return {
848
+ type: 'LEADER',
849
+ ...commonAttrs,
850
+ styleName: styleName,
851
+ isArrowheadEnabled: isArrowheadEnabled > 0,
852
+ isSpline: isSpline > 0,
853
+ leaderCreationFlag: leaderCreationFlag,
854
+ isHooklineSameDirection: isHooklineSameDirection > 0,
855
+ isHooklineExists: isHooklineExists > 0,
856
+ textHeight: textHeight,
857
+ textWidth: textWidth,
858
+ numberOfVertices: numberOfVertices,
859
+ vertices: vertices,
860
+ byBlockColor: byBlockColor,
861
+ normal: normal,
862
+ horizontalDirection: horizontalDirection,
863
+ offsetFromBlock: offsetFromBlock,
864
+ offsetFromAnnotation: offsetFromAnnotation
865
+ };
866
+ }
867
+ convertLine(entity, commonAttrs) {
868
+ const libredwg = this.libredwg;
869
+ const startPoint = libredwg.dwg_dynapi_entity_data(entity, 'start');
870
+ const endPoint = libredwg.dwg_dynapi_entity_data(entity, 'end');
871
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
872
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
873
+ return {
874
+ type: 'LINE',
875
+ ...commonAttrs,
876
+ thickness: thickness,
877
+ startPoint: startPoint,
878
+ endPoint: endPoint,
879
+ extrusionDirection: extrusionDirection
880
+ };
881
+ }
882
+ convertLWPolyline(entity, commonAttrs) {
883
+ const libredwg = this.libredwg;
884
+ const numberOfVertices = libredwg.dwg_dynapi_entity_data(entity, 'num_points');
885
+ const flag = libredwg.dwg_dynapi_entity_data(entity, 'flag');
886
+ const constantWidth = libredwg.dwg_dynapi_entity_data(entity, 'const_width');
887
+ const elevation = libredwg.dwg_dynapi_entity_data(entity, 'elevation');
888
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
889
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
890
+ const vertices = [];
891
+ const num_points = libredwg.dwg_dynapi_entity_data(entity, 'num_points');
892
+ const points_ptr = libredwg.dwg_dynapi_entity_data(entity, 'points');
893
+ const points = libredwg.dwg_ptr_to_point2d_array(points_ptr, num_points);
894
+ const num_bulges = libredwg.dwg_dynapi_entity_data(entity, 'num_bulges');
895
+ const bulges_ptr = libredwg.dwg_dynapi_entity_data(entity, 'bulges');
896
+ const bulges = libredwg.dwg_ptr_to_double_array(bulges_ptr, num_bulges);
897
+ // Flag bit 32 = HAS_NUM_WIDTHS. Each Dwg_LWPOLYLINE_width is two BITCODE_BD
898
+ // values (start, end). Without copying these, tapered polylines (e.g. valve
899
+ // triangles) become zero-width lines after conversion.
900
+ const num_widths = libredwg.dwg_dynapi_entity_data(entity, 'num_widths') ?? 0;
901
+ const widths_ptr = libredwg.dwg_dynapi_entity_data(entity, 'widths');
902
+ const widthDoubles = num_widths > 0 && widths_ptr
903
+ ? libredwg.dwg_ptr_to_double_array(widths_ptr, num_widths * 2)
904
+ : [];
905
+ points.forEach((point, index) => {
906
+ const vertex = {
907
+ id: index,
908
+ x: point.x,
909
+ y: point.y,
910
+ bulge: bulges.length > index ? bulges[index] : 0
911
+ };
912
+ if (index < num_widths && widthDoubles.length >= (index + 1) * 2) {
913
+ vertex.startWidth = widthDoubles[index * 2];
914
+ vertex.endWidth = widthDoubles[index * 2 + 1];
915
+ }
916
+ vertices.push(vertex);
917
+ });
918
+ return {
919
+ type: 'LWPOLYLINE',
920
+ ...commonAttrs,
921
+ numberOfVertices: numberOfVertices,
922
+ flag: flag,
923
+ constantWidth: constantWidth,
924
+ elevation: elevation,
925
+ thickness: thickness,
926
+ extrusionDirection: extrusionDirection,
927
+ vertices: vertices
928
+ };
929
+ }
930
+ convertMLine(entity, commonAttrs) {
931
+ const libredwg = this.libredwg;
932
+ const scale = libredwg.dwg_dynapi_entity_data(entity, 'scale');
933
+ const flags = libredwg.dwg_dynapi_entity_data(entity, 'flags');
934
+ const justification = libredwg.dwg_dynapi_entity_data(entity, 'justification');
935
+ const startPoint = libredwg.dwg_dynapi_entity_data(entity, 'base_point');
936
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
937
+ const numberOfLines = libredwg.dwg_dynapi_entity_data(entity, 'num_lines');
938
+ const numberOfVertices = libredwg.dwg_dynapi_entity_data(entity, 'num_verts');
939
+ const verts_ptr = libredwg.dwg_dynapi_entity_data(entity, 'verts');
940
+ const verts = libredwg.dwg_ptr_to_mline_vertex_array(verts_ptr, numberOfVertices);
941
+ const vertices = [];
942
+ verts.forEach(vert => {
943
+ vertices.push({
944
+ vertex: vert.vertex,
945
+ vertexDirection: vert.vertex_direction,
946
+ miterDirection: vert.miter_direction,
947
+ numberOfLines: vert.num_lines,
948
+ lines: vert.lines.map(line => {
949
+ return {
950
+ numberOfSegmentParams: line.num_segparms,
951
+ segmentParams: line.segparms,
952
+ numberOfAreaFillParams: line.num_areafillparms,
953
+ areaFillParams: line.areafillparms
954
+ };
955
+ })
956
+ });
957
+ });
958
+ return {
959
+ type: 'MLINE',
960
+ ...commonAttrs,
961
+ scale: scale,
962
+ flags: flags,
963
+ justification: justification,
964
+ startPoint: startPoint,
965
+ extrusionDirection: extrusionDirection,
966
+ numberOfLines: numberOfLines,
967
+ numberOfVertices: numberOfVertices,
968
+ vertices: vertices,
969
+ mlineStyle: '' // TODO: Set the correct value
970
+ };
971
+ }
972
+ convertMultiLeader(entity, commonAttrs) {
973
+ const libredwg = this.libredwg;
974
+ const entityVal = (field) => libredwg.dwg_dynapi_entity_data(entity, field);
975
+ const subclassVal = (ptr, subclass, field) => libredwg.dwg_dynapi_subclass_data(ptr, subclass, field);
976
+ const refToId = (ref) => libredwg.dwg_ref_get_id(ref);
977
+ const asBool = (value) => value > 0;
978
+ const mleaderColor = (color) => color != null ? dwgColorToMLeaderRawColor(color) : undefined;
979
+ const version = entityVal('class_version');
980
+ const leaderStyleId = refToId(entityVal('mleaderstyle'));
981
+ const propertyOverrideFlag = entityVal('flags');
982
+ const leaderLineType = entityVal('type');
983
+ const leaderLineColor = mleaderColor(entityVal('line_color'));
984
+ const leaderLineTypeId = refToId(entityVal('line_ltype'));
985
+ const leaderLineWeight = entityVal('line_linewt');
986
+ const landingEnabled = asBool(entityVal('has_landing'));
987
+ const doglegEnabled = asBool(entityVal('has_dogleg'));
988
+ const doglegLength = entityVal('landing_dist');
989
+ const arrowheadId = refToId(entityVal('arrow_handle'));
990
+ const arrowheadSize = entityVal('arrow_size');
991
+ const contentType = entityVal('style_content');
992
+ const textStyleId = refToId(entityVal('text_style'));
993
+ const textLeftAttachmentType = entityVal('text_left');
994
+ const textRightAttachmentType = entityVal('text_right');
995
+ const textAngleType = entityVal('text_angletype');
996
+ const textAlignmentType = entityVal('text_alignment');
997
+ const textColor = mleaderColor(entityVal('text_color'));
998
+ const textFrameEnabled = asBool(entityVal('has_text_frame'));
999
+ const blockContentId = refToId(entityVal('block_style'));
1000
+ const blockContentColor = mleaderColor(entityVal('block_color'));
1001
+ const blockContentScale = entityVal('block_scale');
1002
+ const blockContentRotation = entityVal('block_rotation');
1003
+ const blockContentConnectionType = entityVal('style_attachment');
1004
+ const annotativeScaleEnabled = asBool(entityVal('is_annotative'));
1005
+ const textDirectionNegative = asBool(entityVal('is_neg_textdir'));
1006
+ const textAlignInIPE = entityVal('ipe_alignment');
1007
+ let textAttachmentPoint = entityVal('justification');
1008
+ const textAttachmentDirection = entityVal('attach_dir');
1009
+ const bottomTextAttachmentDirection = entityVal('attach_bottom');
1010
+ const topTextAttachmentDirection = entityVal('attach_top');
1011
+ const contentScale = entityVal('scale_factor');
1012
+ const numArrowheads = entityVal('num_arrowheads');
1013
+ const arrowheadsPtr = entityVal('arrowheads');
1014
+ const arrowHeadSize = libredwg.dwg_dynapi_subclass_size('LEADER_ArrowHead');
1015
+ const arrowheadOverrides = [];
1016
+ for (let i = 0; i < numArrowheads; i++) {
1017
+ const arrowheadPtr = arrowheadsPtr + i * arrowHeadSize;
1018
+ arrowheadOverrides.push({
1019
+ index: subclassVal(arrowheadPtr, 'LEADER_ArrowHead', 'is_default'),
1020
+ handle: refToId(subclassVal(arrowheadPtr, 'LEADER_ArrowHead', 'arrowhead')) ?? ''
1021
+ });
1022
+ }
1023
+ const numBlocklabels = entityVal('num_blocklabels');
1024
+ const blocklabelsPtr = entityVal('blocklabels');
1025
+ const blockLabelSize = libredwg.dwg_dynapi_subclass_size('LEADER_BlockLabel');
1026
+ const blockAttributes = [];
1027
+ for (let i = 0; i < numBlocklabels; i++) {
1028
+ const blocklabelPtr = blocklabelsPtr + i * blockLabelSize;
1029
+ blockAttributes.push({
1030
+ id: refToId(subclassVal(blocklabelPtr, 'LEADER_BlockLabel', 'attdef')),
1031
+ index: subclassVal(blocklabelPtr, 'LEADER_BlockLabel', 'ui_index'),
1032
+ width: subclassVal(blocklabelPtr, 'LEADER_BlockLabel', 'width'),
1033
+ text: subclassVal(blocklabelPtr, 'LEADER_BlockLabel', 'label_text')
1034
+ });
1035
+ }
1036
+ const ctxPtr = entity + libredwg.dwg_dynapi_entity_field_offset(entity, 'ctx');
1037
+ const contentPtr = ctxPtr +
1038
+ libredwg.dwg_dynapi_subclass_field_offset('MLEADER_AnnotContext', 'content');
1039
+ const contentScaleFactor = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'scale_factor');
1040
+ const contentBasePosition = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'content_base');
1041
+ const landingGap = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'landing_gap');
1042
+ const textAttachment = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'attach_dir');
1043
+ const contextTextHeight = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'text_height');
1044
+ const contextArrowSize = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'arrow_size');
1045
+ const contextTextLeft = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'text_left');
1046
+ const contextTextRight = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'text_right');
1047
+ const contextTextAngleType = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'text_angletype');
1048
+ const contextTextAlignment = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'text_alignment');
1049
+ const hasMText = asBool(subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'has_content_txt'));
1050
+ const hasBlock = asBool(subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'has_content_blk'));
1051
+ const planeOrigin = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'base');
1052
+ const planeXAxisDirection = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'base_dir');
1053
+ const planeYAxisDirection = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'base_vert');
1054
+ const planeNormalReversed = asBool(subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'is_normal_reversed'));
1055
+ let textFlowDirection;
1056
+ let normal;
1057
+ let textRotation;
1058
+ let textWidth;
1059
+ let textLineSpacingFactor;
1060
+ let textLineSpacingStyle;
1061
+ let textAnchor;
1062
+ let textDirection;
1063
+ let textBackgroundColor;
1064
+ let textBackgroundScaleFactor;
1065
+ let textBackgroundTransparency;
1066
+ let textBackgroundColorOn;
1067
+ let textFillOn;
1068
+ let textColumnType;
1069
+ let textUseAutoHeight;
1070
+ let textColumnWidth;
1071
+ let textColumnGutterWidth;
1072
+ let textColumnFlowReversed;
1073
+ let textColumnHeight;
1074
+ let textUseWordBreak;
1075
+ let textContent;
1076
+ if (hasMText) {
1077
+ const textAlignment = subclassVal(contentPtr, 'MLEADER_Content_MText', 'alignment');
1078
+ if (textAlignment != null && textAlignment !== 0) {
1079
+ textAttachmentPoint = textAlignment;
1080
+ }
1081
+ normal = subclassVal(contentPtr, 'MLEADER_Content_MText', 'normal');
1082
+ textAnchor = subclassVal(contentPtr, 'MLEADER_Content_MText', 'location');
1083
+ textRotation = subclassVal(contentPtr, 'MLEADER_Content_MText', 'rotation');
1084
+ textDirection = subclassVal(contentPtr, 'MLEADER_Content_MText', 'direction');
1085
+ textWidth = subclassVal(contentPtr, 'MLEADER_Content_MText', 'width');
1086
+ textLineSpacingFactor = subclassVal(contentPtr, 'MLEADER_Content_MText', 'line_spacing_factor');
1087
+ textLineSpacingStyle = subclassVal(contentPtr, 'MLEADER_Content_MText', 'line_spacing_style');
1088
+ textFlowDirection = subclassVal(contentPtr, 'MLEADER_Content_MText', 'flow');
1089
+ textBackgroundColor = mleaderColor(subclassVal(contentPtr, 'MLEADER_Content_MText', 'bg_color'));
1090
+ textBackgroundScaleFactor = subclassVal(contentPtr, 'MLEADER_Content_MText', 'bg_scale');
1091
+ textBackgroundTransparency = subclassVal(contentPtr, 'MLEADER_Content_MText', 'bg_transparency');
1092
+ textFillOn = asBool(subclassVal(contentPtr, 'MLEADER_Content_MText', 'is_bg_fill'));
1093
+ textBackgroundColorOn = asBool(subclassVal(contentPtr, 'MLEADER_Content_MText', 'is_bg_mask_fill'));
1094
+ textColumnType = subclassVal(contentPtr, 'MLEADER_Content_MText', 'col_type');
1095
+ textUseAutoHeight = asBool(subclassVal(contentPtr, 'MLEADER_Content_MText', 'is_height_auto'));
1096
+ textColumnWidth = subclassVal(contentPtr, 'MLEADER_Content_MText', 'col_width');
1097
+ textColumnGutterWidth = subclassVal(contentPtr, 'MLEADER_Content_MText', 'col_gutter');
1098
+ textColumnFlowReversed = asBool(subclassVal(contentPtr, 'MLEADER_Content_MText', 'is_col_flow_reversed'));
1099
+ const numColSizes = subclassVal(contentPtr, 'MLEADER_Content_MText', 'num_col_sizes');
1100
+ const colSizesPtr = subclassVal(contentPtr, 'MLEADER_Content_MText', 'col_sizes');
1101
+ if (numColSizes > 0) {
1102
+ textColumnHeight = libredwg.dwg_ptr_to_double_array(colSizesPtr, numColSizes)[0];
1103
+ }
1104
+ textUseWordBreak = asBool(subclassVal(contentPtr, 'MLEADER_Content_MText', 'word_break'));
1105
+ textContent = subclassVal(contentPtr, 'MLEADER_Content_MText', 'default_text');
1106
+ }
1107
+ let blockContent;
1108
+ if (hasBlock) {
1109
+ const transformPtr = subclassVal(contentPtr, 'MLEADER_Content_Block', 'transform');
1110
+ blockContent = {
1111
+ blockContentId: refToId(subclassVal(contentPtr, 'MLEADER_Content_Block', 'block_table')),
1112
+ normal: subclassVal(contentPtr, 'MLEADER_Content_Block', 'normal'),
1113
+ position: subclassVal(contentPtr, 'MLEADER_Content_Block', 'location'),
1114
+ scale: subclassVal(contentPtr, 'MLEADER_Content_Block', 'scale'),
1115
+ rotation: subclassVal(contentPtr, 'MLEADER_Content_Block', 'rotation'),
1116
+ color: mleaderColor(subclassVal(contentPtr, 'MLEADER_Content_Block', 'color')),
1117
+ transformationMatrix: transformPtr
1118
+ ? libredwg.dwg_ptr_to_double_array(transformPtr, 16)
1119
+ : undefined
1120
+ };
1121
+ }
1122
+ const numLeaders = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'num_leaders');
1123
+ const leadersPtr = subclassVal(ctxPtr, 'MLEADER_AnnotContext', 'leaders');
1124
+ const leaderNodeSize = libredwg.dwg_dynapi_subclass_size('LEADER_Node');
1125
+ const leaderLineSize = libredwg.dwg_dynapi_subclass_size('LEADER_Line');
1126
+ const leaderBreakSize = libredwg.dwg_dynapi_subclass_size('LEADER_Break');
1127
+ const leaderSections = [];
1128
+ for (let i = 0; i < numLeaders; i++) {
1129
+ const nodePtr = leadersPtr + i * leaderNodeSize;
1130
+ const lastLeaderLinePointSet = asBool(subclassVal(nodePtr, 'LEADER_Node', 'has_lastleaderlinepoint'));
1131
+ const doglegVectorSet = asBool(subclassVal(nodePtr, 'LEADER_Node', 'has_dogleg'));
1132
+ const numBreaks = subclassVal(nodePtr, 'LEADER_Node', 'num_breaks');
1133
+ const breaksPtr = subclassVal(nodePtr, 'LEADER_Node', 'breaks');
1134
+ const nodeBreaks = [];
1135
+ for (let j = 0; j < numBreaks; j++) {
1136
+ const breakPtr = breaksPtr + j * leaderBreakSize;
1137
+ nodeBreaks.push({
1138
+ start: subclassVal(breakPtr, 'LEADER_Break', 'start'),
1139
+ end: subclassVal(breakPtr, 'LEADER_Break', 'end')
1140
+ });
1141
+ }
1142
+ const numLines = subclassVal(nodePtr, 'LEADER_Node', 'num_lines');
1143
+ const linesPtr = subclassVal(nodePtr, 'LEADER_Node', 'lines');
1144
+ const leaderLines = [];
1145
+ for (let j = 0; j < numLines; j++) {
1146
+ const linePtr = linesPtr + j * leaderLineSize;
1147
+ const numPoints = subclassVal(linePtr, 'LEADER_Line', 'num_points');
1148
+ const pointsPtr = subclassVal(linePtr, 'LEADER_Line', 'points');
1149
+ const vertices = numPoints > 0
1150
+ ? libredwg.dwg_ptr_to_point3d_array(pointsPtr, numPoints)
1151
+ : [];
1152
+ const lineNumBreaks = subclassVal(linePtr, 'LEADER_Line', 'num_breaks');
1153
+ const lineBreaksPtr = subclassVal(linePtr, 'LEADER_Line', 'breaks');
1154
+ const lineBreaks = [];
1155
+ for (let k = 0; k < lineNumBreaks; k++) {
1156
+ const breakPtr = lineBreaksPtr + k * leaderBreakSize;
1157
+ lineBreaks.push({
1158
+ start: subclassVal(breakPtr, 'LEADER_Break', 'start'),
1159
+ end: subclassVal(breakPtr, 'LEADER_Break', 'end')
1160
+ });
1161
+ }
1162
+ leaderLines.push({
1163
+ vertices,
1164
+ leaderLineIndex: subclassVal(linePtr, 'LEADER_Line', 'line_index'),
1165
+ breaks: lineBreaks.length > 0 ? lineBreaks : undefined
1166
+ });
1167
+ }
1168
+ leaderSections.push({
1169
+ lastLeaderLinePoint: lastLeaderLinePointSet
1170
+ ? subclassVal(nodePtr, 'LEADER_Node', 'lastleaderlinepoint')
1171
+ : undefined,
1172
+ lastLeaderLinePointSet,
1173
+ doglegVector: doglegVectorSet
1174
+ ? subclassVal(nodePtr, 'LEADER_Node', 'dogleg_vector')
1175
+ : undefined,
1176
+ doglegVectorSet,
1177
+ doglegLength: subclassVal(nodePtr, 'LEADER_Node', 'dogleg_length'),
1178
+ breaks: nodeBreaks.length > 0 ? nodeBreaks : undefined,
1179
+ leaderBranchIndex: subclassVal(nodePtr, 'LEADER_Node', 'branch_index'),
1180
+ leaderLines
1181
+ });
1182
+ }
1183
+ return {
1184
+ type: 'MULTILEADER',
1185
+ ...commonAttrs,
1186
+ subclassMarker: 'AcDbMLeader',
1187
+ version,
1188
+ leaderStyleId,
1189
+ propertyOverrideFlag,
1190
+ leaderLineType,
1191
+ leaderLineColor,
1192
+ leaderLineTypeId,
1193
+ leaderLineWeight,
1194
+ landingEnabled,
1195
+ doglegEnabled,
1196
+ doglegLength,
1197
+ arrowheadId,
1198
+ arrowheadSize: arrowheadSize || contextArrowSize,
1199
+ contentType,
1200
+ textStyleId,
1201
+ textLeftAttachmentType: textLeftAttachmentType || contextTextLeft,
1202
+ textRightAttachmentType: textRightAttachmentType || contextTextRight,
1203
+ textAngleType: textAngleType || contextTextAngleType,
1204
+ textAlignmentType: textAlignmentType || contextTextAlignment,
1205
+ textColor,
1206
+ textFrameEnabled,
1207
+ landingGap,
1208
+ textAttachment,
1209
+ textFlowDirection,
1210
+ blockContentId,
1211
+ blockContentColor,
1212
+ blockContentScale,
1213
+ blockContentRotation,
1214
+ blockContentConnectionType,
1215
+ annotativeScaleEnabled,
1216
+ arrowheadOverrides: arrowheadOverrides.length > 0 ? arrowheadOverrides : undefined,
1217
+ blockAttributes: blockAttributes.length > 0 ? blockAttributes : undefined,
1218
+ textDirectionNegative,
1219
+ textAlignInIPE,
1220
+ textAttachmentPoint,
1221
+ textAttachmentDirection,
1222
+ bottomTextAttachmentDirection,
1223
+ topTextAttachmentDirection,
1224
+ contentScale: contentScale || contentScaleFactor,
1225
+ contentBasePosition,
1226
+ normal,
1227
+ textHeight: contextTextHeight,
1228
+ textRotation,
1229
+ textWidth,
1230
+ textLineSpacingFactor,
1231
+ textLineSpacingStyle,
1232
+ textAnchor,
1233
+ textDirection,
1234
+ textBackgroundColor,
1235
+ textBackgroundScaleFactor,
1236
+ textBackgroundTransparency,
1237
+ textBackgroundColorOn,
1238
+ textFillOn,
1239
+ textColumnType,
1240
+ textUseAutoHeight,
1241
+ textColumnWidth,
1242
+ textColumnGutterWidth,
1243
+ textColumnFlowReversed,
1244
+ textColumnHeight,
1245
+ textUseWordBreak,
1246
+ textContent,
1247
+ hasMText,
1248
+ hasBlock,
1249
+ blockContent,
1250
+ planeOrigin,
1251
+ planeXAxisDirection,
1252
+ planeYAxisDirection,
1253
+ planeNormalReversed,
1254
+ leaderSections: leaderSections.length > 0 ? leaderSections : undefined
1255
+ };
1256
+ }
1257
+ convertOle2Frame(entity, commonAttrs) {
1258
+ const libredwg = this.libredwg;
1259
+ const oleVersion = libredwg.dwg_dynapi_entity_data(entity, 'oleversion');
1260
+ const oleClient = libredwg.dwg_dynapi_entity_data(entity, 'oleclient');
1261
+ const dataSize = libredwg.dwg_dynapi_entity_data(entity, 'data_size');
1262
+ let leftUpPoint = libredwg.dwg_dynapi_entity_data(entity, 'pt1');
1263
+ let rightDownPoint = libredwg.dwg_dynapi_entity_data(entity, 'pt2');
1264
+ const lockAspect = libredwg.dwg_dynapi_entity_data(entity, 'lock_aspect');
1265
+ const oleObjectType = libredwg.dwg_dynapi_entity_data(entity, 'type');
1266
+ const tileModeDescriptor = libredwg.dwg_dynapi_entity_data(entity, 'mode');
1267
+ // Prefer sized TF copy: dynapi TF truncates at the first embedded NUL.
1268
+ const dataBytes = libredwg.dwg_entity_ole2frame_get_data(entity);
1269
+ const binaryData = dataBytes ? uint8ArrayToHexString(dataBytes) : '';
1270
+ // Prefer corners decoded from the OLE header (also fixed in dwg_decode_ole2).
1271
+ if (dataBytes) {
1272
+ const corners = decodeOle2FrameCornersFromData(dataBytes);
1273
+ if (corners) {
1274
+ leftUpPoint = corners.upperLeft;
1275
+ rightDownPoint = corners.lowerRight;
1276
+ }
1277
+ }
1278
+ return {
1279
+ type: 'OLE2FRAME',
1280
+ ...commonAttrs,
1281
+ oleVersion: oleVersion,
1282
+ oleClient: oleClient,
1283
+ dataSize: dataSize,
1284
+ leftUpPoint: leftUpPoint,
1285
+ rightDownPoint: rightDownPoint,
1286
+ lockAspect: lockAspect,
1287
+ oleObjectType: oleObjectType,
1288
+ tileModeDescriptor: tileModeDescriptor,
1289
+ binaryData: binaryData
1290
+ };
1291
+ }
1292
+ convertOleFrame(entity, commonAttrs) {
1293
+ const libredwg = this.libredwg;
1294
+ const flag = libredwg.dwg_dynapi_entity_data(entity, 'flag');
1295
+ const mode = libredwg.dwg_dynapi_entity_data(entity, 'mode');
1296
+ const dataSize = libredwg.dwg_dynapi_entity_data(entity, 'data_size');
1297
+ const dataBytes = libredwg.dwg_entity_oleframe_get_data(entity);
1298
+ const binaryData = dataBytes ? uint8ArrayToHexString(dataBytes) : '';
1299
+ return {
1300
+ type: 'OLEFRAME',
1301
+ ...commonAttrs,
1302
+ flag: flag,
1303
+ mode: mode,
1304
+ dataSize: dataSize,
1305
+ binaryData: binaryData
1306
+ };
1307
+ }
1308
+ convertMText(entity, commonAttrs) {
1309
+ const libredwg = this.libredwg;
1310
+ const insertionPoint = libredwg.dwg_dynapi_entity_data(entity, 'ins_pt');
1311
+ const textHeight = libredwg.dwg_dynapi_entity_data(entity, 'text_height');
1312
+ const rectHeight = libredwg.dwg_dynapi_entity_data(entity, 'rect_height');
1313
+ const rectWidth = libredwg.dwg_dynapi_entity_data(entity, 'rect_width');
1314
+ const extentsWidth = libredwg.dwg_dynapi_entity_data(entity, 'extents_width');
1315
+ const extentsHeight = libredwg.dwg_dynapi_entity_data(entity, 'extents_height');
1316
+ const attachmentPoint = libredwg.dwg_dynapi_entity_data(entity, 'attachment');
1317
+ const drawingDirection = libredwg.dwg_dynapi_entity_data(entity, 'flow_dir');
1318
+ const text = libredwg.dwg_dynapi_entity_data(entity, 'text');
1319
+ const styleName = libredwg.dwg_entity_mtext_get_style_name(entity);
1320
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1321
+ const direction = libredwg.dwg_dynapi_entity_data(entity, 'x_axis_dir');
1322
+ const lineSpacingStyle = libredwg.dwg_dynapi_entity_data(entity, 'linespace_style');
1323
+ const lineSpacing = libredwg.dwg_dynapi_entity_data(entity, 'linespace_factor');
1324
+ const backgroundFill = libredwg.dwg_dynapi_entity_data(entity, 'bg_fill_flag');
1325
+ const fillBoxScale = libredwg.dwg_dynapi_entity_data(entity, 'bg_fill_scale');
1326
+ const backgroundFillColor = libredwg.dwg_dynapi_entity_data(entity, 'bg_fill_color');
1327
+ const backgroundFillTransparency = libredwg.dwg_dynapi_entity_data(entity, 'bg_fill_trans');
1328
+ const columnType = libredwg.dwg_dynapi_entity_data(entity, 'column_type');
1329
+ const columnFlowReversed = libredwg.dwg_dynapi_entity_data(entity, 'flow_reversed');
1330
+ const columnAutoHeight = libredwg.dwg_dynapi_entity_data(entity, 'auto_height');
1331
+ const columnWidth = libredwg.dwg_dynapi_entity_data(entity, 'column_width');
1332
+ const columnGutter = libredwg.dwg_dynapi_entity_data(entity, 'gutter');
1333
+ const columnHeightCount = libredwg.dwg_dynapi_entity_data(entity, 'num_column_heights');
1334
+ const columnHeights_ptr = libredwg.dwg_dynapi_entity_data(entity, 'column_heights');
1335
+ const columnHeights = libredwg.dwg_ptr_to_double_array(columnHeights_ptr, columnHeightCount);
1336
+ return {
1337
+ type: 'MTEXT',
1338
+ ...commonAttrs,
1339
+ insertionPoint: insertionPoint,
1340
+ textHeight: textHeight,
1341
+ rectHeight: rectHeight,
1342
+ rectWidth: rectWidth,
1343
+ extentsHeight: extentsHeight,
1344
+ extentsWidth: extentsWidth,
1345
+ attachmentPoint: attachmentPoint,
1346
+ drawingDirection: drawingDirection,
1347
+ text: text,
1348
+ styleName: styleName,
1349
+ extrusionDirection: extrusionDirection,
1350
+ direction: direction,
1351
+ rotation: 0, // TODO: Didn't find the corresponding field in libredwg
1352
+ lineSpacingStyle: lineSpacingStyle,
1353
+ lineSpacing: lineSpacing,
1354
+ backgroundFill: backgroundFill,
1355
+ // backgroundColor: backgroundColor.rgb, // TODO: Double check whether it should be color index
1356
+ fillBoxScale: fillBoxScale,
1357
+ backgroundFillColor: backgroundFillColor.rgb, // TODO: Double check whether it should be color index
1358
+ backgroundFillTransparency: backgroundFillTransparency,
1359
+ columnType: columnType,
1360
+ // columnCount: columnCount,
1361
+ columnFlowReversed: columnFlowReversed,
1362
+ columnAutoHeight: columnAutoHeight,
1363
+ columnWidth: columnWidth,
1364
+ columnGutter: columnGutter,
1365
+ columnHeightCount: columnHeightCount,
1366
+ columnHeights: columnHeights
1367
+ };
1368
+ }
1369
+ convertPoint(entity, commonAttrs) {
1370
+ const libredwg = this.libredwg;
1371
+ const x = libredwg.dwg_dynapi_entity_data(entity, 'x');
1372
+ const y = libredwg.dwg_dynapi_entity_data(entity, 'y');
1373
+ const z = libredwg.dwg_dynapi_entity_data(entity, 'z');
1374
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
1375
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1376
+ const angle = libredwg.dwg_dynapi_entity_data(entity, 'x_ang');
1377
+ return {
1378
+ type: 'POINT',
1379
+ ...commonAttrs,
1380
+ position: { x, y, z },
1381
+ thickness: thickness,
1382
+ extrusionDirection: extrusionDirection,
1383
+ angle: angle
1384
+ };
1385
+ }
1386
+ convertPolyline2d(entity, commonAttrs, object) {
1387
+ const libredwg = this.libredwg;
1388
+ const flag = libredwg.dwg_dynapi_entity_data(entity, 'flag');
1389
+ const smoothType = libredwg.dwg_dynapi_entity_data(entity, 'curve_type');
1390
+ const startWidth = libredwg.dwg_dynapi_entity_data(entity, 'start_width');
1391
+ const endWidth = libredwg.dwg_dynapi_entity_data(entity, 'end_width');
1392
+ const elevation = libredwg.dwg_dynapi_entity_data(entity, 'elevation');
1393
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
1394
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1395
+ const vertices = libredwg.dwg_entity_polyline_2d_get_vertices(object) ?? [];
1396
+ return {
1397
+ type: 'POLYLINE2D',
1398
+ ...commonAttrs,
1399
+ flag: flag,
1400
+ smoothType: smoothType,
1401
+ startWidth: startWidth,
1402
+ endWidth: endWidth,
1403
+ elevation: elevation,
1404
+ thickness: thickness,
1405
+ extrusionDirection: extrusionDirection,
1406
+ vertices: vertices.map(vertex => {
1407
+ return {
1408
+ x: vertex.point.x,
1409
+ y: vertex.point.y,
1410
+ z: vertex.point.z,
1411
+ startWidth: vertex.start_width,
1412
+ endWidth: vertex.end_width,
1413
+ bulge: vertex.bulge,
1414
+ flag: vertex.flag,
1415
+ tangentDirection: vertex.tangent_dir
1416
+ };
1417
+ }),
1418
+ meshMVertexCount: 0,
1419
+ meshNVertexCount: 0,
1420
+ surfaceMDensity: 0,
1421
+ surfaceNDensity: 0
1422
+ };
1423
+ }
1424
+ convertPolyline3d(entity, commonAttrs, object) {
1425
+ const libredwg = this.libredwg;
1426
+ const flag = libredwg.dwg_dynapi_entity_data(entity, 'flag');
1427
+ const smoothType = libredwg.dwg_dynapi_entity_data(entity, 'curve_type');
1428
+ const startWidth = libredwg.dwg_dynapi_entity_data(entity, 'start_width');
1429
+ const endWidth = libredwg.dwg_dynapi_entity_data(entity, 'end_width');
1430
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1431
+ const vertices = libredwg.dwg_entity_polyline_3d_get_vertices(object) ?? [];
1432
+ return {
1433
+ type: 'POLYLINE3D',
1434
+ ...commonAttrs,
1435
+ flag: flag,
1436
+ smoothType: smoothType,
1437
+ startWidth: startWidth,
1438
+ endWidth: endWidth,
1439
+ extrusionDirection: extrusionDirection,
1440
+ vertices: vertices.map(vertex => {
1441
+ return {
1442
+ x: vertex.point.x,
1443
+ y: vertex.point.y,
1444
+ z: vertex.point.z,
1445
+ flag: vertex.flag
1446
+ };
1447
+ })
1448
+ };
1449
+ }
1450
+ convertProxyEntity(entity, commonAttrs, objectPtr) {
1451
+ const libredwg = this.libredwg;
1452
+ const proxyEntityClassId = libredwg.dwg_dynapi_entity_data(entity, 'proxy_id');
1453
+ const applicationEntityClassId = libredwg.dwg_dynapi_entity_data(entity, 'class_id');
1454
+ const entityDataSize = libredwg.dwg_dynapi_entity_data(entity, 'data_numbits');
1455
+ const objectDrawingFormat = libredwg.dwg_dynapi_entity_data(entity, 'version');
1456
+ const fromDxf = libredwg.dwg_dynapi_entity_data(entity, 'from_dxf');
1457
+ const numObjIds = libredwg.dwg_dynapi_entity_data(entity, 'num_objids');
1458
+ const graphicsBytes = libredwg.dwg_entity_get_preview(objectPtr);
1459
+ const graphicsDataSize = graphicsBytes?.length ?? 0;
1460
+ const entityBytes = libredwg.dwg_entity_proxy_entity_get_entity_data(entity);
1461
+ const graphicsData = graphicsBytes
1462
+ ? uint8ArrayToHexString(graphicsBytes)
1463
+ : undefined;
1464
+ const entityData = entityBytes
1465
+ ? uint8ArrayToHexString(entityBytes)
1466
+ : undefined;
1467
+ let linkedObjectIds;
1468
+ if (numObjIds > 0) {
1469
+ const objidsPtr = libredwg.dwg_dynapi_entity_data(entity, 'objids');
1470
+ if (objidsPtr) {
1471
+ const objids = libredwg.dwg_ptr_to_object_ref_array(objidsPtr, numObjIds);
1472
+ linkedObjectIds = objids.map(ref => idToString(ref.absolute_ref));
1473
+ }
1474
+ }
1475
+ const originalDxfName = this.getOriginalDxfName(applicationEntityClassId);
1476
+ const result = {
1477
+ type: 'ACAD_PROXY_ENTITY',
1478
+ subclassMarker: 'AcDbProxyEntity',
1479
+ ...commonAttrs,
1480
+ proxyEntityClassId: proxyEntityClassId || 498,
1481
+ applicationEntityClassId
1482
+ };
1483
+ if (originalDxfName) {
1484
+ result.originalDxfName = originalDxfName;
1485
+ }
1486
+ if (graphicsDataSize > 0) {
1487
+ result.graphicsDataSize = graphicsDataSize;
1488
+ }
1489
+ if (graphicsData) {
1490
+ result.graphicsData = graphicsData;
1491
+ }
1492
+ if (entityDataSize > 0) {
1493
+ result.entityDataSize = entityDataSize;
1494
+ }
1495
+ if (entityData) {
1496
+ result.entityData = entityData;
1497
+ }
1498
+ if (linkedObjectIds && linkedObjectIds.length > 0) {
1499
+ result.linkedObjectIds = linkedObjectIds;
1500
+ }
1501
+ if (objectDrawingFormat) {
1502
+ result.objectDrawingFormat = objectDrawingFormat;
1503
+ }
1504
+ if (fromDxf === 0 || fromDxf === 1) {
1505
+ result.originalDataFormat =
1506
+ fromDxf;
1507
+ }
1508
+ return result;
1509
+ }
1510
+ getOriginalDxfName(classId) {
1511
+ if (this.classes.length === 0 || classId < 0) {
1512
+ return undefined;
1513
+ }
1514
+ const index = classId >= 500 ? classId - 500 : classId;
1515
+ if (index >= 0 && index < this.classes.length) {
1516
+ return this.classes[index].dxfName;
1517
+ }
1518
+ return undefined;
1519
+ }
1520
+ convertRay(entity, commonAttrs) {
1521
+ const libredwg = this.libredwg;
1522
+ const firstPoint = libredwg.dwg_dynapi_entity_data(entity, 'point');
1523
+ const unitDirection = libredwg.dwg_dynapi_entity_data(entity, 'vector');
1524
+ return {
1525
+ type: 'RAY',
1526
+ ...commonAttrs,
1527
+ firstPoint: firstPoint,
1528
+ unitDirection: unitDirection
1529
+ };
1530
+ }
1531
+ convertSection(entity, commonAttrs) {
1532
+ const libredwg = this.libredwg;
1533
+ const state = libredwg.dwg_dynapi_entity_data(entity, 'state');
1534
+ const flags = libredwg.dwg_dynapi_entity_data(entity, 'flag');
1535
+ const name = libredwg.dwg_dynapi_entity_data(entity, 'name');
1536
+ const verticalDirection = libredwg.dwg_dynapi_entity_data(entity, 'vert_dir');
1537
+ const topHeight = libredwg.dwg_dynapi_entity_data(entity, 'top_height');
1538
+ const bottomHeight = libredwg.dwg_dynapi_entity_data(entity, 'bottom_height');
1539
+ const indicatorTransparency = libredwg.dwg_dynapi_entity_data(entity, 'indicator_alpha');
1540
+ const indicatorColor = libredwg.dwg_dynapi_entity_data(entity, 'indicator_color');
1541
+ const numberOfVertices = libredwg.dwg_dynapi_entity_data(entity, 'num_verts');
1542
+ const vertices_ptr = libredwg.dwg_dynapi_entity_data(entity, 'verts');
1543
+ const vertices = numberOfVertices > 0
1544
+ ? libredwg.dwg_ptr_to_point3d_array(vertices_ptr, numberOfVertices)
1545
+ : [];
1546
+ const numberOfBackLineVertices = libredwg.dwg_dynapi_entity_data(entity, 'num_blverts');
1547
+ const backLineVertices_ptr = libredwg.dwg_dynapi_entity_data(entity, 'blverts');
1548
+ const backLineVertices = numberOfBackLineVertices > 0
1549
+ ? libredwg.dwg_ptr_to_point3d_array(backLineVertices_ptr, numberOfBackLineVertices)
1550
+ : [];
1551
+ const geometrySettingHandle = libredwg.dwg_dynapi_entity_data(entity, 'geometrySettingHardId');
1552
+ const geometrySettingHardId = libredwg.dwg_ref_get_handle_absolute_ref(geometrySettingHandle) ?? 0n;
1553
+ return {
1554
+ type: 'SECTION',
1555
+ ...commonAttrs,
1556
+ state: state,
1557
+ flags: flags,
1558
+ name: name,
1559
+ verticalDirection: verticalDirection,
1560
+ topHeight: topHeight,
1561
+ bottomHeight: bottomHeight,
1562
+ indicatorTransparency: indicatorTransparency,
1563
+ indicatorColor: indicatorColor.rgb,
1564
+ numberOfVertices: numberOfVertices,
1565
+ vertices: vertices,
1566
+ numberOfBackLineVertices: numberOfBackLineVertices,
1567
+ backLineVertices: backLineVertices,
1568
+ geometrySettingHardId: geometrySettingHardId
1569
+ };
1570
+ }
1571
+ convertShape(entity, commonAttrs) {
1572
+ const libredwg = this.libredwg;
1573
+ const insertionPoint = libredwg.dwg_dynapi_entity_data(entity, 'ins_pt');
1574
+ const size = libredwg.dwg_dynapi_entity_data(entity, 'scale');
1575
+ const rotation = libredwg.dwg_dynapi_entity_data(entity, 'rotation');
1576
+ const xScale = libredwg.dwg_dynapi_entity_data(entity, 'width_factor');
1577
+ const obliqueAngle = libredwg.dwg_dynapi_entity_data(entity, 'oblique_angle');
1578
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
1579
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1580
+ const shapeNumber = libredwg.dwg_dynapi_entity_data(entity, 'style_id');
1581
+ const styleName = libredwg.dwg_entity_text_get_style_name(entity);
1582
+ return {
1583
+ type: 'SHAPE',
1584
+ subclassMarker: 'AcDbShape',
1585
+ ...commonAttrs,
1586
+ thickness: thickness,
1587
+ insertionPoint: insertionPoint,
1588
+ size: size,
1589
+ shapeNumber: shapeNumber,
1590
+ styleName: styleName,
1591
+ rotation: rotation,
1592
+ xScale: xScale,
1593
+ obliqueAngle: obliqueAngle,
1594
+ extrusionDirection: extrusionDirection
1595
+ };
1596
+ }
1597
+ convertSolid(entity, commonAttrs) {
1598
+ const libredwg = this.libredwg;
1599
+ const corner1 = libredwg.dwg_dynapi_entity_data(entity, 'corner1');
1600
+ const corner2 = libredwg.dwg_dynapi_entity_data(entity, 'corner2');
1601
+ const corner3 = libredwg.dwg_dynapi_entity_data(entity, 'corner3');
1602
+ const corner4 = libredwg.dwg_dynapi_entity_data(entity, 'corner4');
1603
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
1604
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1605
+ return {
1606
+ type: 'SOLID',
1607
+ ...commonAttrs,
1608
+ corner1: corner1,
1609
+ corner2: corner2,
1610
+ corner3: corner3,
1611
+ corner4: corner4,
1612
+ thickness: thickness,
1613
+ extrusionDirection: extrusionDirection
1614
+ };
1615
+ }
1616
+ convertTrace(entity, commonAttrs) {
1617
+ const solid = this.convertSolid(entity, commonAttrs);
1618
+ return {
1619
+ ...solid,
1620
+ type: 'TRACE'
1621
+ };
1622
+ }
1623
+ convertSpline(entity, commonAttrs) {
1624
+ const libredwg = this.libredwg;
1625
+ const flag = libredwg.dwg_dynapi_entity_data(entity, 'splineflags');
1626
+ const degree = libredwg.dwg_dynapi_entity_data(entity, 'degree');
1627
+ // Convert knots
1628
+ const knotTolerance = libredwg.dwg_dynapi_entity_data(entity, 'knot_tol');
1629
+ const numberOfKnots = libredwg.dwg_dynapi_entity_data(entity, 'num_knots');
1630
+ const knots_ptr = libredwg.dwg_dynapi_entity_data(entity, 'knots');
1631
+ const knots = libredwg.dwg_ptr_to_double_array(knots_ptr, numberOfKnots);
1632
+ // Convert fit points
1633
+ const fitTolerance = libredwg.dwg_dynapi_entity_data(entity, 'fit_tol');
1634
+ const numberOfFitPoints = libredwg.dwg_dynapi_entity_data(entity, 'num_fit_pts');
1635
+ const fit_pts_ptr = libredwg.dwg_dynapi_entity_data(entity, 'fit_pts');
1636
+ const fitPoints = libredwg.dwg_ptr_to_point3d_array(fit_pts_ptr, numberOfFitPoints);
1637
+ // Convert control points
1638
+ const weighted = libredwg.dwg_dynapi_entity_data(entity, 'weighted');
1639
+ const controlTolerance = libredwg.dwg_dynapi_entity_data(entity, 'ctrl_tol');
1640
+ const numberOfControlPoints = libredwg.dwg_dynapi_entity_data(entity, 'num_ctrl_pts');
1641
+ const ctrl_pts_ptr = libredwg.dwg_dynapi_entity_data(entity, 'ctrl_pts');
1642
+ const controlPoints = libredwg.dwg_ptr_to_point4d_array(ctrl_pts_ptr, numberOfControlPoints);
1643
+ const startTangent = libredwg.dwg_dynapi_entity_data(entity, 'beg_tan_vec');
1644
+ const endTangent = libredwg.dwg_dynapi_entity_data(entity, 'end_tan_vec');
1645
+ return {
1646
+ type: 'SPLINE',
1647
+ ...commonAttrs,
1648
+ // normal?: DwgPoint3D
1649
+ flag: flag,
1650
+ degree: degree,
1651
+ numberOfKnots: numberOfKnots,
1652
+ numberOfControlPoints: numberOfControlPoints,
1653
+ numberOfFitPoints: numberOfFitPoints,
1654
+ knotTolerance: knotTolerance,
1655
+ controlTolerance: controlTolerance,
1656
+ fitTolerance: fitTolerance,
1657
+ startTangent: startTangent,
1658
+ endTangent: endTangent,
1659
+ knots: knots,
1660
+ weights: weighted ? controlPoints.map(value => value.w) : undefined,
1661
+ controlPoints: controlPoints.map(value => {
1662
+ return {
1663
+ x: value.x,
1664
+ y: value.y,
1665
+ z: value.z
1666
+ };
1667
+ }),
1668
+ fitPoints: fitPoints
1669
+ };
1670
+ }
1671
+ convertTable(entity, commonAttrs) {
1672
+ const libredwg = this.libredwg;
1673
+ const name = libredwg.dwg_dynapi_subclass_data(entity, 'ldata', 'name');
1674
+ const startPoint = libredwg.dwg_dynapi_entity_data(entity, 'ins_pt');
1675
+ const directionVector = libredwg.dwg_dynapi_entity_data(entity, 'horiz_direction');
1676
+ const tableValue = libredwg.dwg_dynapi_entity_data(entity, 'flag_for_table_value');
1677
+ const rowCount = libredwg.dwg_dynapi_entity_data(entity, 'num_rows');
1678
+ const columnCount = libredwg.dwg_dynapi_entity_data(entity, 'num_cols');
1679
+ const row_heights_ptr = libredwg.dwg_dynapi_entity_data(entity, 'row_heights');
1680
+ const rowHeightArr = libredwg.dwg_ptr_to_double_array(row_heights_ptr, rowCount);
1681
+ const col_widths_ptr = libredwg.dwg_dynapi_entity_data(entity, 'col_widths');
1682
+ const columnWidthArr = libredwg.dwg_ptr_to_double_array(col_widths_ptr, columnCount);
1683
+ const table_style_ref = libredwg.dwg_dynapi_entity_data(entity, 'tablestyle');
1684
+ const tableStyleId = libredwg.dwg_ref_get_id(table_style_ref) ?? '';
1685
+ const block_header_ref = libredwg.dwg_dynapi_entity_data(entity, 'block_header');
1686
+ const blockRecordHandle = libredwg.dwg_ref_get_id(block_header_ref) ?? '';
1687
+ const overrideFlag = libredwg.dwg_dynapi_entity_data(entity, 'table_flag_override');
1688
+ const borderColorOverrideFlag = libredwg.dwg_dynapi_entity_data(entity, 'border_color_overrides_flag');
1689
+ const borderLineWeightOverrideFlag = libredwg.dwg_dynapi_entity_data(entity, 'border_lineweight_overrides_flag');
1690
+ const borderVisibilityOverrideFlag = libredwg.dwg_dynapi_entity_data(entity, 'border_visibility_overrides_flag');
1691
+ const num_cells = libredwg.dwg_dynapi_entity_data(entity, 'num_cells');
1692
+ const cells_ptr = libredwg.dwg_dynapi_entity_data(entity, 'cells');
1693
+ const cells = libredwg.dwg_ptr_to_table_cell_array(cells_ptr, num_cells);
1694
+ return {
1695
+ type: 'ACAD_TABLE',
1696
+ ...commonAttrs,
1697
+ name: name,
1698
+ startPoint: startPoint,
1699
+ directionVector: directionVector,
1700
+ // attachmentPoint: DwgAttachmentPoint
1701
+ tableValue: tableValue,
1702
+ rowCount: rowCount,
1703
+ columnCount: columnCount,
1704
+ overrideFlag: overrideFlag,
1705
+ borderColorOverrideFlag: borderColorOverrideFlag,
1706
+ borderLineWeightOverrideFlag: borderLineWeightOverrideFlag,
1707
+ borderVisibilityOverrideFlag: borderVisibilityOverrideFlag,
1708
+ rowHeightArr: rowHeightArr,
1709
+ columnWidthArr: columnWidthArr,
1710
+ tableStyleId: tableStyleId,
1711
+ blockRecordHandle: blockRecordHandle,
1712
+ cells: this.convertTableCells(cells),
1713
+ bmpPreview: ''
1714
+ };
1715
+ }
1716
+ convertTableCells(cells) {
1717
+ return cells.map(cell => ({
1718
+ text: cell.text_value,
1719
+ attachmentPoint: cell.cell_alignment,
1720
+ textStyle: cell.text_style
1721
+ ? String(cell.text_style)
1722
+ : undefined,
1723
+ rotation: cell.rotation,
1724
+ cellType: cell.type,
1725
+ flagValue: cell.flags,
1726
+ mergedValue: cell.is_merged_value,
1727
+ autoFit: cell.is_autofit_flag,
1728
+ topBorderVisibility: !!cell.top_visibility,
1729
+ bottomBorderVisibility: !!cell.bottom_visibility,
1730
+ leftBorderVisibility: !!cell.left_visibility,
1731
+ rightBorderVisibility: !!cell.right_visibility,
1732
+ overrideFlag: cell.cell_flag_override,
1733
+ virtualEdgeFlag: cell.virtual_edge_flag,
1734
+ blockTableRecordId: cell.block_handle
1735
+ ? String(cell.block_handle.absolute_ref ?? '')
1736
+ : undefined,
1737
+ blockScale: cell.block_scale,
1738
+ blockAttrNum: cell.attr_defs?.length ?? 0,
1739
+ attrDefineId: cell.attr_defs?.map(value => String(value.attdef?.absolute_ref ?? '')),
1740
+ textHeight: cell.text_height ?? 0,
1741
+ extendedCellFlags: cell.additional_data_flag
1742
+ }));
1743
+ }
1744
+ convertTextBase(entity) {
1745
+ const libredwg = this.libredwg;
1746
+ const text = libredwg.dwg_dynapi_entity_data(entity, 'text_value');
1747
+ const thickness = libredwg.dwg_dynapi_entity_data(entity, 'thickness');
1748
+ const startPoint = libredwg.dwg_dynapi_entity_data(entity, 'ins_pt');
1749
+ const endPoint = libredwg.dwg_dynapi_entity_data(entity, 'alignment_pt');
1750
+ const rotation = libredwg.dwg_dynapi_entity_data(entity, 'rotation');
1751
+ const textHeight = libredwg.dwg_dynapi_entity_data(entity, 'height');
1752
+ const xScale = libredwg.dwg_dynapi_entity_data(entity, 'width_factor');
1753
+ const obliqueAngle = libredwg.dwg_dynapi_entity_data(entity, 'oblique_angle');
1754
+ const styleName = libredwg.dwg_entity_text_get_style_name(entity);
1755
+ const generationFlag = libredwg.dwg_dynapi_entity_data(entity, 'generation');
1756
+ const halign = libredwg.dwg_dynapi_entity_data(entity, 'horiz_alignment');
1757
+ const valign = libredwg.dwg_dynapi_entity_data(entity, 'vert_alignment');
1758
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1759
+ return {
1760
+ text: text,
1761
+ thickness: thickness,
1762
+ startPoint: startPoint,
1763
+ endPoint: endPoint,
1764
+ textHeight: textHeight,
1765
+ rotation: rotation,
1766
+ xScale: xScale,
1767
+ obliqueAngle: obliqueAngle,
1768
+ styleName: styleName,
1769
+ generationFlag: generationFlag,
1770
+ halign: halign,
1771
+ valign: valign,
1772
+ extrusionDirection: extrusionDirection
1773
+ };
1774
+ }
1775
+ convertText(entity, commonAttrs) {
1776
+ return {
1777
+ type: 'TEXT',
1778
+ ...commonAttrs,
1779
+ ...this.convertTextBase(entity)
1780
+ };
1781
+ }
1782
+ convertTolerance(entity, commonAttrs) {
1783
+ const libredwg = this.libredwg;
1784
+ const insertionPoint = libredwg.dwg_dynapi_entity_data(entity, 'ins_pt');
1785
+ const text = libredwg.dwg_dynapi_entity_data(entity, 'text_value');
1786
+ const xAxisDirection = libredwg.dwg_dynapi_entity_data(entity, 'x_direction');
1787
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1788
+ const dimStyleName = libredwg.dwg_entity_get_dimstyle_name(entity);
1789
+ return {
1790
+ type: 'TOLERANCE',
1791
+ ...commonAttrs,
1792
+ styleName: dimStyleName,
1793
+ insertionPoint: insertionPoint,
1794
+ text: text,
1795
+ extrusionDirection: extrusionDirection,
1796
+ xAxisDirection: xAxisDirection
1797
+ };
1798
+ }
1799
+ convertViewport(entity, commonAttrs) {
1800
+ const libredwg = this.libredwg;
1801
+ const viewportCenter = libredwg.dwg_dynapi_entity_data(entity, 'center');
1802
+ const width = libredwg.dwg_dynapi_entity_data(entity, 'width');
1803
+ const height = libredwg.dwg_dynapi_entity_data(entity, 'height');
1804
+ const status = libredwg.dwg_dynapi_entity_data(entity, 'on_off');
1805
+ const displayCenter = libredwg.dwg_dynapi_entity_data(entity, 'VIEWCTR');
1806
+ const snapBase = libredwg.dwg_dynapi_entity_data(entity, 'SNAPBASE');
1807
+ const snapSpacing = libredwg.dwg_dynapi_entity_data(entity, 'SNAPUNIT');
1808
+ const gridSpacing = libredwg.dwg_dynapi_entity_data(entity, 'GRIDUNIT');
1809
+ const viewDirection = libredwg.dwg_dynapi_entity_data(entity, 'VIEWDIR');
1810
+ const targetPoint = libredwg.dwg_dynapi_entity_data(entity, 'view_target');
1811
+ const perspectiveLensLength = libredwg.dwg_dynapi_entity_data(entity, 'lens_length');
1812
+ const frontClipZ = libredwg.dwg_dynapi_entity_data(entity, 'front_clip_z');
1813
+ const backClipZ = libredwg.dwg_dynapi_entity_data(entity, 'back_clip_z');
1814
+ // TODO: I am not sure whether view size in libredwg represents view height
1815
+ const viewHeight = libredwg.dwg_dynapi_entity_data(entity, 'VIEWSIZE');
1816
+ const snapAngle = libredwg.dwg_dynapi_entity_data(entity, 'SNAPANG');
1817
+ const viewTwistAngle = libredwg.dwg_dynapi_entity_data(entity, 'twist_angle');
1818
+ const circleZoomPercent = libredwg.dwg_dynapi_entity_data(entity, 'circle_zoom');
1819
+ const numFrozenLayers = libredwg.dwg_dynapi_entity_data(entity, 'num_frozen_layers');
1820
+ let frozenLayerIds;
1821
+ if (numFrozenLayers > 0) {
1822
+ const frozenLayersPtr = libredwg.dwg_dynapi_entity_data(entity, 'frozen_layers');
1823
+ if (frozenLayersPtr) {
1824
+ const frozenLayers = libredwg.dwg_ptr_to_object_ref_ptr_array(frozenLayersPtr, numFrozenLayers);
1825
+ frozenLayerIds = frozenLayers
1826
+ .map(ref => libredwg.dwg_ref_get_id(ref))
1827
+ .filter((id) => !!id);
1828
+ }
1829
+ }
1830
+ const statusBitFlags = libredwg.dwg_dynapi_entity_data(entity, 'status_flag');
1831
+ const clip_boundary_ref = libredwg.dwg_dynapi_entity_data(entity, 'clip_boundary');
1832
+ const clippingBoundaryId = libredwg.dwg_ref_get_id(clip_boundary_ref);
1833
+ const sheetName = libredwg.dwg_dynapi_entity_data(entity, 'style_sheet');
1834
+ const renderMode = libredwg.dwg_dynapi_entity_data(entity, 'render_mode');
1835
+ // TODO: Not sure whether UCSVP in libredwg represents ucsPerViewport
1836
+ const ucsPerViewport = libredwg.dwg_dynapi_entity_data(entity, 'UCSVP');
1837
+ const ucsOrigin = libredwg.dwg_dynapi_entity_data(entity, 'ucsorg');
1838
+ const ucsXAxis = libredwg.dwg_dynapi_entity_data(entity, 'ucsxdir');
1839
+ const ucsYAxis = libredwg.dwg_dynapi_entity_data(entity, 'ucsydir');
1840
+ const named_ucs_ref = libredwg.dwg_dynapi_entity_data(entity, 'named_ucs');
1841
+ const ucsId = libredwg.dwg_ref_get_id(named_ucs_ref);
1842
+ const base_ucs_ref = libredwg.dwg_dynapi_entity_data(entity, 'base_ucs');
1843
+ const ucsBaseId = libredwg.dwg_ref_get_id(base_ucs_ref);
1844
+ // TODO: Not sure whether UCSORTHOVIEW represents orthographicType
1845
+ const orthographicType = libredwg.dwg_dynapi_entity_data(entity, 'UCSORTHOVIEW');
1846
+ const elevation = libredwg.dwg_dynapi_entity_data(entity, 'ucs_elevation');
1847
+ const shadePlotMode = libredwg.dwg_dynapi_entity_data(entity, 'shadeplot_mode');
1848
+ const isDefaultLighting = libredwg.dwg_dynapi_entity_data(entity, 'use_default_lights');
1849
+ const defaultLightingType = libredwg.dwg_dynapi_entity_data(entity, 'default_lighting_type');
1850
+ const brightness = libredwg.dwg_dynapi_entity_data(entity, 'brightness');
1851
+ const contrast = libredwg.dwg_dynapi_entity_data(entity, 'contrast');
1852
+ const majorGridFrequency = libredwg.dwg_dynapi_entity_data(entity, 'grid_major');
1853
+ const background_ref = libredwg.dwg_dynapi_entity_data(entity, 'background');
1854
+ const backgroundId = libredwg.dwg_ref_get_id(background_ref);
1855
+ const shadeplot_ref = libredwg.dwg_dynapi_entity_data(entity, 'shadeplot');
1856
+ const shadePlotId = libredwg.dwg_ref_get_id(shadeplot_ref);
1857
+ const visualstyle_ref = libredwg.dwg_dynapi_entity_data(entity, 'visualstyle');
1858
+ const visualStyleId = libredwg.dwg_ref_get_id(visualstyle_ref);
1859
+ // TODO: convert ambientLightColor
1860
+ const sun_ref = libredwg.dwg_dynapi_entity_data(entity, 'sun');
1861
+ const sunId = libredwg.dwg_ref_get_id(sun_ref);
1862
+ return {
1863
+ type: 'VIEWPORT',
1864
+ ...commonAttrs,
1865
+ viewportCenter: viewportCenter,
1866
+ width: width,
1867
+ height: height,
1868
+ status: status,
1869
+ viewportId: 0, // Will be set later in LibreDwgConverter.convert
1870
+ displayCenter: displayCenter,
1871
+ snapBase: snapBase,
1872
+ snapSpacing: snapSpacing,
1873
+ gridSpacing: gridSpacing,
1874
+ viewDirection: viewDirection,
1875
+ targetPoint: targetPoint,
1876
+ perspectiveLensLength: perspectiveLensLength,
1877
+ frontClipZ: frontClipZ,
1878
+ backClipZ: backClipZ,
1879
+ viewHeight: viewHeight,
1880
+ snapAngle: snapAngle,
1881
+ viewTwistAngle: viewTwistAngle,
1882
+ circleZoomPercent: circleZoomPercent,
1883
+ frozenLayerIds,
1884
+ statusBitFlags: statusBitFlags,
1885
+ clippingBoundaryId,
1886
+ sheetName: sheetName,
1887
+ renderMode: renderMode,
1888
+ ucsPerViewport: ucsPerViewport,
1889
+ ucsOrigin: ucsOrigin,
1890
+ ucsXAxis: ucsXAxis,
1891
+ ucsYAxis: ucsYAxis,
1892
+ ucsId: ucsId ?? '',
1893
+ ucsBaseId: ucsBaseId ?? '',
1894
+ orthographicType: orthographicType,
1895
+ elevation: elevation,
1896
+ shadePlotMode: shadePlotMode,
1897
+ majorGridFrequency: majorGridFrequency,
1898
+ backgroundId: backgroundId ?? '',
1899
+ shadePlotId: shadePlotId ?? '',
1900
+ visualStyleId: visualStyleId ?? '',
1901
+ isDefaultLighting: !!isDefaultLighting,
1902
+ defaultLightingType: defaultLightingType,
1903
+ brightness: brightness,
1904
+ contrast: contrast,
1905
+ sunId: sunId ?? ''
1906
+ };
1907
+ }
1908
+ convertWipeout(entity, commonAttrs) {
1909
+ const libredwg = this.libredwg;
1910
+ const version = libredwg.dwg_dynapi_entity_data(entity, 'class_version');
1911
+ const position = libredwg.dwg_dynapi_entity_data(entity, 'pt0');
1912
+ const uPixel = libredwg.dwg_dynapi_entity_data(entity, 'uvec');
1913
+ const vPixel = libredwg.dwg_dynapi_entity_data(entity, 'vvec');
1914
+ const imageSize = libredwg.dwg_dynapi_entity_data(entity, 'image_size');
1915
+ const flags = libredwg.dwg_dynapi_entity_data(entity, 'display_props');
1916
+ const clipping = libredwg.dwg_dynapi_entity_data(entity, 'clipping');
1917
+ const brightness = libredwg.dwg_dynapi_entity_data(entity, 'brightness');
1918
+ const contrast = libredwg.dwg_dynapi_entity_data(entity, 'contrast');
1919
+ const fade = libredwg.dwg_dynapi_entity_data(entity, 'fade');
1920
+ const clipMode = libredwg.dwg_dynapi_entity_data(entity, 'clip_mode');
1921
+ const clippingBoundaryType = libredwg.dwg_dynapi_entity_data(entity, 'clip_boundary_type');
1922
+ const countBoundaryPoints = libredwg.dwg_dynapi_entity_data(entity, 'num_clip_verts');
1923
+ const clip_verts = libredwg.dwg_dynapi_entity_data(entity, 'clip_verts');
1924
+ const clippingBoundaryPath = libredwg.dwg_ptr_to_point2d_array(clip_verts, countBoundaryPoints);
1925
+ const imagedef_ref = libredwg.dwg_dynapi_entity_data(entity, 'imagedef');
1926
+ const imageDefHandle = libredwg.dwg_ref_get_absref(imagedef_ref) ?? 0;
1927
+ const imagedefreactor_ref = libredwg.dwg_dynapi_entity_data(entity, 'imagedefreactor');
1928
+ const imageDefReactorHandle = libredwg.dwg_ref_get_absref(imagedefreactor_ref) ?? 0;
1929
+ return {
1930
+ type: 'WIPEOUT',
1931
+ ...commonAttrs,
1932
+ version: version,
1933
+ position: position,
1934
+ uPixel: uPixel,
1935
+ vPixel: vPixel,
1936
+ imageSize: imageSize,
1937
+ imageDefHandle: imageDefHandle,
1938
+ flags: flags,
1939
+ clipping: clipping,
1940
+ brightness: brightness,
1941
+ contrast: contrast,
1942
+ fade: fade,
1943
+ imageDefReactorHandle: imageDefReactorHandle,
1944
+ clippingBoundaryType: clippingBoundaryType,
1945
+ countBoundaryPoints: countBoundaryPoints,
1946
+ clippingBoundaryPath: clippingBoundaryPath,
1947
+ clipMode: clipMode
1948
+ };
1949
+ }
1950
+ convertXline(entity, commonAttrs) {
1951
+ const libredwg = this.libredwg;
1952
+ const firstPoint = libredwg.dwg_dynapi_entity_data(entity, 'point');
1953
+ const unitDirection = libredwg.dwg_dynapi_entity_data(entity, 'vector');
1954
+ return {
1955
+ type: 'XLINE',
1956
+ ...commonAttrs,
1957
+ firstPoint: firstPoint,
1958
+ unitDirection: unitDirection
1959
+ };
1960
+ }
1961
+ getDimensionCommonAttrs(entity) {
1962
+ const libredwg = this.libredwg;
1963
+ const version = libredwg.dwg_dynapi_entity_data(entity, 'class_version');
1964
+ const name = libredwg.dwg_entity_get_block_name(entity, 'block');
1965
+ const definitionPoint = libredwg.dwg_dynapi_entity_data(entity, 'def_pt');
1966
+ const textPoint = libredwg.dwg_dynapi_entity_data(entity, 'text_midpt');
1967
+ const attachmentPoint = libredwg.dwg_dynapi_entity_data(entity, 'attachmentPoint');
1968
+ const dimensionType = libredwg.dwg_dynapi_entity_data(entity, 'flag');
1969
+ const textLineSpacingStyle = libredwg.dwg_dynapi_entity_data(entity, 'lspace_factor');
1970
+ const textLineSpacingFactor = libredwg.dwg_dynapi_entity_data(entity, 'lspace_factor');
1971
+ const measurement = libredwg.dwg_dynapi_entity_data(entity, 'act_measurement');
1972
+ const text = libredwg.dwg_dynapi_entity_data(entity, 'user_text');
1973
+ const textRotation = libredwg.dwg_dynapi_entity_data(entity, 'text_rotation');
1974
+ // TODO: Not sure whether 'ins_rotation' is 'ocsRotation'.
1975
+ const ocsRotation = libredwg.dwg_dynapi_entity_data(entity, 'ins_rotation');
1976
+ const extrusionDirection = libredwg.dwg_dynapi_entity_data(entity, 'extrusion');
1977
+ const styleName = libredwg.dwg_entity_get_dimstyle_name(entity);
1978
+ return {
1979
+ type: 'DIMENSION',
1980
+ version: version,
1981
+ name: name,
1982
+ definitionPoint: definitionPoint,
1983
+ textPoint: textPoint,
1984
+ dimensionType: dimensionType,
1985
+ attachmentPoint: attachmentPoint,
1986
+ textLineSpacingStyle: textLineSpacingStyle,
1987
+ textLineSpacingFactor: textLineSpacingFactor || 1,
1988
+ measurement: measurement,
1989
+ text: text,
1990
+ textRotation: textRotation,
1991
+ ocsRotation: ocsRotation,
1992
+ extrusionDirection: extrusionDirection,
1993
+ styleName: styleName
1994
+ };
1995
+ }
1996
+ getCommonAttrs(entity) {
1997
+ const libredwg = this.libredwg;
1998
+ const color = libredwg.dwg_object_entity_get_color_object(entity);
1999
+ // - 0xc0 for ByLayer (also c3 and rgb of 0x100)
2000
+ // - 0xc1 for ByBlock (also c3 and rgb of 0)
2001
+ // - 0xc2 for entities (default), with names with an additional name flag RC
2002
+ // - 0xc3 for truecolor
2003
+ // - 0xc5 for foreground color
2004
+ // - 0xc8 for none (also c3 and rgb of 0x101)
2005
+ const method = color.method;
2006
+ const colorIndex = color.index;
2007
+ let rgbColor = undefined;
2008
+ if (method == 0xc2 || ((color.rgb >>> 24) & 0xff) === 0xc2) {
2009
+ rgbColor = color.rgb & 0x00ffffff;
2010
+ }
2011
+ const layer = this.getLayerName(entity);
2012
+ const handle = libredwg.dwg_object_entity_get_handle_object(entity);
2013
+ const ownerhandle = libredwg.dwg_object_entity_get_ownerhandle_object(entity);
2014
+ const ownerDictionaryHardId = libredwg.dwg_object_entity_get_xdicobjhandle_object(entity);
2015
+ const lineType = this.getLtypeName(entity);
2016
+ const lineweight = libredwg.dwg_object_entity_get_line_weight(entity);
2017
+ const lineTypeScale = libredwg.dwg_object_entity_get_ltype_scale(entity);
2018
+ const isVisible = !libredwg.dwg_object_entity_get_invisible(entity);
2019
+ const xdata = libredwg.dwg_object_entity_get_xdata(entity);
2020
+ return {
2021
+ handle: idToString(handle.value),
2022
+ ownerDictionaryHardId: idToString(ownerDictionaryHardId.absolute_ref),
2023
+ ownerBlockRecordSoftId: idToString(ownerhandle.absolute_ref),
2024
+ layer: layer,
2025
+ color: rgbColor,
2026
+ colorIndex: colorIndex,
2027
+ colorName: color.name,
2028
+ lineType: lineType,
2029
+ lineweight: lineweight,
2030
+ lineTypeScale: lineTypeScale,
2031
+ isVisible: isVisible,
2032
+ transparency: color.alpha,
2033
+ transparencyType: color.alpha_type,
2034
+ xdata: xdata
2035
+ };
2036
+ }
2037
+ getLayerName(entity) {
2038
+ const libredwg = this.libredwg;
2039
+ const layer = libredwg.dwg_object_entity_get_layer_object_ref(entity);
2040
+ const name = this.layers.get(idToString(layer.handleref.value));
2041
+ return name ?? '0';
2042
+ }
2043
+ getLtypeName(entity) {
2044
+ const libredwg = this.libredwg;
2045
+ const ltype = libredwg.dwg_object_entity_get_ltype_object_ref(entity);
2046
+ const name = this.ltypes.get(idToString(ltype.handleref.value));
2047
+ return name ?? '';
2048
+ }
2049
+ }
2050
+ //# sourceMappingURL=entityConverter.js.map