@mlightcad/data-model 1.9.1 → 1.9.2

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.
@@ -0,0 +1,1104 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
+ if (ar || !(i in from)) {
20
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
+ ar[i] = from[i];
22
+ }
23
+ }
24
+ return to.concat(ar || Array.prototype.slice.call(from));
25
+ };
26
+ var __values = (this && this.__values) || function(o) {
27
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
28
+ if (m) return m.call(o);
29
+ if (o && typeof o.length === "number") return {
30
+ next: function () {
31
+ if (o && i >= o.length) o = void 0;
32
+ return { value: o && o[i++], done: !o };
33
+ }
34
+ };
35
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
36
+ };
37
+ import { AcCmColor, AcCmColorMethod, AcCmColorUtil } from '@mlightcad/common';
38
+ import { AcGeArea2d, AcGeCircArc3d, AcGeEllipseArc3d, AcGeMatrix3d, AcGePoint3d, AcGePolyline2d, AcGeVector3d, getOcsAngle, getOcsReferenceVector, TAU, transformOcsPointToWcs, transformWcsPointToOcs } from '@mlightcad/geometry-engine';
39
+ import { AcGiLineWeight, AcGiMTextAttachmentPoint, AcGiMTextFlowDirection } from '@mlightcad/graphic-interface';
40
+ import { ByBlock, ByLayer, DEFAULT_TEXT_STYLE } from '../AcDbConstants';
41
+ import { RAW_COLOR_TYPE_ACI, RAW_COLOR_TYPE_BY_BLOCK, RAW_COLOR_TYPE_BY_LAYER, RAW_COLOR_TYPE_RGB } from '../AcDbMLeaderStyleColorCodec';
42
+ import { AcDbProxyGraphicBitStream, AcDbProxyGraphicByteStream } from './AcDbProxyGraphicBinaryStream';
43
+ /**
44
+ * Maximum number of bytes written to each DXF group code **310** chunk when
45
+ * exporting proxy graphics.
46
+ *
47
+ * AutoCAD splits large binary payloads into 127-byte hexadecimal records.
48
+ */
49
+ export var ACDB_PROXY_GRAPHIC_CHUNK_SIZE = 127;
50
+ /**
51
+ * Proxy-graphic command type codes defined by ODA and used by ezdxf.
52
+ *
53
+ * Each record in a proxy-graphic stream begins with an 8-byte header
54
+ * `(size, type)` followed by a type-specific payload. Attribute commands affect
55
+ * subsequent geometry; matrix commands push and pop a transform stack.
56
+ */
57
+ export var AcDbProxyGraphicType;
58
+ (function (AcDbProxyGraphicType) {
59
+ /** Axis-aligned bounding box extents (type code 1). */
60
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Extents"] = 1] = "Extents";
61
+ /** Circle defined by center, radius, and normal (type code 2). */
62
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Circle"] = 2] = "Circle";
63
+ /** Circle defined by three points (type code 3). */
64
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Circle3P"] = 3] = "Circle3P";
65
+ /** Circular arc defined by center, radius, normal, start vector, and sweep (type code 4). */
66
+ AcDbProxyGraphicType[AcDbProxyGraphicType["CircularArc"] = 4] = "CircularArc";
67
+ /** Circular arc defined by three points (type code 5). */
68
+ AcDbProxyGraphicType[AcDbProxyGraphicType["CircularArc3P"] = 5] = "CircularArc3P";
69
+ /** Open polyline or single-point entity (type code 6). */
70
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Polyline"] = 6] = "Polyline";
71
+ /** Closed polygon, optionally filled (type code 7). */
72
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Polygon"] = 7] = "Polygon";
73
+ /** Triangle mesh (type code 8). Not currently rendered. */
74
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Mesh"] = 8] = "Mesh";
75
+ /** Faceted shell rendered as edge segments (type code 9). */
76
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Shell"] = 9] = "Shell";
77
+ /** Single-byte text primitive (type code 10). */
78
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Text"] = 10] = "Text";
79
+ /** Extended single-byte text primitive (type code 11). */
80
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Text2"] = 11] = "Text2";
81
+ /** Construction line through two points (type code 12). */
82
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Xline"] = 12] = "Xline";
83
+ /** Ray from a base point through a second point (type code 13). */
84
+ AcDbProxyGraphicType[AcDbProxyGraphicType["Ray"] = 13] = "Ray";
85
+ /** Sets the ACI color index for subsequent geometry (type code 14). */
86
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeColor"] = 14] = "AttributeColor";
87
+ /** Sets the layer by table index for subsequent geometry (type code 16). */
88
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeLayer"] = 16] = "AttributeLayer";
89
+ /** Sets the linetype by table index for subsequent geometry (type code 18). */
90
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeLinetype"] = 18] = "AttributeLinetype";
91
+ /** Marker attribute reserved by the format (type code 19). */
92
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeMarker"] = 19] = "AttributeMarker";
93
+ /** Enables or disables solid fill for the next polygon (type code 20). */
94
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeFill"] = 20] = "AttributeFill";
95
+ /** Sets true-color or special color encoding (type code 22). */
96
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeTrueColor"] = 22] = "AttributeTrueColor";
97
+ /** Sets lineweight for subsequent geometry (type code 23). */
98
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeLineweight"] = 23] = "AttributeLineweight";
99
+ /** Sets linetype scale for subsequent geometry (type code 24). */
100
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeLtscale"] = 24] = "AttributeLtscale";
101
+ /** Sets thickness for subsequent geometry (type code 25). */
102
+ AcDbProxyGraphicType[AcDbProxyGraphicType["AttributeThickness"] = 25] = "AttributeThickness";
103
+ /** Pushes a 4×4 transform matrix onto the matrix stack (type code 29). */
104
+ AcDbProxyGraphicType[AcDbProxyGraphicType["PushMatrix"] = 29] = "PushMatrix";
105
+ /** Pops the top transform matrix off the matrix stack (type code 31). */
106
+ AcDbProxyGraphicType[AcDbProxyGraphicType["PopMatrix"] = 31] = "PopMatrix";
107
+ /** Polyline with an appended normal vector (type code 32). */
108
+ AcDbProxyGraphicType[AcDbProxyGraphicType["PolylineWithNormals"] = 32] = "PolylineWithNormals";
109
+ /** Lightweight polyline encoded with DWG bit fields (type code 33). */
110
+ AcDbProxyGraphicType[AcDbProxyGraphicType["LwPolyline"] = 33] = "LwPolyline";
111
+ /** Unicode text primitive (type code 36). */
112
+ AcDbProxyGraphicType[AcDbProxyGraphicType["UnicodeText"] = 36] = "UnicodeText";
113
+ /** Extended Unicode text primitive (type code 38). */
114
+ AcDbProxyGraphicType[AcDbProxyGraphicType["UnicodeText2"] = 38] = "UnicodeText2";
115
+ /** Elliptical arc primitive (type code 44). */
116
+ AcDbProxyGraphicType[AcDbProxyGraphicType["EllipticArc"] = 44] = "EllipticArc";
117
+ })(AcDbProxyGraphicType || (AcDbProxyGraphicType = {}));
118
+ /** World Z axis used as the default entity normal. */
119
+ var Z_AXIS = AcGeVector3d.Z_AXIS;
120
+ /** Maximum raw lineweight value before sign extension is applied. */
121
+ var MAX_VALID_LINEWEIGHT = 0x211;
122
+ /**
123
+ * Decodes a packed 32-bit proxy-graphic color value into ACI or RGB parts.
124
+ *
125
+ * @param raw - Packed color dword from an {@link AcDbProxyGraphicType.AttributeTrueColor} chunk.
126
+ * @returns Decoded color index and/or 24-bit RGB value.
127
+ */
128
+ function decodeProxyGraphicRawColor(raw) {
129
+ var type = (raw >> 24) & 0xff;
130
+ if (type === RAW_COLOR_TYPE_RGB) {
131
+ return { rgb: raw & 0xffffff };
132
+ }
133
+ if (type === RAW_COLOR_TYPE_BY_LAYER) {
134
+ return { colorIndex: 256 };
135
+ }
136
+ if (type === RAW_COLOR_TYPE_BY_BLOCK) {
137
+ return { colorIndex: 0 };
138
+ }
139
+ if (type === RAW_COLOR_TYPE_ACI) {
140
+ return { colorIndex: raw & 0xff };
141
+ }
142
+ return { colorIndex: raw & 0xff };
143
+ }
144
+ /**
145
+ * Converts a {@link AcGeVector3dLike} object to an {@link AcGeVector3d}.
146
+ *
147
+ * @param v - Input vector-like value.
148
+ * @returns A concrete 3D vector with `z` defaulting to `0` when omitted.
149
+ */
150
+ function vectorFromLike(v) {
151
+ var _a;
152
+ return new AcGeVector3d(v.x, v.y, (_a = v.z) !== null && _a !== void 0 ? _a : 0);
153
+ }
154
+ /**
155
+ * Converts a {@link AcGePoint3dLike} object to an {@link AcGePoint3d}.
156
+ *
157
+ * @param p - Input point-like value.
158
+ * @returns A concrete 3D point with `z` defaulting to `0` when omitted.
159
+ */
160
+ function pointFromLike(p) {
161
+ var _a;
162
+ return new AcGePoint3d(p.x, p.y, (_a = p.z) !== null && _a !== void 0 ? _a : 0);
163
+ }
164
+ /**
165
+ * Converts a numeric vertex tuple to a {@link AcGePoint3dLike} object.
166
+ *
167
+ * @param v - Vertex as `[x, y, z]`.
168
+ * @returns A point-like object suitable for geometry helpers.
169
+ */
170
+ function vertexTuple(v) {
171
+ return { x: v[0], y: v[1], z: v[2] };
172
+ }
173
+ /**
174
+ * Decodes AutoCAD proxy-entity graphics binary data and renders primitives
175
+ * through {@link AcGiRenderer}.
176
+ *
177
+ * A proxy-graphic buffer is a sequence of length-prefixed chunks. Each chunk
178
+ * begins with a little-endian header `(size, type)` where `size` includes the
179
+ * 8-byte header itself. Geometry commands emit drawable entities; attribute
180
+ * commands update a lightweight graphics-state machine (color, layer, linetype,
181
+ * fill, and so on).
182
+ *
183
+ * The implementation follows the ODA proxy-graphic format used by ezdxf's
184
+ * `ProxyGraphic` module.
185
+ *
186
+ * @see {@link AcDbProxyEntity.subWorldDraw}
187
+ */
188
+ var AcDbProxyGraphic = /** @class */ (function () {
189
+ /**
190
+ * Creates a proxy-graphic parser over the given byte stream.
191
+ *
192
+ * When a {@link AcDbDatabase} is supplied, layer and linetype tables are
193
+ * cached so attribute commands can resolve table indices to names.
194
+ *
195
+ * @param data - Raw proxy-graphic bytes from a proxy entity.
196
+ * @param options - Optional decoding and rendering context.
197
+ */
198
+ function AcDbProxyGraphic(data, options) {
199
+ if (options === void 0) { options = {}; }
200
+ var _this = this;
201
+ var _a, _b, _c;
202
+ /** Index of the first chunk header. Skips the 8-byte stream prefix. */
203
+ this._index = 8;
204
+ /** Current ACI color index for subsequent geometry. `256` means ByLayer. */
205
+ this._colorIndex = 256;
206
+ /** Current layer name for subsequent geometry. */
207
+ this._layer = '0';
208
+ /** Current linetype name for subsequent geometry. */
209
+ this._linetype = ByLayer;
210
+ /** Current lineweight for subsequent geometry. */
211
+ this._lineweight = AcGiLineWeight.ByLineWeightDefault;
212
+ /** Current linetype scale for subsequent geometry. */
213
+ this._ltscale = 1;
214
+ /** Current thickness for subsequent geometry. */
215
+ this._thickness = 0;
216
+ /** When `true`, the next {@link AcDbProxyGraphicType.Polygon} is filled. */
217
+ this._fill = false;
218
+ /** Layer names indexed by {@link AcDbProxyGraphicType.AttributeLayer} values. */
219
+ this._layers = [];
220
+ /** Linetype names indexed by {@link AcDbProxyGraphicType.AttributeLinetype} values. */
221
+ this._linetypes = [];
222
+ /** Active transform stack applied to decoded points and vectors. */
223
+ this._matrices = [];
224
+ this._buffer = data;
225
+ this._database = options.database;
226
+ this._dxfversion = (_a = options.dxfversion) !== null && _a !== void 0 ? _a : 'AC1015';
227
+ this._encoding =
228
+ (_b = options.encoding) !== null && _b !== void 0 ? _b : (this._dxfversion < 'AC1024' ? 'windows-1252' : 'utf-8');
229
+ this._layer = (_c = options.defaultLayer) !== null && _c !== void 0 ? _c : '0';
230
+ if (this._database) {
231
+ this._database.tables.layerTable
232
+ .newIterator()
233
+ .toArray()
234
+ .forEach(function (layer) { return _this._layers.push(layer.name); });
235
+ this._database.tables.linetypeTable
236
+ .newIterator()
237
+ .toArray()
238
+ .forEach(function (linetype) { return _this._linetypes.push(linetype.name); });
239
+ }
240
+ }
241
+ Object.defineProperty(AcDbProxyGraphic.prototype, "extents", {
242
+ /**
243
+ * Gets the most recently parsed extents corners.
244
+ *
245
+ * @returns Minimum and maximum corners from the last EXTENTS chunk, or
246
+ * `undefined` when no extents chunk has been read.
247
+ */
248
+ get: function () {
249
+ return this._extents;
250
+ },
251
+ enumerable: false,
252
+ configurable: true
253
+ });
254
+ /**
255
+ * Scans the buffer for an {@link AcDbProxyGraphicType.Extents} chunk without
256
+ * rendering geometry.
257
+ *
258
+ * @returns The minimum and maximum corners when an EXTENTS chunk is found,
259
+ * otherwise `undefined`.
260
+ */
261
+ AcDbProxyGraphic.prototype.scanExtents = function () {
262
+ var _a;
263
+ var buffer = this._buffer;
264
+ var index = this._index;
265
+ while (index < buffer.length) {
266
+ var headerView = new DataView(buffer.buffer, buffer.byteOffset + index, 8);
267
+ var size = headerView.getUint32(0, true);
268
+ var type = headerView.getUint32(4, true);
269
+ if (size < 8) {
270
+ break;
271
+ }
272
+ if (type === AcDbProxyGraphicType.Extents) {
273
+ var chunk = buffer.subarray(index + 8, index + size);
274
+ this.readExtents(chunk);
275
+ if (((_a = this._extents) === null || _a === void 0 ? void 0 : _a.length) === 2) {
276
+ return [this._extents[0], this._extents[1]];
277
+ }
278
+ return undefined;
279
+ }
280
+ index += size;
281
+ }
282
+ return undefined;
283
+ };
284
+ /**
285
+ * Parses the full proxy-graphic stream and renders drawable primitives.
286
+ *
287
+ * Renderer sub-entity traits are saved before parsing and restored afterward
288
+ * so attribute commands do not leak state to the caller.
289
+ *
290
+ * @param renderer - Target graphics renderer.
291
+ * @returns A grouped {@link AcGiEntity} when at least one primitive was
292
+ * emitted, otherwise `undefined`.
293
+ */
294
+ AcDbProxyGraphic.prototype.worldDraw = function (renderer) {
295
+ var entities = [];
296
+ var traits = renderer.subEntityTraits;
297
+ var previousTraits = {
298
+ color: traits.color.clone(),
299
+ rgbColor: traits.rgbColor,
300
+ lineType: traits.lineType,
301
+ lineTypeScale: traits.lineTypeScale,
302
+ lineWeight: traits.lineWeight,
303
+ layer: traits.layer,
304
+ thickness: traits.thickness
305
+ };
306
+ var buffer = this._buffer;
307
+ var index = this._index;
308
+ while (index < buffer.length) {
309
+ var headerView = new DataView(buffer.buffer, buffer.byteOffset + index, 8);
310
+ var size = headerView.getUint32(0, true);
311
+ var type = headerView.getUint32(4, true);
312
+ if (size < 8) {
313
+ break;
314
+ }
315
+ var chunk = buffer.subarray(index + 8, index + size);
316
+ this.dispatchChunk(renderer, entities, type, chunk);
317
+ if (type !== AcDbProxyGraphicType.AttributeFill) {
318
+ this._fill = false;
319
+ }
320
+ index += size;
321
+ }
322
+ traits.color = previousTraits.color;
323
+ traits.rgbColor = previousTraits.rgbColor;
324
+ traits.lineType = previousTraits.lineType;
325
+ traits.lineTypeScale = previousTraits.lineTypeScale;
326
+ traits.lineWeight = previousTraits.lineWeight;
327
+ traits.layer = previousTraits.layer;
328
+ traits.thickness = previousTraits.thickness;
329
+ if (entities.length === 0) {
330
+ return undefined;
331
+ }
332
+ return renderer.group(entities);
333
+ };
334
+ /**
335
+ * Dispatches a single proxy-graphic chunk to the appropriate handler.
336
+ *
337
+ * @param renderer - Target graphics renderer.
338
+ * @param entities - Accumulator for emitted drawable entities.
339
+ * @param type - Chunk type code from {@link AcDbProxyGraphicType}.
340
+ * @param data - Chunk payload bytes excluding the 8-byte header.
341
+ */
342
+ AcDbProxyGraphic.prototype.dispatchChunk = function (renderer, entities, type, data) {
343
+ switch (type) {
344
+ case AcDbProxyGraphicType.Extents:
345
+ this.readExtents(data);
346
+ break;
347
+ case AcDbProxyGraphicType.Circle:
348
+ this.drawCircle(renderer, entities, data);
349
+ break;
350
+ case AcDbProxyGraphicType.Circle3P:
351
+ this.drawCircle3P(renderer, entities, data);
352
+ break;
353
+ case AcDbProxyGraphicType.CircularArc:
354
+ this.drawCircularArc(renderer, entities, data);
355
+ break;
356
+ case AcDbProxyGraphicType.CircularArc3P:
357
+ this.drawCircularArc3P(renderer, entities, data);
358
+ break;
359
+ case AcDbProxyGraphicType.EllipticArc:
360
+ this.drawEllipticArc(renderer, entities, data);
361
+ break;
362
+ case AcDbProxyGraphicType.Polyline:
363
+ this.drawPolyline(renderer, entities, data, false);
364
+ break;
365
+ case AcDbProxyGraphicType.PolylineWithNormals:
366
+ this.drawPolyline(renderer, entities, data, true);
367
+ break;
368
+ case AcDbProxyGraphicType.Polygon:
369
+ this.drawPolygon(renderer, entities, data);
370
+ break;
371
+ case AcDbProxyGraphicType.LwPolyline:
372
+ this.drawLwPolyline(renderer, entities, data);
373
+ break;
374
+ case AcDbProxyGraphicType.Shell:
375
+ this.drawShell(renderer, entities, data);
376
+ break;
377
+ case AcDbProxyGraphicType.Text:
378
+ this.drawText(renderer, entities, data, false);
379
+ break;
380
+ case AcDbProxyGraphicType.UnicodeText:
381
+ this.drawText(renderer, entities, data, true);
382
+ break;
383
+ case AcDbProxyGraphicType.Text2:
384
+ this.drawText2(renderer, entities, data, false);
385
+ break;
386
+ case AcDbProxyGraphicType.UnicodeText2:
387
+ this.drawText2(renderer, entities, data, true);
388
+ break;
389
+ case AcDbProxyGraphicType.Xline:
390
+ this.drawXline(renderer, entities, data, false);
391
+ break;
392
+ case AcDbProxyGraphicType.Ray:
393
+ this.drawXline(renderer, entities, data, true);
394
+ break;
395
+ case AcDbProxyGraphicType.AttributeColor:
396
+ this.readAttributeColor(data);
397
+ break;
398
+ case AcDbProxyGraphicType.AttributeLayer:
399
+ this.readAttributeLayer(data);
400
+ break;
401
+ case AcDbProxyGraphicType.AttributeLinetype:
402
+ this.readAttributeLinetype(data);
403
+ break;
404
+ case AcDbProxyGraphicType.AttributeFill:
405
+ this.readAttributeFill(data);
406
+ break;
407
+ case AcDbProxyGraphicType.AttributeTrueColor:
408
+ this.readAttributeTrueColor(data);
409
+ break;
410
+ case AcDbProxyGraphicType.AttributeLineweight:
411
+ this.readAttributeLineweight(data);
412
+ break;
413
+ case AcDbProxyGraphicType.AttributeLtscale:
414
+ this.readAttributeLtscale(data);
415
+ break;
416
+ case AcDbProxyGraphicType.AttributeThickness:
417
+ this.readAttributeThickness(data);
418
+ break;
419
+ case AcDbProxyGraphicType.PushMatrix:
420
+ this.pushMatrix(data);
421
+ break;
422
+ case AcDbProxyGraphicType.PopMatrix:
423
+ this.popMatrix();
424
+ break;
425
+ default:
426
+ break;
427
+ }
428
+ };
429
+ /**
430
+ * Applies the current proxy-graphic graphics state to renderer traits.
431
+ *
432
+ * @param renderer - Target graphics renderer whose {@link AcGiRenderer.subEntityTraits}
433
+ * are updated in place.
434
+ */
435
+ AcDbProxyGraphic.prototype.applyTraits = function (renderer) {
436
+ var _a;
437
+ var traits = renderer.subEntityTraits;
438
+ traits.layer = this._layer;
439
+ traits.lineTypeScale = this._ltscale;
440
+ traits.thickness = this._thickness;
441
+ traits.lineWeight = this._lineweight;
442
+ if (this._rgbColor != null) {
443
+ traits.rgbColor = this._rgbColor;
444
+ traits.color = new AcCmColor(AcCmColorMethod.ByColor, this._rgbColor);
445
+ }
446
+ else if (this._colorIndex === 256) {
447
+ traits.color = new AcCmColor(AcCmColorMethod.ByLayer);
448
+ traits.rgbColor =
449
+ (_a = AcCmColorUtil.getColorByIndex(7)) !== null && _a !== void 0 ? _a : traits.rgbColor;
450
+ }
451
+ else if (this._colorIndex === 0) {
452
+ traits.color = new AcCmColor(AcCmColorMethod.ByBlock);
453
+ }
454
+ else {
455
+ var rgb = AcCmColorUtil.getColorByIndex(this._colorIndex);
456
+ traits.color = new AcCmColor(AcCmColorMethod.ByACI, this._colorIndex);
457
+ if (rgb != null) {
458
+ traits.rgbColor = rgb;
459
+ }
460
+ }
461
+ traits.lineType = {
462
+ name: this._linetype,
463
+ type: this.resolveLineStyleType(),
464
+ standardFlag: 0,
465
+ description: '',
466
+ totalPatternLength: 0
467
+ };
468
+ };
469
+ /**
470
+ * Maps the current linetype name to a renderer style-type enum value.
471
+ *
472
+ * @returns `'ByLayer'`, `'ByBlock'`, or `'UserSpecified'`.
473
+ */
474
+ AcDbProxyGraphic.prototype.resolveLineStyleType = function () {
475
+ if (this._linetype === ByLayer)
476
+ return 'ByLayer';
477
+ if (this._linetype === ByBlock)
478
+ return 'ByBlock';
479
+ return 'UserSpecified';
480
+ };
481
+ /**
482
+ * Applies the active matrix stack to a point.
483
+ *
484
+ * @param point - Source point in proxy-graphic coordinates.
485
+ * @returns The transformed {@link AcGePoint3d}.
486
+ */
487
+ AcDbProxyGraphic.prototype.transformPoint = function (point) {
488
+ var like = Array.isArray(point) ? vertexTuple(point) : point;
489
+ var transformed = pointFromLike(like);
490
+ if (this._matrices.length > 0) {
491
+ transformed.applyMatrix4(this._matrices[this._matrices.length - 1]);
492
+ }
493
+ return transformed;
494
+ };
495
+ /**
496
+ * Applies the active matrix stack to a direction vector and normalizes it.
497
+ *
498
+ * @param vector - Source vector in proxy-graphic coordinates.
499
+ * @returns The transformed unit vector.
500
+ */
501
+ AcDbProxyGraphic.prototype.transformVector = function (vector) {
502
+ var like = Array.isArray(vector) ? vertexTuple(vector) : vector;
503
+ var transformed = vectorFromLike(like);
504
+ if (this._matrices.length > 0) {
505
+ transformed.transformDirection(this._matrices[this._matrices.length - 1]);
506
+ }
507
+ return transformed.normalize();
508
+ };
509
+ /**
510
+ * Appends a drawable entity to the output list when defined.
511
+ *
512
+ * @param entities - Accumulator for emitted drawable entities.
513
+ * @param entity - Entity returned by the renderer, if any.
514
+ */
515
+ AcDbProxyGraphic.prototype.pushEntity = function (entities, entity) {
516
+ if (entity) {
517
+ entities.push(entity);
518
+ }
519
+ };
520
+ /**
521
+ * Parses an {@link AcDbProxyGraphicType.Extents} chunk.
522
+ *
523
+ * @param data - Chunk payload containing minimum and maximum vertices.
524
+ */
525
+ AcDbProxyGraphic.prototype.readExtents = function (data) {
526
+ var bs = new AcDbProxyGraphicByteStream(data);
527
+ var min = bs.readVertex();
528
+ var max = bs.readVertex();
529
+ this._extents = [
530
+ new AcGePoint3d(min[0], min[1], min[2]),
531
+ new AcGePoint3d(max[0], max[1], max[2])
532
+ ];
533
+ };
534
+ /**
535
+ * Parses an {@link AcDbProxyGraphicType.AttributeColor} chunk.
536
+ *
537
+ * @param data - Chunk payload containing a 32-bit ACI color index.
538
+ */
539
+ AcDbProxyGraphic.prototype.readAttributeColor = function (data) {
540
+ var value = new DataView(data.buffer, data.byteOffset, 4).getUint32(0, true);
541
+ this._rgbColor = undefined;
542
+ this._colorIndex = value > 256 || value < 0 ? 256 : value;
543
+ };
544
+ /**
545
+ * Parses an {@link AcDbProxyGraphicType.AttributeLayer} chunk.
546
+ *
547
+ * @param data - Chunk payload containing a layer-table index.
548
+ */
549
+ AcDbProxyGraphic.prototype.readAttributeLayer = function (data) {
550
+ var index = new DataView(data.buffer, data.byteOffset, 4).getUint32(0, true);
551
+ if (index < this._layers.length) {
552
+ this._layer = this._layers[index];
553
+ }
554
+ };
555
+ /**
556
+ * Parses an {@link AcDbProxyGraphicType.AttributeLinetype} chunk.
557
+ *
558
+ * @param data - Chunk payload containing a linetype-table index.
559
+ */
560
+ AcDbProxyGraphic.prototype.readAttributeLinetype = function (data) {
561
+ var index = new DataView(data.buffer, data.byteOffset, 4).getUint32(0, true);
562
+ if (index + 2 < this._linetypes.length) {
563
+ this._linetype = this._linetypes[index + 2];
564
+ }
565
+ else if (index === 32766) {
566
+ this._linetype = ByBlock;
567
+ }
568
+ else {
569
+ this._linetype = ByLayer;
570
+ }
571
+ };
572
+ /**
573
+ * Parses an {@link AcDbProxyGraphicType.AttributeFill} chunk.
574
+ *
575
+ * @param data - Chunk payload where any non-zero value enables fill.
576
+ */
577
+ AcDbProxyGraphic.prototype.readAttributeFill = function (data) {
578
+ this._fill = new DataView(data.buffer, data.byteOffset, 4).getUint32(0, true) !== 0;
579
+ };
580
+ /**
581
+ * Parses an {@link AcDbProxyGraphicType.AttributeTrueColor} chunk.
582
+ *
583
+ * @param data - Chunk payload containing a packed true-color dword.
584
+ */
585
+ AcDbProxyGraphic.prototype.readAttributeTrueColor = function (data) {
586
+ var raw = new DataView(data.buffer, data.byteOffset, 4).getUint32(0, true);
587
+ var decoded = decodeProxyGraphicRawColor(raw);
588
+ this._rgbColor = decoded.rgb;
589
+ if (decoded.colorIndex != null) {
590
+ this._colorIndex = decoded.colorIndex;
591
+ }
592
+ };
593
+ /**
594
+ * Parses an {@link AcDbProxyGraphicType.AttributeLineweight} chunk.
595
+ *
596
+ * @param data - Chunk payload containing a raw lineweight value.
597
+ */
598
+ AcDbProxyGraphic.prototype.readAttributeLineweight = function (data) {
599
+ var lw = new DataView(data.buffer, data.byteOffset, 4).getUint32(0, true);
600
+ if (lw > MAX_VALID_LINEWEIGHT) {
601
+ this._lineweight = (lw - 0x100000000);
602
+ }
603
+ else {
604
+ this._lineweight = lw;
605
+ }
606
+ };
607
+ /**
608
+ * Parses an {@link AcDbProxyGraphicType.AttributeLtscale} chunk.
609
+ *
610
+ * @param data - Chunk payload containing a little-endian double.
611
+ */
612
+ AcDbProxyGraphic.prototype.readAttributeLtscale = function (data) {
613
+ this._ltscale = new DataView(data.buffer, data.byteOffset, 8).getFloat64(0, true);
614
+ };
615
+ /**
616
+ * Parses an {@link AcDbProxyGraphicType.AttributeThickness} chunk.
617
+ *
618
+ * @param data - Chunk payload containing a little-endian double.
619
+ */
620
+ AcDbProxyGraphic.prototype.readAttributeThickness = function (data) {
621
+ this._thickness = new DataView(data.buffer, data.byteOffset, 8).getFloat64(0, true);
622
+ };
623
+ /**
624
+ * Parses a {@link AcDbProxyGraphicType.PushMatrix} chunk and pushes the
625
+ * decoded matrix onto the transform stack.
626
+ *
627
+ * @param data - Chunk payload containing 16 little-endian doubles.
628
+ */
629
+ AcDbProxyGraphic.prototype.pushMatrix = function (data) {
630
+ var values = new Float64Array(data.buffer, data.byteOffset, 16);
631
+ var matrix = new AcGeMatrix3d().fromArray(Array.from(values));
632
+ matrix.transpose();
633
+ this._matrices.push(matrix);
634
+ };
635
+ /**
636
+ * Pops the top matrix from the transform stack when the stack is non-empty.
637
+ */
638
+ AcDbProxyGraphic.prototype.popMatrix = function () {
639
+ if (this._matrices.length > 0) {
640
+ this._matrices.pop();
641
+ }
642
+ };
643
+ /**
644
+ * Reads a vertex list from a polyline-style chunk.
645
+ *
646
+ * @param data - Chunk payload beginning with a vertex count.
647
+ * @param loadNormal - When `true`, the final vertex is interpreted as a normal vector.
648
+ * @returns Decoded vertices and the extracted normal (defaults to Z axis).
649
+ */
650
+ AcDbProxyGraphic.prototype.loadVertices = function (data, loadNormal) {
651
+ var bs = new AcDbProxyGraphicByteStream(data);
652
+ var count = bs.readLong();
653
+ if (loadNormal) {
654
+ count += 1;
655
+ }
656
+ var vertices = [];
657
+ while (count > 0) {
658
+ var _a = __read(bs.readVertex(), 3), x = _a[0], y = _a[1], z = _a[2];
659
+ vertices.push(this.transformPoint({ x: x, y: y, z: z }));
660
+ count -= 1;
661
+ }
662
+ var normal = Z_AXIS;
663
+ if (loadNormal && vertices.length > 0) {
664
+ normal = vectorFromLike(vertices.pop());
665
+ }
666
+ return { vertices: vertices, normal: normal };
667
+ };
668
+ /**
669
+ * Renders an {@link AcDbProxyGraphicType.Circle} chunk.
670
+ *
671
+ * @param renderer - Target graphics renderer.
672
+ * @param entities - Accumulator for emitted drawable entities.
673
+ * @param data - Chunk payload.
674
+ */
675
+ AcDbProxyGraphic.prototype.drawCircle = function (renderer, entities, data) {
676
+ var bs = new AcDbProxyGraphicByteStream(data);
677
+ var center = bs.readVertex();
678
+ var radius = bs.readFloat();
679
+ var normalVec = this.transformVector(bs.readVertex());
680
+ var centerPoint = pointFromLike({ x: center[0], y: center[1], z: center[2] });
681
+ if (!normalVec.equals(Z_AXIS)) {
682
+ centerPoint = transformWcsPointToOcs(centerPoint, normalVec);
683
+ }
684
+ centerPoint = this.transformPoint(centerPoint);
685
+ var refVec = getOcsReferenceVector(normalVec);
686
+ var arc = new AcGeCircArc3d(transformOcsPointToWcs(centerPoint, normalVec), radius, 0, TAU, normalVec, refVec);
687
+ this.applyTraits(renderer);
688
+ this.pushEntity(entities, renderer.circularArc(arc));
689
+ };
690
+ /**
691
+ * Renders an {@link AcDbProxyGraphicType.Circle3P} chunk.
692
+ *
693
+ * @param renderer - Target graphics renderer.
694
+ * @param entities - Accumulator for emitted drawable entities.
695
+ * @param data - Chunk payload containing three perimeter points.
696
+ */
697
+ AcDbProxyGraphic.prototype.drawCircle3P = function (renderer, entities, data) {
698
+ var bs = new AcDbProxyGraphicByteStream(data);
699
+ var p1 = this.transformPoint(bs.readVertex());
700
+ var p2 = this.transformPoint(bs.readVertex());
701
+ var p3 = this.transformPoint(bs.readVertex());
702
+ var center = AcGeCircArc3d.computeCenterPoint(p1, p2, p3);
703
+ if (!center)
704
+ return;
705
+ var radius = center.distanceTo(p1);
706
+ var arc = new AcGeCircArc3d(center, radius, 0, TAU, Z_AXIS);
707
+ this.applyTraits(renderer);
708
+ this.pushEntity(entities, renderer.circularArc(arc));
709
+ };
710
+ /**
711
+ * Renders an {@link AcDbProxyGraphicType.CircularArc} chunk.
712
+ *
713
+ * @param renderer - Target graphics renderer.
714
+ * @param entities - Accumulator for emitted drawable entities.
715
+ * @param data - Chunk payload.
716
+ */
717
+ AcDbProxyGraphic.prototype.drawCircularArc = function (renderer, entities, data) {
718
+ var bs = new AcDbProxyGraphicByteStream(data);
719
+ var center = bs.readVertex();
720
+ var radius = bs.readFloat();
721
+ var normal = bs.readVertex();
722
+ var startVec = bs.readVertex();
723
+ var sweepAngle = bs.readFloat();
724
+ var normalVec = this.transformVector(normal);
725
+ var centerWcs = pointFromLike({
726
+ x: center[0],
727
+ y: center[1],
728
+ z: center[2]
729
+ });
730
+ var refVec = this.transformVector(startVec).normalize();
731
+ var startAngle = 0;
732
+ var endAngle = sweepAngle;
733
+ var arc = new AcGeCircArc3d(this.transformPoint(centerWcs), radius, startAngle, endAngle, normalVec, refVec);
734
+ this.applyTraits(renderer);
735
+ this.pushEntity(entities, renderer.circularArc(arc));
736
+ };
737
+ /**
738
+ * Renders an {@link AcDbProxyGraphicType.CircularArc3P} chunk.
739
+ *
740
+ * @param renderer - Target graphics renderer.
741
+ * @param entities - Accumulator for emitted drawable entities.
742
+ * @param data - Chunk payload containing start, middle, and end points.
743
+ */
744
+ AcDbProxyGraphic.prototype.drawCircularArc3P = function (renderer, entities, data) {
745
+ var bs = new AcDbProxyGraphicByteStream(data);
746
+ var p1 = this.transformPoint(bs.readVertex());
747
+ var p2 = this.transformPoint(bs.readVertex());
748
+ var p3 = this.transformPoint(bs.readVertex());
749
+ var center = AcGeCircArc3d.computeCenterPoint(p1, p3, p2);
750
+ if (!center)
751
+ return;
752
+ var radius = center.distanceTo(p1);
753
+ var startAngle = getOcsAngle(center, p1, Z_AXIS);
754
+ var endAngle = getOcsAngle(center, p3, Z_AXIS);
755
+ var arc = new AcGeCircArc3d(center, radius, startAngle, endAngle, Z_AXIS);
756
+ this.applyTraits(renderer);
757
+ this.pushEntity(entities, renderer.circularArc(arc));
758
+ };
759
+ /**
760
+ * Renders an {@link AcDbProxyGraphicType.EllipticArc} chunk.
761
+ *
762
+ * @param renderer - Target graphics renderer.
763
+ * @param entities - Accumulator for emitted drawable entities.
764
+ * @param data - Chunk payload.
765
+ */
766
+ AcDbProxyGraphic.prototype.drawEllipticArc = function (renderer, entities, data) {
767
+ var bs = new AcDbProxyGraphicByteStream(data);
768
+ var center = this.transformPoint(bs.readVertex());
769
+ var extrusion = this.transformVector(bs.readVertex());
770
+ var majorAxisLength = bs.readFloat();
771
+ var minorAxisLength = bs.readFloat();
772
+ var startParam = bs.readFloat();
773
+ var endParam = bs.readFloat();
774
+ var majorAxisAngle = bs.readFloat();
775
+ var majorAxis = transformOcsPointToWcs({
776
+ x: Math.cos(majorAxisAngle) * majorAxisLength,
777
+ y: Math.sin(majorAxisAngle) * majorAxisLength,
778
+ z: 0
779
+ }, extrusion);
780
+ var ellipse = new AcGeEllipseArc3d(center, extrusion, majorAxis, majorAxisLength, minorAxisLength, startParam, endParam);
781
+ this.applyTraits(renderer);
782
+ this.pushEntity(entities, renderer.ellipticalArc(ellipse));
783
+ };
784
+ /**
785
+ * Renders an {@link AcDbProxyGraphicType.Polyline} or
786
+ * {@link AcDbProxyGraphicType.PolylineWithNormals} chunk.
787
+ *
788
+ * A single vertex is rendered as a point entity using database `pdmode` and
789
+ * `pdsize` settings when available.
790
+ *
791
+ * @param renderer - Target graphics renderer.
792
+ * @param entities - Accumulator for emitted drawable entities.
793
+ * @param data - Chunk payload.
794
+ * @param _loadNormal - When `true`, the final vertex stores the polyline normal.
795
+ */
796
+ AcDbProxyGraphic.prototype.drawPolyline = function (renderer, entities, data, _loadNormal) {
797
+ var _a, _b, _c, _d;
798
+ var vertices = this.loadVertices(data, _loadNormal).vertices;
799
+ if (vertices.length === 0)
800
+ return;
801
+ if (vertices.length === 1) {
802
+ this.applyTraits(renderer);
803
+ var pdmode = (_b = (_a = this._database) === null || _a === void 0 ? void 0 : _a.pdmode) !== null && _b !== void 0 ? _b : 0;
804
+ var pdsize = (_d = (_c = this._database) === null || _c === void 0 ? void 0 : _c.pdsize) !== null && _d !== void 0 ? _d : 0;
805
+ this.pushEntity(entities, renderer.point(vertices[0], { displayMode: pdmode, displaySize: pdsize }));
806
+ return;
807
+ }
808
+ this.applyTraits(renderer);
809
+ this.pushEntity(entities, renderer.lines(vertices));
810
+ };
811
+ /**
812
+ * Renders an {@link AcDbProxyGraphicType.Polygon} chunk.
813
+ *
814
+ * When {@link AcDbProxyGraphicType.AttributeFill} was set for this polygon, a
815
+ * solid filled area is emitted; otherwise the polygon outline is drawn as a
816
+ * closed polyline.
817
+ *
818
+ * @param renderer - Target graphics renderer.
819
+ * @param entities - Accumulator for emitted drawable entities.
820
+ * @param data - Chunk payload.
821
+ */
822
+ AcDbProxyGraphic.prototype.drawPolygon = function (renderer, entities, data) {
823
+ var vertices = this.loadVertices(data, false).vertices;
824
+ if (vertices.length < 2)
825
+ return;
826
+ if (this._fill) {
827
+ var polyline = new AcGePolyline2d(vertices.map(function (vertex) { return ({ x: vertex.x, y: vertex.y }); }), true);
828
+ var area = new AcGeArea2d();
829
+ area.add(polyline);
830
+ var traits = renderer.subEntityTraits;
831
+ traits.fillType = {
832
+ solidFill: true,
833
+ patternAngle: 0,
834
+ definitionLines: []
835
+ };
836
+ traits.drawOrder = -1;
837
+ this.applyTraits(renderer);
838
+ this.pushEntity(entities, renderer.area(area));
839
+ return;
840
+ }
841
+ var closed = __spreadArray(__spreadArray([], __read(vertices), false), [vertices[0]], false);
842
+ this.applyTraits(renderer);
843
+ this.pushEntity(entities, renderer.lines(closed));
844
+ };
845
+ /**
846
+ * Renders an {@link AcDbProxyGraphicType.LwPolyline} chunk.
847
+ *
848
+ * Bulge values are consumed but arc segments are not yet expanded; the result
849
+ * is a vertex polyline in the current transform stack.
850
+ *
851
+ * @param renderer - Target graphics renderer.
852
+ * @param entities - Accumulator for emitted drawable entities.
853
+ * @param data - Bit-packed chunk payload.
854
+ */
855
+ AcDbProxyGraphic.prototype.drawLwPolyline = function (renderer, entities, data) {
856
+ var bs = new AcDbProxyGraphicBitStream(data, this._dxfversion, this._encoding);
857
+ var elevation = 0;
858
+ var isClosed = false;
859
+ bs.readUnsignedLong();
860
+ var flag = bs.readBitShort();
861
+ if (flag & 8) {
862
+ elevation = bs.readBitDouble();
863
+ }
864
+ if (flag & 512) {
865
+ isClosed = true;
866
+ }
867
+ var numPoints = bs.readBitLong();
868
+ if (numPoints <= 0)
869
+ return;
870
+ var numBulges = flag & 16 ? bs.readBitLong() : 0;
871
+ if (this._dxfversion >= 'AC1024') {
872
+ if (flag & 1024) {
873
+ bs.readBitLong();
874
+ }
875
+ if (flag & 32) {
876
+ bs.readBitLong();
877
+ }
878
+ }
879
+ var rawVertices = bs.readRawDouble(2);
880
+ var vertices = [
881
+ this.transformPoint({ x: rawVertices[0], y: rawVertices[1], z: elevation })
882
+ ];
883
+ var prev = rawVertices;
884
+ for (var i = 1; i < numPoints; i++) {
885
+ var x = bs.readBitDoubleDefault(1, prev[0]);
886
+ var y = bs.readBitDoubleDefault(1, prev[1]);
887
+ prev = [x, y];
888
+ vertices.push(this.transformPoint({ x: x, y: y, z: elevation }));
889
+ }
890
+ for (var i = 0; i < numBulges; i++) {
891
+ bs.readBitDouble();
892
+ }
893
+ if (isClosed && vertices.length > 1) {
894
+ vertices.push(vertices[0].clone());
895
+ }
896
+ this.applyTraits(renderer);
897
+ this.pushEntity(entities, renderer.lines(vertices));
898
+ };
899
+ /**
900
+ * Renders an {@link AcDbProxyGraphicType.Shell} chunk as face edge segments.
901
+ *
902
+ * @param renderer - Target graphics renderer.
903
+ * @param entities - Accumulator for emitted drawable entities.
904
+ * @param data - Chunk payload containing vertices and face index lists.
905
+ */
906
+ AcDbProxyGraphic.prototype.drawShell = function (renderer, entities, data) {
907
+ var bs = new AcDbProxyGraphicByteStream(data);
908
+ var totalVertexCount = bs.readLong();
909
+ var vertices = [];
910
+ for (var i = 0; i < totalVertexCount; i++) {
911
+ var _a = __read(bs.readVertex(), 3), x = _a[0], y = _a[1], z = _a[2];
912
+ vertices.push(this.transformPoint({ x: x, y: y, z: z }));
913
+ }
914
+ var faceEntryCount = bs.readLong();
915
+ var lines = [];
916
+ var readCount = 0;
917
+ while (readCount < faceEntryCount) {
918
+ var edgeCount = Math.abs(bs.readSignedLong());
919
+ readCount += 1 + edgeCount;
920
+ var faceIndices = [];
921
+ for (var i = 0; i < edgeCount; i++) {
922
+ faceIndices.push(bs.readLong());
923
+ }
924
+ var faceVertices = faceIndices
925
+ .map(function (index) { return vertices[index]; })
926
+ .filter(Boolean);
927
+ if (faceVertices.length >= 3) {
928
+ for (var i = 0; i < faceVertices.length; i++) {
929
+ lines.push(faceVertices[i]);
930
+ lines.push(faceVertices[(i + 1) % faceVertices.length]);
931
+ }
932
+ }
933
+ }
934
+ if (lines.length === 0)
935
+ return;
936
+ this.applyTraits(renderer);
937
+ this.pushEntity(entities, renderer.lines(lines));
938
+ };
939
+ /**
940
+ * Renders an {@link AcDbProxyGraphicType.Text} or
941
+ * {@link AcDbProxyGraphicType.UnicodeText} chunk.
942
+ *
943
+ * @param renderer - Target graphics renderer.
944
+ * @param entities - Accumulator for emitted drawable entities.
945
+ * @param data - Chunk payload.
946
+ * @param unicode - When `true`, text is decoded as UTF-16LE.
947
+ */
948
+ AcDbProxyGraphic.prototype.drawText = function (renderer, entities, data, unicode) {
949
+ var bs = new AcDbProxyGraphicByteStream(data);
950
+ var insert = this.transformPoint(bs.readVertex());
951
+ var normal = this.transformVector(bs.readVertex());
952
+ var textDirection = this.transformVector(bs.readVertex());
953
+ var _a = __read(bs.readStruct([
954
+ 8,
955
+ 8,
956
+ 8
957
+ ]), 3), height = _a[0], widthFactor = _a[1], obliqueAngle = _a[2];
958
+ var text = unicode
959
+ ? bs.readPaddedUnicodeString()
960
+ : bs.readPaddedString(this._encoding);
961
+ this.drawTextPrimitive(renderer, entities, {
962
+ insert: insert,
963
+ normal: normal,
964
+ textDirection: textDirection,
965
+ text: text,
966
+ height: height,
967
+ widthFactor: widthFactor,
968
+ obliqueAngle: obliqueAngle
969
+ });
970
+ };
971
+ /**
972
+ * Renders an {@link AcDbProxyGraphicType.Text2} or
973
+ * {@link AcDbProxyGraphicType.UnicodeText2} chunk.
974
+ *
975
+ * @param renderer - Target graphics renderer.
976
+ * @param entities - Accumulator for emitted drawable entities.
977
+ * @param data - Chunk payload with extended text header fields.
978
+ * @param unicode - When `true`, text is decoded as UTF-16LE.
979
+ */
980
+ AcDbProxyGraphic.prototype.drawText2 = function (renderer, entities, data, unicode) {
981
+ var bs = new AcDbProxyGraphicByteStream(data);
982
+ var insert = this.transformPoint(bs.readVertex());
983
+ var normal = this.transformVector(bs.readVertex());
984
+ var textDirection = this.transformVector(bs.readVertex());
985
+ var text = unicode
986
+ ? bs.readPaddedUnicodeString()
987
+ : bs.readPaddedString(this._encoding);
988
+ bs.readSignedLong();
989
+ bs.readSignedLong();
990
+ var _a = __read(bs.readStruct([
991
+ 8,
992
+ 8,
993
+ 8
994
+ ]), 3), height = _a[0], widthFactor = _a[1], obliqueAngle = _a[2];
995
+ bs.readFloat();
996
+ this.drawTextPrimitive(renderer, entities, {
997
+ insert: insert,
998
+ normal: normal,
999
+ textDirection: textDirection,
1000
+ text: text,
1001
+ height: height,
1002
+ widthFactor: widthFactor,
1003
+ obliqueAngle: obliqueAngle
1004
+ });
1005
+ };
1006
+ /**
1007
+ * Emits a proxy-graphic text command as an {@link AcGiRenderer.mtext} entity.
1008
+ *
1009
+ * @param renderer - Target graphics renderer.
1010
+ * @param entities - Accumulator for emitted drawable entities.
1011
+ * @param options - Parsed text placement and formatting values.
1012
+ */
1013
+ AcDbProxyGraphic.prototype.drawTextPrimitive = function (renderer, entities, options) {
1014
+ var rotation = Math.atan2(options.textDirection.y, options.textDirection.x);
1015
+ var mtextData = {
1016
+ text: options.text,
1017
+ height: options.height,
1018
+ width: Infinity,
1019
+ widthFactor: options.widthFactor,
1020
+ position: options.insert,
1021
+ rotation: (rotation * 180) / Math.PI,
1022
+ drawingDirection: AcGiMTextFlowDirection.BOTTOM_TO_TOP,
1023
+ attachmentPoint: AcGiMTextAttachmentPoint.BaselineLeft
1024
+ };
1025
+ var style = {
1026
+ name: DEFAULT_TEXT_STYLE,
1027
+ standardFlag: 0,
1028
+ fixedTextHeight: 0,
1029
+ widthFactor: options.widthFactor,
1030
+ obliqueAngle: (options.obliqueAngle * 180) / Math.PI,
1031
+ textGenerationFlag: 0,
1032
+ lastHeight: options.height,
1033
+ font: 'txt',
1034
+ bigFont: ''
1035
+ };
1036
+ this.applyTraits(renderer);
1037
+ this.pushEntity(entities, renderer.mtext(mtextData, style));
1038
+ };
1039
+ /**
1040
+ * Renders an {@link AcDbProxyGraphicType.Xline} or
1041
+ * {@link AcDbProxyGraphicType.Ray} chunk as a long screen-space segment.
1042
+ *
1043
+ * @param renderer - Target graphics renderer.
1044
+ * @param entities - Accumulator for emitted drawable entities.
1045
+ * @param data - Chunk payload containing two defining points.
1046
+ * @param isRay - When `true`, the line starts at the first point; otherwise it
1047
+ * extends infinitely in both directions.
1048
+ */
1049
+ AcDbProxyGraphic.prototype.drawXline = function (renderer, entities, data, isRay) {
1050
+ var bs = new AcDbProxyGraphicByteStream(data);
1051
+ var start = this.transformPoint(bs.readVertex());
1052
+ var other = this.transformPoint(bs.readVertex());
1053
+ var direction = new AcGeVector3d().subVectors(other, start);
1054
+ if (direction.lengthSq() === 0)
1055
+ return;
1056
+ var far = 1e6;
1057
+ var end = isRay
1058
+ ? start.clone().add(direction.normalize().multiplyScalar(far))
1059
+ : start.clone().sub(direction.normalize().multiplyScalar(far));
1060
+ var farEnd = other.clone().add(direction.normalize().multiplyScalar(far));
1061
+ this.applyTraits(renderer);
1062
+ this.pushEntity(entities, renderer.lines([end, farEnd]));
1063
+ };
1064
+ return AcDbProxyGraphic;
1065
+ }());
1066
+ export { AcDbProxyGraphic };
1067
+ /**
1068
+ * Loads proxy-graphic bytes from DXF group codes **160** and **310**.
1069
+ *
1070
+ * Hex chunks are concatenated in order and optionally truncated to the declared
1071
+ * byte length from group code **160**.
1072
+ *
1073
+ * @param length - Expected byte length from group code **160**.
1074
+ * @param hexChunks - One or more hexadecimal strings from group code **310**.
1075
+ * @returns Decoded bytes, or `undefined` when no hex chunks are supplied.
1076
+ */
1077
+ export function loadAcDbProxyGraphicFromDxf(length, hexChunks) {
1078
+ var e_1, _a;
1079
+ if (!(hexChunks === null || hexChunks === void 0 ? void 0 : hexChunks.length)) {
1080
+ return undefined;
1081
+ }
1082
+ var bytes = new Uint8Array(hexChunks.reduce(function (sum, chunk) { return sum + Math.floor(chunk.length / 2); }, 0));
1083
+ var offset = 0;
1084
+ try {
1085
+ for (var hexChunks_1 = __values(hexChunks), hexChunks_1_1 = hexChunks_1.next(); !hexChunks_1_1.done; hexChunks_1_1 = hexChunks_1.next()) {
1086
+ var chunk = hexChunks_1_1.value;
1087
+ for (var i = 0; i < chunk.length; i += 2) {
1088
+ bytes[offset++] = parseInt(chunk.slice(i, i + 2), 16);
1089
+ }
1090
+ }
1091
+ }
1092
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1093
+ finally {
1094
+ try {
1095
+ if (hexChunks_1_1 && !hexChunks_1_1.done && (_a = hexChunks_1.return)) _a.call(hexChunks_1);
1096
+ }
1097
+ finally { if (e_1) throw e_1.error; }
1098
+ }
1099
+ if (length != null && length > 0 && bytes.length >= length) {
1100
+ return bytes.subarray(0, length);
1101
+ }
1102
+ return bytes;
1103
+ }
1104
+ //# sourceMappingURL=AcDbProxyGraphic.js.map