@mlightcad/pdf-renderer 1.7.1
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.
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/index.js +40188 -0
- package/dist/index.umd.cjs +159 -0
- package/lib/AcPdfExport.d.ts +10 -0
- package/lib/AcPdfExport.d.ts.map +1 -0
- package/lib/AcPdfExport.js +354 -0
- package/lib/AcPdfExport.js.map +1 -0
- package/lib/AcPdfExportOptions.d.ts +105 -0
- package/lib/AcPdfExportOptions.d.ts.map +1 -0
- package/lib/AcPdfExportOptions.js +2 -0
- package/lib/AcPdfExportOptions.js.map +1 -0
- package/lib/AcPdfUnits.d.ts +17 -0
- package/lib/AcPdfUnits.d.ts.map +1 -0
- package/lib/AcPdfUnits.js +70 -0
- package/lib/AcPdfUnits.js.map +1 -0
- package/lib/hatch/AcPdfGradient.d.ts +43 -0
- package/lib/hatch/AcPdfGradient.d.ts.map +1 -0
- package/lib/hatch/AcPdfGradient.js +222 -0
- package/lib/hatch/AcPdfGradient.js.map +1 -0
- package/lib/hatch/AcPdfHatchTessellator.d.ts +24 -0
- package/lib/hatch/AcPdfHatchTessellator.d.ts.map +1 -0
- package/lib/hatch/AcPdfHatchTessellator.js +362 -0
- package/lib/hatch/AcPdfHatchTessellator.js.map +1 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/linetype/AcPdfLineTypeStroker.d.ts +36 -0
- package/lib/linetype/AcPdfLineTypeStroker.d.ts.map +1 -0
- package/lib/linetype/AcPdfLineTypeStroker.js +160 -0
- package/lib/linetype/AcPdfLineTypeStroker.js.map +1 -0
- package/lib/pdf/AcPdfContentWriter.d.ts +197 -0
- package/lib/pdf/AcPdfContentWriter.d.ts.map +1 -0
- package/lib/pdf/AcPdfContentWriter.js +977 -0
- package/lib/pdf/AcPdfContentWriter.js.map +1 -0
- package/lib/pdf/AcPdfDocumentWriter.d.ts +66 -0
- package/lib/pdf/AcPdfDocumentWriter.d.ts.map +1 -0
- package/lib/pdf/AcPdfDocumentWriter.js +360 -0
- package/lib/pdf/AcPdfDocumentWriter.js.map +1 -0
- package/lib/pdf/AcPdfEffectiveLayer.d.ts +7 -0
- package/lib/pdf/AcPdfEffectiveLayer.d.ts.map +1 -0
- package/lib/pdf/AcPdfEffectiveLayer.js +13 -0
- package/lib/pdf/AcPdfEffectiveLayer.js.map +1 -0
- package/lib/pdf/AcPdfFontManager.d.ts +95 -0
- package/lib/pdf/AcPdfFontManager.d.ts.map +1 -0
- package/lib/pdf/AcPdfFontManager.js +517 -0
- package/lib/pdf/AcPdfFontManager.js.map +1 -0
- package/lib/pdf/AcPdfMarkedContent.d.ts +14 -0
- package/lib/pdf/AcPdfMarkedContent.d.ts.map +1 -0
- package/lib/pdf/AcPdfMarkedContent.js +28 -0
- package/lib/pdf/AcPdfMarkedContent.js.map +1 -0
- package/lib/pdf/AcPdfOcgManager.d.ts +20 -0
- package/lib/pdf/AcPdfOcgManager.d.ts.map +1 -0
- package/lib/pdf/AcPdfOcgManager.js +147 -0
- package/lib/pdf/AcPdfOcgManager.js.map +1 -0
- package/lib/pdf/AcPdfPageLayout.d.ts +47 -0
- package/lib/pdf/AcPdfPageLayout.d.ts.map +1 -0
- package/lib/pdf/AcPdfPageLayout.js +79 -0
- package/lib/pdf/AcPdfPageLayout.js.map +1 -0
- package/lib/renderer/AcPdfEntity.d.ts +96 -0
- package/lib/renderer/AcPdfEntity.d.ts.map +1 -0
- package/lib/renderer/AcPdfEntity.js +661 -0
- package/lib/renderer/AcPdfEntity.js.map +1 -0
- package/lib/renderer/AcPdfGroup.d.ts +9 -0
- package/lib/renderer/AcPdfGroup.d.ts.map +1 -0
- package/lib/renderer/AcPdfGroup.js +65 -0
- package/lib/renderer/AcPdfGroup.js.map +1 -0
- package/lib/renderer/AcPdfMTextParser.d.ts +46 -0
- package/lib/renderer/AcPdfMTextParser.d.ts.map +1 -0
- package/lib/renderer/AcPdfMTextParser.js +225 -0
- package/lib/renderer/AcPdfMTextParser.js.map +1 -0
- package/lib/renderer/AcPdfMatrixUtil.d.ts +23 -0
- package/lib/renderer/AcPdfMatrixUtil.d.ts.map +1 -0
- package/lib/renderer/AcPdfMatrixUtil.js +85 -0
- package/lib/renderer/AcPdfMatrixUtil.js.map +1 -0
- package/lib/renderer/AcPdfRenderer.d.ts +139 -0
- package/lib/renderer/AcPdfRenderer.d.ts.map +1 -0
- package/lib/renderer/AcPdfRenderer.js +1188 -0
- package/lib/renderer/AcPdfRenderer.js.map +1 -0
- package/lib/renderer/AcPdfStyle.d.ts +132 -0
- package/lib/renderer/AcPdfStyle.d.ts.map +1 -0
- package/lib/renderer/AcPdfStyle.js +8 -0
- package/lib/renderer/AcPdfStyle.js.map +1 -0
- package/lib/renderer/AcPdfStyleUtil.d.ts +49 -0
- package/lib/renderer/AcPdfStyleUtil.d.ts.map +1 -0
- package/lib/renderer/AcPdfStyleUtil.js +140 -0
- package/lib/renderer/AcPdfStyleUtil.js.map +1 -0
- package/lib/renderer/AcPdfTextLayout.d.ts +103 -0
- package/lib/renderer/AcPdfTextLayout.d.ts.map +1 -0
- package/lib/renderer/AcPdfTextLayout.js +539 -0
- package/lib/renderer/AcPdfTextLayout.js.map +1 -0
- package/lib/text/AcPdfGlyphProvider.d.ts +52 -0
- package/lib/text/AcPdfGlyphProvider.d.ts.map +1 -0
- package/lib/text/AcPdfGlyphProvider.js +2 -0
- package/lib/text/AcPdfGlyphProvider.js.map +1 -0
- package/lib/viewport/AcPdfPaperSpaceExport.d.ts +28 -0
- package/lib/viewport/AcPdfPaperSpaceExport.d.ts.map +1 -0
- package/lib/viewport/AcPdfPaperSpaceExport.js +129 -0
- package/lib/viewport/AcPdfPaperSpaceExport.js.map +1 -0
- package/lib/viewport/AcPdfPaperViewport.d.ts +42 -0
- package/lib/viewport/AcPdfPaperViewport.d.ts.map +1 -0
- package/lib/viewport/AcPdfPaperViewport.js +80 -0
- package/lib/viewport/AcPdfPaperViewport.js.map +1 -0
- package/lib/viewport/AcPdfViewportContent.d.ts +37 -0
- package/lib/viewport/AcPdfViewportContent.d.ts.map +1 -0
- package/lib/viewport/AcPdfViewportContent.js +163 -0
- package/lib/viewport/AcPdfViewportContent.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __values = (this && this.__values) || function(o) {
|
|
13
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
14
|
+
if (m) return m.call(o);
|
|
15
|
+
if (o && typeof o.length === "number") return {
|
|
16
|
+
next: function () {
|
|
17
|
+
if (o && i >= o.length) o = void 0;
|
|
18
|
+
return { value: o && o[i++], done: !o };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
22
|
+
};
|
|
23
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
24
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
25
|
+
if (!m) return o;
|
|
26
|
+
var i = m.call(o), r, ar = [], e;
|
|
27
|
+
try {
|
|
28
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
29
|
+
}
|
|
30
|
+
catch (error) { e = { error: error }; }
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
34
|
+
}
|
|
35
|
+
finally { if (e) throw e.error; }
|
|
36
|
+
}
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
40
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
41
|
+
if (ar || !(i in from)) {
|
|
42
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
43
|
+
ar[i] = from[i];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
47
|
+
};
|
|
48
|
+
import { AcGeBox2d } from '@mlightcad/data-model';
|
|
49
|
+
import { effectivePdfLayer } from '../pdf/AcPdfEffectiveLayer';
|
|
50
|
+
import { AcPdfMatrixUtil } from './AcPdfMatrixUtil';
|
|
51
|
+
/**
|
|
52
|
+
* Drawable node produced by {@link AcPdfRenderer}.
|
|
53
|
+
*/
|
|
54
|
+
var AcPdfEntity = /** @class */ (function () {
|
|
55
|
+
function AcPdfEntity() {
|
|
56
|
+
this._objectId = '';
|
|
57
|
+
this._ownerId = '';
|
|
58
|
+
this._layerName = '';
|
|
59
|
+
this._visible = true;
|
|
60
|
+
this._userData = {};
|
|
61
|
+
this._box = new AcGeBox2d();
|
|
62
|
+
this._ops = [];
|
|
63
|
+
this._children = [];
|
|
64
|
+
this._drawOrder = 0;
|
|
65
|
+
this._entityType = '';
|
|
66
|
+
}
|
|
67
|
+
Object.defineProperty(AcPdfEntity.prototype, "box", {
|
|
68
|
+
get: function () {
|
|
69
|
+
return this._box;
|
|
70
|
+
},
|
|
71
|
+
set: function (value) {
|
|
72
|
+
this._box.copy(value);
|
|
73
|
+
},
|
|
74
|
+
enumerable: false,
|
|
75
|
+
configurable: true
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(AcPdfEntity.prototype, "drawOrder", {
|
|
78
|
+
get: function () {
|
|
79
|
+
return this._drawOrder;
|
|
80
|
+
},
|
|
81
|
+
set: function (value) {
|
|
82
|
+
this._drawOrder = value;
|
|
83
|
+
},
|
|
84
|
+
enumerable: false,
|
|
85
|
+
configurable: true
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(AcPdfEntity.prototype, "objectId", {
|
|
88
|
+
get: function () {
|
|
89
|
+
return this._objectId;
|
|
90
|
+
},
|
|
91
|
+
set: function (value) {
|
|
92
|
+
this._objectId = value;
|
|
93
|
+
},
|
|
94
|
+
enumerable: false,
|
|
95
|
+
configurable: true
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(AcPdfEntity.prototype, "ownerId", {
|
|
98
|
+
get: function () {
|
|
99
|
+
return this._ownerId;
|
|
100
|
+
},
|
|
101
|
+
set: function (value) {
|
|
102
|
+
this._ownerId = value;
|
|
103
|
+
},
|
|
104
|
+
enumerable: false,
|
|
105
|
+
configurable: true
|
|
106
|
+
});
|
|
107
|
+
Object.defineProperty(AcPdfEntity.prototype, "layerName", {
|
|
108
|
+
get: function () {
|
|
109
|
+
return this._layerName;
|
|
110
|
+
},
|
|
111
|
+
set: function (value) {
|
|
112
|
+
this._layerName = value;
|
|
113
|
+
},
|
|
114
|
+
enumerable: false,
|
|
115
|
+
configurable: true
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(AcPdfEntity.prototype, "entityType", {
|
|
118
|
+
get: function () {
|
|
119
|
+
return this._entityType;
|
|
120
|
+
},
|
|
121
|
+
set: function (value) {
|
|
122
|
+
this._entityType = value;
|
|
123
|
+
},
|
|
124
|
+
enumerable: false,
|
|
125
|
+
configurable: true
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(AcPdfEntity.prototype, "insertName", {
|
|
128
|
+
get: function () {
|
|
129
|
+
return this._insertName;
|
|
130
|
+
},
|
|
131
|
+
set: function (value) {
|
|
132
|
+
this._insertName = value;
|
|
133
|
+
},
|
|
134
|
+
enumerable: false,
|
|
135
|
+
configurable: true
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(AcPdfEntity.prototype, "actualText", {
|
|
138
|
+
get: function () {
|
|
139
|
+
return this._actualText;
|
|
140
|
+
},
|
|
141
|
+
set: function (value) {
|
|
142
|
+
this._actualText = value;
|
|
143
|
+
},
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: true
|
|
146
|
+
});
|
|
147
|
+
Object.defineProperty(AcPdfEntity.prototype, "clipBox", {
|
|
148
|
+
get: function () {
|
|
149
|
+
return this._clipBox;
|
|
150
|
+
},
|
|
151
|
+
enumerable: false,
|
|
152
|
+
configurable: true
|
|
153
|
+
});
|
|
154
|
+
/**
|
|
155
|
+
* Clips this node's paint to `box` and uses `box` as the page-framing
|
|
156
|
+
* extents (paper-space viewport frame).
|
|
157
|
+
*/
|
|
158
|
+
AcPdfEntity.prototype.setClipBox = function (box) {
|
|
159
|
+
this._clipBox = box.clone();
|
|
160
|
+
this._box.copy(box);
|
|
161
|
+
};
|
|
162
|
+
Object.defineProperty(AcPdfEntity.prototype, "visible", {
|
|
163
|
+
get: function () {
|
|
164
|
+
return this._visible;
|
|
165
|
+
},
|
|
166
|
+
set: function (value) {
|
|
167
|
+
this._visible = value;
|
|
168
|
+
},
|
|
169
|
+
enumerable: false,
|
|
170
|
+
configurable: true
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(AcPdfEntity.prototype, "userData", {
|
|
173
|
+
get: function () {
|
|
174
|
+
return this._userData;
|
|
175
|
+
},
|
|
176
|
+
set: function (value) {
|
|
177
|
+
this._userData = value;
|
|
178
|
+
},
|
|
179
|
+
enumerable: false,
|
|
180
|
+
configurable: true
|
|
181
|
+
});
|
|
182
|
+
Object.defineProperty(AcPdfEntity.prototype, "childCount", {
|
|
183
|
+
get: function () {
|
|
184
|
+
return this._children.length;
|
|
185
|
+
},
|
|
186
|
+
enumerable: false,
|
|
187
|
+
configurable: true
|
|
188
|
+
});
|
|
189
|
+
AcPdfEntity.prototype.addOp = function (op) {
|
|
190
|
+
this._ops.push(op);
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Walks this node and descendants, invoking `visitor` for each draw op.
|
|
194
|
+
*/
|
|
195
|
+
AcPdfEntity.prototype.forEachOp = function (visitor) {
|
|
196
|
+
var e_1, _a, e_2, _b;
|
|
197
|
+
try {
|
|
198
|
+
for (var _c = __values(this._ops), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
199
|
+
var op = _d.value;
|
|
200
|
+
visitor(op);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
204
|
+
finally {
|
|
205
|
+
try {
|
|
206
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
207
|
+
}
|
|
208
|
+
finally { if (e_1) throw e_1.error; }
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
for (var _e = __values(this._children), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
212
|
+
var child = _f.value;
|
|
213
|
+
child.forEachOp(visitor);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
217
|
+
finally {
|
|
218
|
+
try {
|
|
219
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
220
|
+
}
|
|
221
|
+
finally { if (e_2) throw e_2.error; }
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Like {@link forEachOp}, but applies this node's INSERT/CTM matrix so
|
|
226
|
+
* points are in the same drawing space as {@link box} after applyMatrix.
|
|
227
|
+
*/
|
|
228
|
+
AcPdfEntity.prototype.forEachWorldOp = function (visitor, parentMatrix) {
|
|
229
|
+
var e_3, _a, e_4, _b;
|
|
230
|
+
var matrix = this._matrix
|
|
231
|
+
? parentMatrix
|
|
232
|
+
? parentMatrix.clone().multiply(this._matrix)
|
|
233
|
+
: this._matrix
|
|
234
|
+
: parentMatrix;
|
|
235
|
+
try {
|
|
236
|
+
for (var _c = __values(this._ops), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
237
|
+
var op = _d.value;
|
|
238
|
+
visitor(op, matrix);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
242
|
+
finally {
|
|
243
|
+
try {
|
|
244
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
245
|
+
}
|
|
246
|
+
finally { if (e_3) throw e_3.error; }
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
for (var _e = __values(this._children), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
250
|
+
var child = _f.value;
|
|
251
|
+
child.forEachWorldOp(visitor, matrix);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
255
|
+
finally {
|
|
256
|
+
try {
|
|
257
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
258
|
+
}
|
|
259
|
+
finally { if (e_4) throw e_4.error; }
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Paints this node and its children into a PDF content stream.
|
|
264
|
+
*/
|
|
265
|
+
AcPdfEntity.prototype.paint = function (writerOrCtx) {
|
|
266
|
+
var e_5, _a;
|
|
267
|
+
var _b, _c;
|
|
268
|
+
var ctx = 'drawOp' in writerOrCtx ? { writer: writerOrCtx } : writerOrCtx;
|
|
269
|
+
var writer = ctx.writer;
|
|
270
|
+
if (!this._visible) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
var isInsert = !!this._insertName || this._entityType === 'INSERT';
|
|
274
|
+
var layer = effectivePdfLayer(this._layerName, ctx.insertLayer);
|
|
275
|
+
var ocgName = (_b = ctx.ocg) === null || _b === void 0 ? void 0 : _b.ensure(layer).resourceName;
|
|
276
|
+
if (ocgName) {
|
|
277
|
+
writer.beginOcg(ocgName);
|
|
278
|
+
}
|
|
279
|
+
if (this._objectId || isInsert) {
|
|
280
|
+
writer.beginEntity({
|
|
281
|
+
handle: this._objectId || undefined,
|
|
282
|
+
type: isInsert ? 'INSERT' : this._entityType || undefined,
|
|
283
|
+
name: this._insertName,
|
|
284
|
+
layer: layer
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
var text = ctx.embedActualText !== false ? (_c = this._actualText) === null || _c === void 0 ? void 0 : _c.trim() : undefined;
|
|
288
|
+
if (text) {
|
|
289
|
+
writer.beginActualText(text);
|
|
290
|
+
}
|
|
291
|
+
var localToDrawing = this._matrix
|
|
292
|
+
? composeCtm(ctx.localToDrawing, this._matrix)
|
|
293
|
+
: ctx.localToDrawing;
|
|
294
|
+
// Form reuse is disabled: Form XObjects + page CTM conjugation proved
|
|
295
|
+
// brittle across viewers; baking into drawing space is deterministic.
|
|
296
|
+
var paintedAsForm = false;
|
|
297
|
+
if (!paintedAsForm) {
|
|
298
|
+
if (this._clipBox) {
|
|
299
|
+
writer.save();
|
|
300
|
+
writer.clipRect(this._clipBox);
|
|
301
|
+
}
|
|
302
|
+
if (this._ops.length > 0) {
|
|
303
|
+
writer.drawOps(this._ops, localToDrawing
|
|
304
|
+
? function (op) { return transformOpByMatrix(op, localToDrawing); }
|
|
305
|
+
: undefined, localToDrawing);
|
|
306
|
+
}
|
|
307
|
+
var childCtx = __assign(__assign({}, ctx), { insertLayer: isInsert ? layer : ctx.insertLayer, localToDrawing: localToDrawing });
|
|
308
|
+
try {
|
|
309
|
+
for (var _d = __values(this._children), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
310
|
+
var child = _e.value;
|
|
311
|
+
child.paint(childCtx);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
315
|
+
finally {
|
|
316
|
+
try {
|
|
317
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
318
|
+
}
|
|
319
|
+
finally { if (e_5) throw e_5.error; }
|
|
320
|
+
}
|
|
321
|
+
if (this._clipBox) {
|
|
322
|
+
writer.restore();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (text) {
|
|
326
|
+
writer.endMarked();
|
|
327
|
+
}
|
|
328
|
+
if (this._objectId || isInsert) {
|
|
329
|
+
writer.endMarked();
|
|
330
|
+
}
|
|
331
|
+
if (ocgName) {
|
|
332
|
+
writer.endMarked();
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
AcPdfEntity.prototype.applyMatrix = function (matrix) {
|
|
336
|
+
if (!this._matrix) {
|
|
337
|
+
this._matrix = matrix.clone();
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
this._matrix = matrix.clone().multiply(this._matrix);
|
|
341
|
+
}
|
|
342
|
+
this.transformBoxesRecursive(matrix);
|
|
343
|
+
};
|
|
344
|
+
AcPdfEntity.prototype.transformBoxesRecursive = function (matrix) {
|
|
345
|
+
var e_6, _a;
|
|
346
|
+
AcPdfMatrixUtil.transformBox(this._box, matrix);
|
|
347
|
+
try {
|
|
348
|
+
for (var _b = __values(this._children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
349
|
+
var child = _c.value;
|
|
350
|
+
child.transformBoxesRecursive(matrix);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
354
|
+
finally {
|
|
355
|
+
try {
|
|
356
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
357
|
+
}
|
|
358
|
+
finally { if (e_6) throw e_6.error; }
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
AcPdfEntity.prototype.recomputeBoundingBox = function () {
|
|
362
|
+
// Bounding boxes are maintained during draw and applyMatrix.
|
|
363
|
+
};
|
|
364
|
+
AcPdfEntity.prototype.highlight = function () {
|
|
365
|
+
// Export renderer: no interactive highlight.
|
|
366
|
+
};
|
|
367
|
+
AcPdfEntity.prototype.unhighlight = function () {
|
|
368
|
+
// Export renderer: no interactive highlight.
|
|
369
|
+
};
|
|
370
|
+
AcPdfEntity.prototype.addChild = function (entity) {
|
|
371
|
+
if (entity instanceof AcPdfEntity) {
|
|
372
|
+
this._children.push(entity);
|
|
373
|
+
this._box.union(entity.box);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
/**
|
|
377
|
+
* Clones this node (used by `AcDbRenderingCache` to stamp INSERT instances).
|
|
378
|
+
*
|
|
379
|
+
* Shares draw ops with the source by default: ops are treated as immutable
|
|
380
|
+
* across the whole pipeline (paint bakes transformed copies via
|
|
381
|
+
* `transformOpByMatrix`, boxes are per-entity), so sharing turns per-INSERT
|
|
382
|
+
* cloning from O(points) deep copies into O(ops) reference copies — the
|
|
383
|
+
* dominant memory multiplier on INSERT-heavy drawings.
|
|
384
|
+
*/
|
|
385
|
+
AcPdfEntity.prototype.fastDeepClone = function (shareGeometry) {
|
|
386
|
+
var e_7, _a, e_8, _b;
|
|
387
|
+
if (shareGeometry === void 0) { shareGeometry = true; }
|
|
388
|
+
var cloned = new AcPdfEntity();
|
|
389
|
+
cloned._objectId = this._objectId;
|
|
390
|
+
cloned._ownerId = this._ownerId;
|
|
391
|
+
cloned._layerName = this._layerName;
|
|
392
|
+
cloned._visible = this._visible;
|
|
393
|
+
cloned._userData = this._userData;
|
|
394
|
+
cloned._drawOrder = this._drawOrder;
|
|
395
|
+
cloned._entityType = this._entityType;
|
|
396
|
+
cloned._insertName = this._insertName;
|
|
397
|
+
cloned._actualText = this._actualText;
|
|
398
|
+
cloned._box.copy(this._box);
|
|
399
|
+
if (this._clipBox) {
|
|
400
|
+
cloned._clipBox = this._clipBox.clone();
|
|
401
|
+
}
|
|
402
|
+
if (this._matrix) {
|
|
403
|
+
cloned._matrix = this._matrix.clone();
|
|
404
|
+
}
|
|
405
|
+
if (this._basePoint) {
|
|
406
|
+
cloned._basePoint = this._basePoint.clone();
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
for (var _c = __values(this._ops), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
410
|
+
var op = _d.value;
|
|
411
|
+
cloned._ops.push(shareGeometry ? op : cloneOp(op));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
415
|
+
finally {
|
|
416
|
+
try {
|
|
417
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
418
|
+
}
|
|
419
|
+
finally { if (e_7) throw e_7.error; }
|
|
420
|
+
}
|
|
421
|
+
try {
|
|
422
|
+
for (var _e = __values(this._children), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
423
|
+
var child = _f.value;
|
|
424
|
+
cloned._children.push(child.fastDeepClone(shareGeometry));
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
428
|
+
finally {
|
|
429
|
+
try {
|
|
430
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
431
|
+
}
|
|
432
|
+
finally { if (e_8) throw e_8.error; }
|
|
433
|
+
}
|
|
434
|
+
return cloned;
|
|
435
|
+
};
|
|
436
|
+
return AcPdfEntity;
|
|
437
|
+
}());
|
|
438
|
+
export { AcPdfEntity };
|
|
439
|
+
function cloneOp(op) {
|
|
440
|
+
var _a;
|
|
441
|
+
if (op.kind === 'stroke') {
|
|
442
|
+
return {
|
|
443
|
+
kind: 'stroke',
|
|
444
|
+
points: op.points.map(function (p) { return ({ x: p.x, y: p.y }); }),
|
|
445
|
+
closed: op.closed,
|
|
446
|
+
style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) })
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
if (op.kind === 'fill') {
|
|
450
|
+
return {
|
|
451
|
+
kind: 'fill',
|
|
452
|
+
loops: op.loops.map(function (loop) { return loop.map(function (p) { return ({ x: p.x, y: p.y }); }); }),
|
|
453
|
+
style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) })
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (op.kind === 'triangles') {
|
|
457
|
+
// Flat buffers are immutable; share them even on deep clones.
|
|
458
|
+
return {
|
|
459
|
+
kind: 'triangles',
|
|
460
|
+
data: op.data,
|
|
461
|
+
style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) })
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
if (op.kind === 'polylines') {
|
|
465
|
+
return {
|
|
466
|
+
kind: 'polylines',
|
|
467
|
+
data: op.data,
|
|
468
|
+
style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) })
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
if (op.kind === 'circle') {
|
|
472
|
+
return {
|
|
473
|
+
kind: 'circle',
|
|
474
|
+
x: op.x,
|
|
475
|
+
y: op.y,
|
|
476
|
+
r: op.r,
|
|
477
|
+
style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) })
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
if (op.kind === 'text') {
|
|
481
|
+
return __assign(__assign({}, op), { style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) }) });
|
|
482
|
+
}
|
|
483
|
+
if (op.kind === 'gradient') {
|
|
484
|
+
return {
|
|
485
|
+
kind: 'gradient',
|
|
486
|
+
loops: op.loops.map(function (loop) { return loop.map(function (p) { return ({ x: p.x, y: p.y }); }); }),
|
|
487
|
+
shadingType: op.shadingType,
|
|
488
|
+
coords: __spreadArray([], __read(op.coords), false),
|
|
489
|
+
c0: __assign({}, op.c0),
|
|
490
|
+
c1: __assign({}, op.c1),
|
|
491
|
+
strips: (_a = op.strips) === null || _a === void 0 ? void 0 : _a.map(function (s) { return ({
|
|
492
|
+
rgb: __assign({}, s.rgb),
|
|
493
|
+
points: s.points.map(function (p) { return ({ x: p.x, y: p.y }); })
|
|
494
|
+
}); }),
|
|
495
|
+
style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) })
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
kind: 'image',
|
|
500
|
+
bytes: op.bytes,
|
|
501
|
+
format: op.format,
|
|
502
|
+
x: op.x,
|
|
503
|
+
y: op.y,
|
|
504
|
+
width: op.width,
|
|
505
|
+
height: op.height
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Maps draw-op geometry by an affine matrix (drawing-space bake).
|
|
510
|
+
*/
|
|
511
|
+
function affineScale2d(matrix) {
|
|
512
|
+
var el = matrix.elements;
|
|
513
|
+
var sx = Math.hypot(el[0], el[1]);
|
|
514
|
+
var sy = Math.hypot(el[4], el[5]);
|
|
515
|
+
var scale = (sx + sy) / 2;
|
|
516
|
+
return Number.isFinite(scale) && scale > 0 ? scale : 1;
|
|
517
|
+
}
|
|
518
|
+
function transformOpByMatrix(op, matrix) {
|
|
519
|
+
var _a, _b;
|
|
520
|
+
var map = function (p) {
|
|
521
|
+
return AcPdfMatrixUtil.transformPoint(matrix, { x: p.x, y: p.y, z: 0 });
|
|
522
|
+
};
|
|
523
|
+
var scale = affineScale2d(matrix);
|
|
524
|
+
if (op.kind === 'stroke') {
|
|
525
|
+
return __assign(__assign({}, op), { points: op.points.map(map), style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb), lineWidth: op.style.lineWidth * scale, dashArray: (_a = op.style.dashArray) === null || _a === void 0 ? void 0 : _a.map(function (d) { return d * scale; }) }) });
|
|
526
|
+
}
|
|
527
|
+
if (op.kind === 'fill') {
|
|
528
|
+
return __assign(__assign({}, op), { loops: op.loops.map(function (loop) { return loop.map(map); }), style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) }) });
|
|
529
|
+
}
|
|
530
|
+
if (op.kind === 'triangles') {
|
|
531
|
+
// Numeric bake keeps the shared float32 buffer untouched; callers that
|
|
532
|
+
// care about allocation use the writer's Form XObject path instead.
|
|
533
|
+
return __assign(__assign({}, op), { data: transformFlatPoints(op.data, matrix) });
|
|
534
|
+
}
|
|
535
|
+
if (op.kind === 'polylines') {
|
|
536
|
+
return __assign(__assign({}, op), { data: transformFlatPolylines(op.data, matrix), style: __assign(__assign({}, op.style), { lineWidth: op.style.lineWidth * scale }) });
|
|
537
|
+
}
|
|
538
|
+
if (op.kind === 'circle') {
|
|
539
|
+
var c = map({ x: op.x, y: op.y });
|
|
540
|
+
var edge = map({ x: op.x + op.r, y: op.y });
|
|
541
|
+
var r = Math.hypot(edge.x - c.x, edge.y - c.y);
|
|
542
|
+
return __assign(__assign({}, op), { x: c.x, y: c.y, r: r, style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) }) });
|
|
543
|
+
}
|
|
544
|
+
if (op.kind === 'text') {
|
|
545
|
+
return transformTextOp(op, map);
|
|
546
|
+
}
|
|
547
|
+
if (op.kind === 'gradient') {
|
|
548
|
+
var mapCoord = function (x, y) {
|
|
549
|
+
var p = map({ x: x, y: y });
|
|
550
|
+
return { x: p.x, y: p.y };
|
|
551
|
+
};
|
|
552
|
+
var coords = __spreadArray([], __read(op.coords), false);
|
|
553
|
+
if (op.shadingType === 2 && coords.length >= 4) {
|
|
554
|
+
var a = mapCoord(coords[0], coords[1]);
|
|
555
|
+
var b = mapCoord(coords[2], coords[3]);
|
|
556
|
+
coords = [a.x, a.y, b.x, b.y];
|
|
557
|
+
}
|
|
558
|
+
else if (op.shadingType === 3 && coords.length >= 6) {
|
|
559
|
+
var c0 = mapCoord(coords[0], coords[1]);
|
|
560
|
+
var c1 = mapCoord(coords[3], coords[4]);
|
|
561
|
+
var edge = mapCoord(coords[0] + coords[2], coords[1]);
|
|
562
|
+
var edge2 = mapCoord(coords[3] + coords[5], coords[4]);
|
|
563
|
+
var r0 = Math.hypot(edge.x - c0.x, edge.y - c0.y);
|
|
564
|
+
var r1 = Math.hypot(edge2.x - c1.x, edge2.y - c1.y);
|
|
565
|
+
coords = [c0.x, c0.y, r0, c1.x, c1.y, r1];
|
|
566
|
+
}
|
|
567
|
+
return __assign(__assign({}, op), { loops: op.loops.map(function (loop) { return loop.map(map); }), coords: coords, strips: (_b = op.strips) === null || _b === void 0 ? void 0 : _b.map(function (s) { return ({
|
|
568
|
+
rgb: __assign({}, s.rgb),
|
|
569
|
+
points: s.points.map(map)
|
|
570
|
+
}); }), style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) }) });
|
|
571
|
+
}
|
|
572
|
+
var p0 = map({ x: op.x, y: op.y });
|
|
573
|
+
var p1 = map({ x: op.x + op.width, y: op.y + op.height });
|
|
574
|
+
return __assign(__assign({}, op), { x: Math.min(p0.x, p1.x), y: Math.min(p0.y, p1.y), width: Math.abs(p1.x - p0.x), height: Math.abs(p1.y - p0.y) });
|
|
575
|
+
}
|
|
576
|
+
function composeCtm(parent, local) {
|
|
577
|
+
return parent ? parent.clone().multiply(local) : local.clone();
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Bakes an affine matrix into a text op.
|
|
581
|
+
*
|
|
582
|
+
* The baseline origin maps directly; the glyph frame's advance (`u`) and up
|
|
583
|
+
* (`v`) directions are transformed to derive the new rotation, font size and
|
|
584
|
+
* width factor — so INSERT block transforms (translate/rotate/scale/mirror)
|
|
585
|
+
* keep text glued to its geometry. A transform with negative determinant
|
|
586
|
+
* (mirror) flips the frame's handedness: the op keeps `flipX` enabled (or
|
|
587
|
+
* gains it) so glyphs render mirrored instead of collapsing into a 180°
|
|
588
|
+
* baseline turn with absorbed width factor.
|
|
589
|
+
*/
|
|
590
|
+
function transformTextOp(op, map) {
|
|
591
|
+
var origin = map({ x: op.x, y: op.y });
|
|
592
|
+
var rad = (op.angleDeg * Math.PI) / 180;
|
|
593
|
+
var cos = Math.cos(rad);
|
|
594
|
+
var sin = Math.sin(rad);
|
|
595
|
+
// Advance direction (`u`): negated for flipped ops (glyph x-axis reversed);
|
|
596
|
+
// the up direction (`v`) is the unflipped perpendicular in both cases.
|
|
597
|
+
var ux = op.flipX === true ? -cos : cos;
|
|
598
|
+
var uy = op.flipX === true ? -sin : sin;
|
|
599
|
+
var dir = map({ x: op.x + ux, y: op.y + uy });
|
|
600
|
+
var perp = map({ x: op.x - sin, y: op.y + cos });
|
|
601
|
+
var du = { x: dir.x - origin.x, y: dir.y - origin.y };
|
|
602
|
+
var dv = { x: perp.x - origin.x, y: perp.y - origin.y };
|
|
603
|
+
var su = Math.hypot(du.x, du.y);
|
|
604
|
+
var sv = Math.hypot(dv.x, dv.y);
|
|
605
|
+
var fallback = __assign(__assign({}, op), { x: origin.x, y: origin.y, style: __assign(__assign({}, op.style), { rgb: __assign({}, op.style.rgb) }) });
|
|
606
|
+
if (!(su > 0) || !(sv > 0)) {
|
|
607
|
+
// Degenerate transform (zero scale): keep orientation, move the origin.
|
|
608
|
+
return fallback;
|
|
609
|
+
}
|
|
610
|
+
// Cross product sign = transformed frame handedness.
|
|
611
|
+
var cross = du.x * dv.y - du.y * dv.x;
|
|
612
|
+
var flipX = cross < 0;
|
|
613
|
+
var angleRad = flipX ? Math.atan2(-du.y, -du.x) : Math.atan2(du.y, du.x);
|
|
614
|
+
return __assign(__assign({}, fallback), { flipX: flipX, angleDeg: (angleRad * 180) / Math.PI, size: op.size * sv, hScale: Math.abs(op.hScale * (su / sv)) });
|
|
615
|
+
}
|
|
616
|
+
/** Bakes an affine matrix into a flat `[x, y, ...]` coordinate buffer. */
|
|
617
|
+
function transformFlatPoints(data, matrix) {
|
|
618
|
+
var out = new Float32Array(data.length);
|
|
619
|
+
for (var i = 0; i + 1 < data.length; i += 2) {
|
|
620
|
+
var p = AcPdfMatrixUtil.transformPoint(matrix, {
|
|
621
|
+
x: data[i],
|
|
622
|
+
y: data[i + 1],
|
|
623
|
+
z: 0
|
|
624
|
+
});
|
|
625
|
+
out[i] = p.x;
|
|
626
|
+
out[i + 1] = p.y;
|
|
627
|
+
}
|
|
628
|
+
return out;
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Bakes an affine matrix into a flat polyline buffer, preserving the
|
|
632
|
+
* vertex-count prefixes (`[n, x, y, ..., n, ...]`).
|
|
633
|
+
*/
|
|
634
|
+
function transformFlatPolylines(data, matrix) {
|
|
635
|
+
var out = new Float32Array(data.length);
|
|
636
|
+
var i = 0;
|
|
637
|
+
while (i < data.length) {
|
|
638
|
+
var n = data[i];
|
|
639
|
+
if (!(n >= 2) || i + 1 + n * 2 > data.length) {
|
|
640
|
+
// Malformed tail: copy verbatim.
|
|
641
|
+
for (; i < data.length; i++) {
|
|
642
|
+
out[i] = data[i];
|
|
643
|
+
}
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
out[i] = n;
|
|
647
|
+
i++;
|
|
648
|
+
for (var k = 0; k < n; k++) {
|
|
649
|
+
var p = AcPdfMatrixUtil.transformPoint(matrix, {
|
|
650
|
+
x: data[i],
|
|
651
|
+
y: data[i + 1],
|
|
652
|
+
z: 0
|
|
653
|
+
});
|
|
654
|
+
out[i] = p.x;
|
|
655
|
+
out[i + 1] = p.y;
|
|
656
|
+
i += 2;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return out;
|
|
660
|
+
}
|
|
661
|
+
//# sourceMappingURL=AcPdfEntity.js.map
|