@mlightcad/cad-pdf-plugin 1.7.3 → 1.7.5
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 -21
- package/README.md +180 -180
- package/dist/cad-pdf-plugin.js +12456 -11919
- package/dist/cad-pdf-plugin.umd.cjs +13 -13
- package/lib/AcApImportPdfCmd.d.ts +1 -0
- package/lib/AcApImportPdfCmd.d.ts.map +1 -1
- package/lib/AcApImportPdfCmd.js +12 -5
- package/lib/AcApImportPdfCmd.js.map +1 -1
- package/lib/AcApPdfFontResolver.d.ts +5 -3
- package/lib/AcApPdfFontResolver.d.ts.map +1 -1
- package/lib/AcApPdfFontResolver.js +52 -12
- package/lib/AcApPdfFontResolver.js.map +1 -1
- package/lib/AcApPdfGlyphProvider.d.ts.map +1 -1
- package/lib/AcApPdfGlyphProvider.js +179 -49
- package/lib/AcApPdfGlyphProvider.js.map +1 -1
- package/lib/AcApPdfImportConvertor.d.ts +15 -7
- package/lib/AcApPdfImportConvertor.d.ts.map +1 -1
- package/lib/AcApPdfImportConvertor.js +262 -234
- package/lib/AcApPdfImportConvertor.js.map +1 -1
- package/lib/pdfOptionalContent.d.ts +93 -0
- package/lib/pdfOptionalContent.d.ts.map +1 -0
- package/lib/pdfOptionalContent.js +287 -0
- package/lib/pdfOptionalContent.js.map +1 -0
- package/lib/pdfVectorImport.d.ts +105 -0
- package/lib/pdfVectorImport.d.ts.map +1 -0
- package/lib/pdfVectorImport.js +680 -0
- package/lib/pdfVectorImport.js.map +1 -0
- package/package.json +9 -9
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF operator-list → CAD polyline conversion, without pdfjs-dist.
|
|
3
|
+
*
|
|
4
|
+
* PDF.js numeric op codes are passed in so unit tests can exercise packed
|
|
5
|
+
* `constructPath` streams, CTM save/restore, and layer assignment without
|
|
6
|
+
* loading the PDF worker.
|
|
7
|
+
*/
|
|
8
|
+
var __assign = (this && this.__assign) || function () {
|
|
9
|
+
__assign = Object.assign || function(t) {
|
|
10
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11
|
+
s = arguments[i];
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
return __assign.apply(this, arguments);
|
|
18
|
+
};
|
|
19
|
+
var __values = (this && this.__values) || function(o) {
|
|
20
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
21
|
+
if (m) return m.call(o);
|
|
22
|
+
if (o && typeof o.length === "number") return {
|
|
23
|
+
next: function () {
|
|
24
|
+
if (o && i >= o.length) o = void 0;
|
|
25
|
+
return { value: o && o[i++], done: !o };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
29
|
+
};
|
|
30
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
31
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
32
|
+
if (!m) return o;
|
|
33
|
+
var i = m.call(o), r, ar = [], e;
|
|
34
|
+
try {
|
|
35
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
36
|
+
}
|
|
37
|
+
catch (error) { e = { error: error }; }
|
|
38
|
+
finally {
|
|
39
|
+
try {
|
|
40
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
41
|
+
}
|
|
42
|
+
finally { if (e) throw e.error; }
|
|
43
|
+
}
|
|
44
|
+
return ar;
|
|
45
|
+
};
|
|
46
|
+
import { getPdfMarkedContentTarget } from './pdfOptionalContent';
|
|
47
|
+
/** 1 PDF point in mm (1 pt = 1/72 inch = 25.4/72 mm) */
|
|
48
|
+
export var PDF_PT_TO_MM = 25.4 / 72;
|
|
49
|
+
/** Bezier approximation resolution (line segments per curve) */
|
|
50
|
+
var BEZIER_STEPS = 8;
|
|
51
|
+
/**
|
|
52
|
+
* Converts one page operator list into model-space subpaths.
|
|
53
|
+
*
|
|
54
|
+
* Coordinates are mapped through the content-stream CTM and then the PDF.js
|
|
55
|
+
* viewport. PDF.js bakes a pure translation `q cm ... Q` into `constructPath`
|
|
56
|
+
* and removes that `transform` op, so this function applies only the
|
|
57
|
+
* transforms that remain in the operator list.
|
|
58
|
+
*
|
|
59
|
+
* @param fallbackLayerName - Layer for geometry outside a single OCG. Omit it
|
|
60
|
+
* for PDFs with no optional content so entities stay on the current layer.
|
|
61
|
+
*/
|
|
62
|
+
export function extractPdfImportSubpaths(opList, ops, viewport, ocgLayers, fallbackLayerName) {
|
|
63
|
+
var e_1, _a;
|
|
64
|
+
var _b, _c, _d;
|
|
65
|
+
var fnArray = opList.fnArray, argsArray = opList.argsArray;
|
|
66
|
+
var subpathResult = [];
|
|
67
|
+
var textResult = [];
|
|
68
|
+
// PDF.js 5.x normally packs path construction into OPS.constructPath.
|
|
69
|
+
// The packed stream uses DrawOPS values from PDF.js shared/util:
|
|
70
|
+
// moveTo=0, lineTo=1, curveTo=2, quadraticCurveTo=3, closePath=4.
|
|
71
|
+
var DRAW_MOVE_TO = 0;
|
|
72
|
+
var DRAW_LINE_TO = 1;
|
|
73
|
+
var DRAW_CURVE_TO = 2;
|
|
74
|
+
var DRAW_QUADRATIC_CURVE_TO = 3;
|
|
75
|
+
var DRAW_CLOSE_PATH = 4;
|
|
76
|
+
var subpaths = [];
|
|
77
|
+
var current = [];
|
|
78
|
+
var currentPathLayerName = fallbackLayerName;
|
|
79
|
+
var activeLayerName = fallbackLayerName;
|
|
80
|
+
var markedContentLayerStack = [];
|
|
81
|
+
var curX = 0;
|
|
82
|
+
var curY = 0;
|
|
83
|
+
var ctm = [1, 0, 0, 1, 0, 0];
|
|
84
|
+
var fillColor = '#000000';
|
|
85
|
+
var strokeColor = '#000000';
|
|
86
|
+
// Text state parameters (Tf/Tc/Tw/Tz/TL/Tr/Ts) are graphics-state fields and
|
|
87
|
+
// must round-trip with q/Q. Tm/Tlm and the text cursor are not.
|
|
88
|
+
var fontSize = 0;
|
|
89
|
+
var textHScale = 1;
|
|
90
|
+
var textRise = 0;
|
|
91
|
+
var leading = 0;
|
|
92
|
+
var charSpacing = 0;
|
|
93
|
+
var wordSpacing = 0;
|
|
94
|
+
var textRenderingMode = 0;
|
|
95
|
+
var graphicsStack = [];
|
|
96
|
+
var textMatrix = [1, 0, 0, 1, 0, 0];
|
|
97
|
+
var textLineMatrix = [1, 0, 0, 1, 0, 0];
|
|
98
|
+
var textX = 0;
|
|
99
|
+
var textY = 0;
|
|
100
|
+
var cloneMatrix = function (matrix) { return [
|
|
101
|
+
matrix[0],
|
|
102
|
+
matrix[1],
|
|
103
|
+
matrix[2],
|
|
104
|
+
matrix[3],
|
|
105
|
+
matrix[4],
|
|
106
|
+
matrix[5]
|
|
107
|
+
]; };
|
|
108
|
+
var multiplyMatrix = function (left, right) { return [
|
|
109
|
+
left[0] * right[0] + left[2] * right[1],
|
|
110
|
+
left[1] * right[0] + left[3] * right[1],
|
|
111
|
+
left[0] * right[2] + left[2] * right[3],
|
|
112
|
+
left[1] * right[2] + left[3] * right[3],
|
|
113
|
+
left[0] * right[4] + left[2] * right[5] + left[4],
|
|
114
|
+
left[1] * right[4] + left[3] * right[5] + left[5]
|
|
115
|
+
]; };
|
|
116
|
+
var transformPoint = function (x, y) { return ({
|
|
117
|
+
x: ctm[0] * x + ctm[2] * y + ctm[4],
|
|
118
|
+
y: ctm[1] * x + ctm[3] * y + ctm[5]
|
|
119
|
+
}); };
|
|
120
|
+
var flush = function () {
|
|
121
|
+
if (current.length > 1) {
|
|
122
|
+
subpaths.push({
|
|
123
|
+
points: current,
|
|
124
|
+
layerName: currentPathLayerName
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
current = [];
|
|
128
|
+
currentPathLayerName = activeLayerName;
|
|
129
|
+
};
|
|
130
|
+
var commit = function (color) {
|
|
131
|
+
var e_2, _a;
|
|
132
|
+
if (color === void 0) { color = strokeColor; }
|
|
133
|
+
flush();
|
|
134
|
+
try {
|
|
135
|
+
for (var subpaths_1 = __values(subpaths), subpaths_1_1 = subpaths_1.next(); !subpaths_1_1.done; subpaths_1_1 = subpaths_1.next()) {
|
|
136
|
+
var subpath = subpaths_1_1.value;
|
|
137
|
+
subpathResult.push(__assign(__assign({}, subpath), { color: color }));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
141
|
+
finally {
|
|
142
|
+
try {
|
|
143
|
+
if (subpaths_1_1 && !subpaths_1_1.done && (_a = subpaths_1.return)) _a.call(subpaths_1);
|
|
144
|
+
}
|
|
145
|
+
finally { if (e_2) throw e_2.error; }
|
|
146
|
+
}
|
|
147
|
+
subpaths = [];
|
|
148
|
+
};
|
|
149
|
+
var paintColor = function (paintOp) {
|
|
150
|
+
return paintOp === ops.fill || paintOp === ops.eoFill ? fillColor : strokeColor;
|
|
151
|
+
};
|
|
152
|
+
var discard = function () {
|
|
153
|
+
current = [];
|
|
154
|
+
subpaths = [];
|
|
155
|
+
currentPathLayerName = activeLayerName;
|
|
156
|
+
};
|
|
157
|
+
var pagePointToCadPoint = function (x, y) {
|
|
158
|
+
var transformed = transformPoint(x, y);
|
|
159
|
+
var _a = __read(viewport.convertToViewportPoint(transformed.x, transformed.y), 2), viewportX = _a[0], viewportY = _a[1];
|
|
160
|
+
return {
|
|
161
|
+
x: viewportX * PDF_PT_TO_MM,
|
|
162
|
+
y: (viewport.height - viewportY) * PDF_PT_TO_MM
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
var tx = function (x, y) { return pagePointToCadPoint(x, y).x; };
|
|
166
|
+
var ty = function (x, y) { return pagePointToCadPoint(x, y).y; };
|
|
167
|
+
var moveTo = function (x, y) {
|
|
168
|
+
flush();
|
|
169
|
+
curX = x;
|
|
170
|
+
curY = y;
|
|
171
|
+
currentPathLayerName = activeLayerName;
|
|
172
|
+
current = [{ x: tx(x, y), y: ty(x, y) }];
|
|
173
|
+
};
|
|
174
|
+
var lineTo = function (x, y) {
|
|
175
|
+
curX = x;
|
|
176
|
+
curY = y;
|
|
177
|
+
current.push({ x: tx(x, y), y: ty(x, y) });
|
|
178
|
+
};
|
|
179
|
+
var curveTo = function (x1, y1, x2, y2, x3, y3) {
|
|
180
|
+
var e_3, _a;
|
|
181
|
+
var pts = cubicBezier({ x: curX, y: curY }, { x: x1, y: y1 }, { x: x2, y: y2 }, { x: x3, y: y3 }, BEZIER_STEPS);
|
|
182
|
+
try {
|
|
183
|
+
for (var pts_1 = __values(pts), pts_1_1 = pts_1.next(); !pts_1_1.done; pts_1_1 = pts_1.next()) {
|
|
184
|
+
var point = pts_1_1.value;
|
|
185
|
+
current.push({ x: tx(point.x, point.y), y: ty(point.x, point.y) });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
189
|
+
finally {
|
|
190
|
+
try {
|
|
191
|
+
if (pts_1_1 && !pts_1_1.done && (_a = pts_1.return)) _a.call(pts_1);
|
|
192
|
+
}
|
|
193
|
+
finally { if (e_3) throw e_3.error; }
|
|
194
|
+
}
|
|
195
|
+
curX = x3;
|
|
196
|
+
curY = y3;
|
|
197
|
+
};
|
|
198
|
+
var quadraticCurveTo = function (x1, y1, x2, y2) {
|
|
199
|
+
for (var step = 1; step <= BEZIER_STEPS; step++) {
|
|
200
|
+
var t = step / BEZIER_STEPS;
|
|
201
|
+
var mt = 1 - t;
|
|
202
|
+
var x = mt * mt * curX + 2 * mt * t * x1 + t * t * x2;
|
|
203
|
+
var y = mt * mt * curY + 2 * mt * t * y1 + t * t * y2;
|
|
204
|
+
current.push({ x: tx(x, y), y: ty(x, y) });
|
|
205
|
+
}
|
|
206
|
+
curX = x2;
|
|
207
|
+
curY = y2;
|
|
208
|
+
};
|
|
209
|
+
var closePath = function () {
|
|
210
|
+
if (current.length > 0) {
|
|
211
|
+
current.push(__assign({}, current[0]));
|
|
212
|
+
}
|
|
213
|
+
flush();
|
|
214
|
+
};
|
|
215
|
+
var rectangle = function (x, y, width, height) {
|
|
216
|
+
moveTo(x, y);
|
|
217
|
+
lineTo(x + width, y);
|
|
218
|
+
lineTo(x + width, y + height);
|
|
219
|
+
lineTo(x, y + height);
|
|
220
|
+
closePath();
|
|
221
|
+
};
|
|
222
|
+
var isArrayLikePathData = function (value) {
|
|
223
|
+
return Array.isArray(value) || ArrayBuffer.isView(value);
|
|
224
|
+
};
|
|
225
|
+
var processPackedPathStream = function (stream) {
|
|
226
|
+
if (stream.length === 0 || stream[0] == null)
|
|
227
|
+
return;
|
|
228
|
+
var index = 0;
|
|
229
|
+
var take = function () { return Number(stream[index++]); };
|
|
230
|
+
while (index < stream.length) {
|
|
231
|
+
var pathOp = Number(stream[index++]);
|
|
232
|
+
switch (pathOp) {
|
|
233
|
+
case DRAW_MOVE_TO:
|
|
234
|
+
moveTo(take(), take());
|
|
235
|
+
break;
|
|
236
|
+
case DRAW_LINE_TO:
|
|
237
|
+
lineTo(take(), take());
|
|
238
|
+
break;
|
|
239
|
+
case DRAW_CURVE_TO:
|
|
240
|
+
curveTo(take(), take(), take(), take(), take(), take());
|
|
241
|
+
break;
|
|
242
|
+
case DRAW_QUADRATIC_CURVE_TO:
|
|
243
|
+
quadraticCurveTo(take(), take(), take(), take());
|
|
244
|
+
break;
|
|
245
|
+
case DRAW_CLOSE_PATH:
|
|
246
|
+
closePath();
|
|
247
|
+
break;
|
|
248
|
+
default:
|
|
249
|
+
// Avoid consuming coordinates with an unknown DrawOPS value.
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
// Compatibility with older operator-list shapes where path operation codes
|
|
255
|
+
// and coordinates were delivered as separate arrays.
|
|
256
|
+
var processSplitPathStream = function (pathOps, pathArgs) {
|
|
257
|
+
var argIndex = 0;
|
|
258
|
+
var take = function () { return Number(pathArgs[argIndex++]); };
|
|
259
|
+
for (var i = 0; i < pathOps.length; i++) {
|
|
260
|
+
var pathOp = Number(pathOps[i]);
|
|
261
|
+
switch (pathOp) {
|
|
262
|
+
case DRAW_MOVE_TO:
|
|
263
|
+
case ops.moveTo:
|
|
264
|
+
moveTo(take(), take());
|
|
265
|
+
break;
|
|
266
|
+
case DRAW_LINE_TO:
|
|
267
|
+
case ops.lineTo:
|
|
268
|
+
lineTo(take(), take());
|
|
269
|
+
break;
|
|
270
|
+
case DRAW_CURVE_TO:
|
|
271
|
+
case ops.curveTo:
|
|
272
|
+
curveTo(take(), take(), take(), take(), take(), take());
|
|
273
|
+
break;
|
|
274
|
+
case DRAW_QUADRATIC_CURVE_TO:
|
|
275
|
+
quadraticCurveTo(take(), take(), take(), take());
|
|
276
|
+
break;
|
|
277
|
+
case ops.curveTo2:
|
|
278
|
+
curveTo(curX, curY, take(), take(), take(), take());
|
|
279
|
+
break;
|
|
280
|
+
case ops.curveTo3: {
|
|
281
|
+
var x1 = take();
|
|
282
|
+
var y1 = take();
|
|
283
|
+
var x3 = take();
|
|
284
|
+
var y3 = take();
|
|
285
|
+
curveTo(x1, y1, x3, y3, x3, y3);
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
case ops.rectangle:
|
|
289
|
+
rectangle(take(), take(), take(), take());
|
|
290
|
+
break;
|
|
291
|
+
case DRAW_CLOSE_PATH:
|
|
292
|
+
case ops.closePath:
|
|
293
|
+
closePath();
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
var finishConstructPath = function (paintOp) {
|
|
299
|
+
switch (paintOp) {
|
|
300
|
+
case ops.stroke:
|
|
301
|
+
case ops.closeStroke:
|
|
302
|
+
case ops.fill:
|
|
303
|
+
case ops.eoFill:
|
|
304
|
+
case ops.fillStroke:
|
|
305
|
+
case ops.eoFillStroke:
|
|
306
|
+
case ops.closeFillStroke:
|
|
307
|
+
case ops.closeEOFillStroke:
|
|
308
|
+
commit(paintColor(paintOp));
|
|
309
|
+
break;
|
|
310
|
+
case ops.endPath:
|
|
311
|
+
// PDF "n" ends the current path without painting it, commonly after
|
|
312
|
+
// clipping. Do not create CAD entities from those paths.
|
|
313
|
+
discard();
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
for (var i = 0; i < fnArray.length; i++) {
|
|
318
|
+
var fn = fnArray[i];
|
|
319
|
+
var value = argsArray[i];
|
|
320
|
+
var rawArgs = Array.isArray(value) ? value : [];
|
|
321
|
+
if (fn === ops.save) {
|
|
322
|
+
graphicsStack.push({
|
|
323
|
+
ctm: cloneMatrix(ctm),
|
|
324
|
+
fillColor: fillColor,
|
|
325
|
+
strokeColor: strokeColor,
|
|
326
|
+
fontSize: fontSize,
|
|
327
|
+
textHScale: textHScale,
|
|
328
|
+
textRise: textRise,
|
|
329
|
+
leading: leading,
|
|
330
|
+
charSpacing: charSpacing,
|
|
331
|
+
wordSpacing: wordSpacing,
|
|
332
|
+
textRenderingMode: textRenderingMode
|
|
333
|
+
});
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (fn === ops.restore) {
|
|
337
|
+
var restored = graphicsStack.pop();
|
|
338
|
+
if (restored) {
|
|
339
|
+
ctm = restored.ctm;
|
|
340
|
+
fillColor = restored.fillColor;
|
|
341
|
+
strokeColor = restored.strokeColor;
|
|
342
|
+
fontSize = restored.fontSize;
|
|
343
|
+
textHScale = restored.textHScale;
|
|
344
|
+
textRise = restored.textRise;
|
|
345
|
+
leading = restored.leading;
|
|
346
|
+
charSpacing = restored.charSpacing;
|
|
347
|
+
wordSpacing = restored.wordSpacing;
|
|
348
|
+
textRenderingMode = restored.textRenderingMode;
|
|
349
|
+
}
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
if (fn === ops.setFillRGBColor) {
|
|
353
|
+
var color = readCssColor(rawArgs[0]);
|
|
354
|
+
if (color)
|
|
355
|
+
fillColor = color;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if (fn === ops.setStrokeRGBColor) {
|
|
359
|
+
var color = readCssColor(rawArgs[0]);
|
|
360
|
+
if (color)
|
|
361
|
+
strokeColor = color;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (fn === ops.beginText) {
|
|
365
|
+
textMatrix = [1, 0, 0, 1, 0, 0];
|
|
366
|
+
textLineMatrix = [1, 0, 0, 1, 0, 0];
|
|
367
|
+
textX = 0;
|
|
368
|
+
textY = 0;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (fn === ops.endText) {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (fn === ops.setFont) {
|
|
375
|
+
var size = Number(rawArgs[1]);
|
|
376
|
+
if (Number.isFinite(size))
|
|
377
|
+
fontSize = size;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (fn === ops.setTextMatrix) {
|
|
381
|
+
var matrix = readMatrix(rawArgs);
|
|
382
|
+
if (matrix) {
|
|
383
|
+
textMatrix = matrix;
|
|
384
|
+
textLineMatrix = cloneMatrix(matrix);
|
|
385
|
+
textX = 0;
|
|
386
|
+
textY = 0;
|
|
387
|
+
}
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (fn === ops.moveText) {
|
|
391
|
+
moveTextLine(Number(rawArgs[0]), Number(rawArgs[1]));
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (fn === ops.setLeadingMoveText) {
|
|
395
|
+
var ty_1 = Number(rawArgs[1]);
|
|
396
|
+
leading = -ty_1;
|
|
397
|
+
moveTextLine(Number(rawArgs[0]), ty_1);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (fn === ops.nextLine) {
|
|
401
|
+
moveTextLine(0, -leading);
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
if (fn === ops.setLeading) {
|
|
405
|
+
var value_1 = Number(rawArgs[0]);
|
|
406
|
+
if (Number.isFinite(value_1))
|
|
407
|
+
leading = value_1;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (fn === ops.setCharSpacing) {
|
|
411
|
+
var value_2 = Number(rawArgs[0]);
|
|
412
|
+
if (Number.isFinite(value_2))
|
|
413
|
+
charSpacing = value_2;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (fn === ops.setWordSpacing) {
|
|
417
|
+
var value_3 = Number(rawArgs[0]);
|
|
418
|
+
if (Number.isFinite(value_3))
|
|
419
|
+
wordSpacing = value_3;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (fn === ops.setHScale) {
|
|
423
|
+
var value_4 = Number(rawArgs[0]);
|
|
424
|
+
if (Number.isFinite(value_4))
|
|
425
|
+
textHScale = value_4 / 100;
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (fn === ops.setTextRise) {
|
|
429
|
+
var value_5 = Number(rawArgs[0]);
|
|
430
|
+
if (Number.isFinite(value_5))
|
|
431
|
+
textRise = value_5;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (fn === ops.setTextRenderingMode) {
|
|
435
|
+
var value_6 = Number(rawArgs[0]);
|
|
436
|
+
if (Number.isFinite(value_6))
|
|
437
|
+
textRenderingMode = value_6;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (fn === ops.showText) {
|
|
441
|
+
showGlyphs(rawArgs[0]);
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (fn === ops.transform) {
|
|
445
|
+
if (rawArgs.length >= 6) {
|
|
446
|
+
var next = [
|
|
447
|
+
Number(rawArgs[0]),
|
|
448
|
+
Number(rawArgs[1]),
|
|
449
|
+
Number(rawArgs[2]),
|
|
450
|
+
Number(rawArgs[3]),
|
|
451
|
+
Number(rawArgs[4]),
|
|
452
|
+
Number(rawArgs[5])
|
|
453
|
+
];
|
|
454
|
+
ctm = multiplyMatrix(ctm, next);
|
|
455
|
+
}
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
if (fn === ops.beginMarkedContent) {
|
|
459
|
+
markedContentLayerStack.push(activeLayerName);
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (fn === ops.beginMarkedContentProps) {
|
|
463
|
+
markedContentLayerStack.push(activeLayerName);
|
|
464
|
+
var target = getPdfMarkedContentTarget(rawArgs);
|
|
465
|
+
if (target.kind === 'ocg') {
|
|
466
|
+
activeLayerName = (_c = (_b = ocgLayers.get(target.id)) === null || _b === void 0 ? void 0 : _b.layerName) !== null && _c !== void 0 ? _c : fallbackLayerName;
|
|
467
|
+
}
|
|
468
|
+
else if (target.kind === 'fallback') {
|
|
469
|
+
activeLayerName = fallbackLayerName;
|
|
470
|
+
}
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (fn === ops.endMarkedContent) {
|
|
474
|
+
activeLayerName = (_d = markedContentLayerStack.pop()) !== null && _d !== void 0 ? _d : fallbackLayerName;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
switch (fn) {
|
|
478
|
+
case ops.constructPath: {
|
|
479
|
+
var first = rawArgs[0];
|
|
480
|
+
var second = rawArgs[1];
|
|
481
|
+
if (isArrayLikePathData(first) && isArrayLikePathData(second)) {
|
|
482
|
+
processSplitPathStream(first, second);
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
var paintOp = Number(first);
|
|
486
|
+
// PDF.js 5.x shape:
|
|
487
|
+
// [paintOp, [Float32Array(DrawOPS + coordinates)], minMax]
|
|
488
|
+
if (Array.isArray(second)) {
|
|
489
|
+
try {
|
|
490
|
+
for (var second_1 = (e_1 = void 0, __values(second)), second_1_1 = second_1.next(); !second_1_1.done; second_1_1 = second_1.next()) {
|
|
491
|
+
var stream = second_1_1.value;
|
|
492
|
+
if (!isArrayLikePathData(stream))
|
|
493
|
+
continue;
|
|
494
|
+
processPackedPathStream(stream);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
498
|
+
finally {
|
|
499
|
+
try {
|
|
500
|
+
if (second_1_1 && !second_1_1.done && (_a = second_1.return)) _a.call(second_1);
|
|
501
|
+
}
|
|
502
|
+
finally { if (e_1) throw e_1.error; }
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
else if (isArrayLikePathData(second)) {
|
|
506
|
+
processPackedPathStream(second);
|
|
507
|
+
}
|
|
508
|
+
finishConstructPath(paintOp);
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
case ops.moveTo: {
|
|
512
|
+
var args = rawArgs;
|
|
513
|
+
moveTo(args[0], args[1]);
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
case ops.lineTo: {
|
|
517
|
+
var args = rawArgs;
|
|
518
|
+
lineTo(args[0], args[1]);
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
case ops.curveTo: {
|
|
522
|
+
var args = rawArgs;
|
|
523
|
+
curveTo(args[0], args[1], args[2], args[3], args[4], args[5]);
|
|
524
|
+
break;
|
|
525
|
+
}
|
|
526
|
+
case ops.curveTo2: {
|
|
527
|
+
var args = rawArgs;
|
|
528
|
+
curveTo(curX, curY, args[0], args[1], args[2], args[3]);
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
case ops.curveTo3: {
|
|
532
|
+
var args = rawArgs;
|
|
533
|
+
curveTo(args[0], args[1], args[2], args[3], args[2], args[3]);
|
|
534
|
+
break;
|
|
535
|
+
}
|
|
536
|
+
case ops.rectangle: {
|
|
537
|
+
var args = rawArgs;
|
|
538
|
+
rectangle(args[0], args[1], args[2], args[3]);
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
case ops.closePath:
|
|
542
|
+
closePath();
|
|
543
|
+
break;
|
|
544
|
+
case ops.closeStroke:
|
|
545
|
+
case ops.closeFillStroke:
|
|
546
|
+
case ops.closeEOFillStroke:
|
|
547
|
+
closePath();
|
|
548
|
+
commit(paintColor(fn));
|
|
549
|
+
break;
|
|
550
|
+
case ops.stroke:
|
|
551
|
+
case ops.fill:
|
|
552
|
+
case ops.eoFill:
|
|
553
|
+
case ops.fillStroke:
|
|
554
|
+
case ops.eoFillStroke:
|
|
555
|
+
commit(paintColor(fn));
|
|
556
|
+
break;
|
|
557
|
+
case ops.endPath:
|
|
558
|
+
discard();
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
commit();
|
|
563
|
+
return { subpaths: subpathResult, texts: textResult };
|
|
564
|
+
// Hoisted so the operator loop above can call them.
|
|
565
|
+
function moveTextLine(tx, ty) {
|
|
566
|
+
var shift = [1, 0, 0, 1, tx, ty];
|
|
567
|
+
textLineMatrix = multiplyMatrix(shift, textLineMatrix);
|
|
568
|
+
textMatrix = cloneMatrix(textLineMatrix);
|
|
569
|
+
textX = 0;
|
|
570
|
+
textY = 0;
|
|
571
|
+
}
|
|
572
|
+
function showGlyphs(glyphs) {
|
|
573
|
+
var list = asNumberList(glyphs);
|
|
574
|
+
if (!list)
|
|
575
|
+
return;
|
|
576
|
+
var text = '';
|
|
577
|
+
var advance = 0;
|
|
578
|
+
var widthAdvanceScale = fontSize * 0.001;
|
|
579
|
+
for (var index = 0; index < list.length; index++) {
|
|
580
|
+
var glyph = list[index];
|
|
581
|
+
if (typeof glyph === 'number') {
|
|
582
|
+
// TJ spacing is in thousandths of a unit; a positive value moves left.
|
|
583
|
+
advance += (-glyph * fontSize) / 1000;
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
if (!glyph || typeof glyph !== 'object')
|
|
587
|
+
continue;
|
|
588
|
+
var record = glyph;
|
|
589
|
+
var unicode = typeof record.unicode === 'string' ? record.unicode : '';
|
|
590
|
+
var fontChar = typeof record.fontChar === 'string' ? record.fontChar : '';
|
|
591
|
+
text += unicode || fontChar;
|
|
592
|
+
var width = typeof record.width === 'number' ? record.width : 0;
|
|
593
|
+
var spacing = (record.isSpace ? wordSpacing : 0) + charSpacing;
|
|
594
|
+
advance += width * widthAdvanceScale + spacing;
|
|
595
|
+
}
|
|
596
|
+
text = text.split('\u0000').join('');
|
|
597
|
+
var paints = (textRenderingMode & 3) !== 3;
|
|
598
|
+
if (paints && fontSize !== 0 && text.length > 0) {
|
|
599
|
+
var origin_1 = textPointToCad(textX, textY + textRise);
|
|
600
|
+
var alongX = textPointToCad(textX + textHScale, textY + textRise);
|
|
601
|
+
var alongY = textPointToCad(textX, textY + textRise + fontSize);
|
|
602
|
+
var dx = alongX.x - origin_1.x;
|
|
603
|
+
var dy = alongX.y - origin_1.y;
|
|
604
|
+
var height = Math.hypot(alongY.x - origin_1.x, alongY.y - origin_1.y);
|
|
605
|
+
var unitY = fontSize > 0 ? height / fontSize : 0;
|
|
606
|
+
var widthFactor = unitY > 1e-9 ? Math.hypot(dx, dy) / unitY : textHScale;
|
|
607
|
+
if (height > 1e-9) {
|
|
608
|
+
textResult.push({
|
|
609
|
+
text: text,
|
|
610
|
+
position: origin_1,
|
|
611
|
+
height: height,
|
|
612
|
+
rotation: Math.atan2(dy, dx),
|
|
613
|
+
widthFactor: widthFactor,
|
|
614
|
+
layerName: activeLayerName,
|
|
615
|
+
color: (textRenderingMode & 3) === 1 ? strokeColor : fillColor
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
textX += advance * textHScale;
|
|
620
|
+
}
|
|
621
|
+
function textPointToCad(x, y) {
|
|
622
|
+
var userX = textMatrix[0] * x + textMatrix[2] * y + textMatrix[4];
|
|
623
|
+
var userY = textMatrix[1] * x + textMatrix[3] * y + textMatrix[5];
|
|
624
|
+
return pagePointToCadPoint(userX, userY);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Approximates a cubic Bezier curve as a polyline.
|
|
629
|
+
*
|
|
630
|
+
* @param p0 - Start point
|
|
631
|
+
* @param p1 - First control point
|
|
632
|
+
* @param p2 - Second control point
|
|
633
|
+
* @param p3 - End point
|
|
634
|
+
* @param steps - Number of line segments to generate
|
|
635
|
+
* @returns Sampled points along the curve (excluding `p0`)
|
|
636
|
+
*/
|
|
637
|
+
function readCssColor(value) {
|
|
638
|
+
if (typeof value === 'string' && /^#[0-9a-fA-F]{6}$/.test(value)) {
|
|
639
|
+
return value.toLowerCase();
|
|
640
|
+
}
|
|
641
|
+
return undefined;
|
|
642
|
+
}
|
|
643
|
+
function readMatrix(rawArgs) {
|
|
644
|
+
var nested = rawArgs.length === 1 ? asNumberList(rawArgs[0]) : undefined;
|
|
645
|
+
var source = nested && nested.length >= 6 ? nested : rawArgs;
|
|
646
|
+
if (source.length < 6)
|
|
647
|
+
return undefined;
|
|
648
|
+
return [
|
|
649
|
+
Number(source[0]),
|
|
650
|
+
Number(source[1]),
|
|
651
|
+
Number(source[2]),
|
|
652
|
+
Number(source[3]),
|
|
653
|
+
Number(source[4]),
|
|
654
|
+
Number(source[5])
|
|
655
|
+
];
|
|
656
|
+
}
|
|
657
|
+
function asNumberList(value) {
|
|
658
|
+
if (Array.isArray(value) || ArrayBuffer.isView(value)) {
|
|
659
|
+
return value;
|
|
660
|
+
}
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
663
|
+
function cubicBezier(p0, p1, p2, p3, steps) {
|
|
664
|
+
var pts = [];
|
|
665
|
+
for (var i = 1; i <= steps; i++) {
|
|
666
|
+
var t = i / steps;
|
|
667
|
+
var mt = 1 - t;
|
|
668
|
+
var x = mt * mt * mt * p0.x +
|
|
669
|
+
3 * mt * mt * t * p1.x +
|
|
670
|
+
3 * mt * t * t * p2.x +
|
|
671
|
+
t * t * t * p3.x;
|
|
672
|
+
var y = mt * mt * mt * p0.y +
|
|
673
|
+
3 * mt * mt * t * p1.y +
|
|
674
|
+
3 * mt * t * t * p2.y +
|
|
675
|
+
t * t * t * p3.y;
|
|
676
|
+
pts.push({ x: x, y: y });
|
|
677
|
+
}
|
|
678
|
+
return pts;
|
|
679
|
+
}
|
|
680
|
+
//# sourceMappingURL=pdfVectorImport.js.map
|