@mlightcad/pdf-renderer 1.7.1 → 1.7.3
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 +29 -29
- package/dist/index.js +6738 -7619
- package/dist/index.umd.cjs +72 -73
- package/lib/AcPdfExport.d.ts.map +1 -1
- package/lib/AcPdfExport.js +64 -53
- package/lib/AcPdfExport.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/linetype/AcPdfLineTypeStroker.d.ts +49 -4
- package/lib/linetype/AcPdfLineTypeStroker.d.ts.map +1 -1
- package/lib/linetype/AcPdfLineTypeStroker.js +163 -13
- package/lib/linetype/AcPdfLineTypeStroker.js.map +1 -1
- package/lib/pdf/AcPdfContentWriter.d.ts +5 -3
- package/lib/pdf/AcPdfContentWriter.d.ts.map +1 -1
- package/lib/pdf/AcPdfContentWriter.js +13 -5
- package/lib/pdf/AcPdfContentWriter.js.map +1 -1
- package/lib/pdf/AcPdfDocumentWriter.d.ts +3 -4
- package/lib/pdf/AcPdfDocumentWriter.d.ts.map +1 -1
- package/lib/pdf/AcPdfDocumentWriter.js +32 -18
- package/lib/pdf/AcPdfDocumentWriter.js.map +1 -1
- package/lib/pdf/AcPdfFontManager.d.ts +10 -0
- package/lib/pdf/AcPdfFontManager.d.ts.map +1 -1
- package/lib/pdf/AcPdfFontManager.js +35 -5
- package/lib/pdf/AcPdfFontManager.js.map +1 -1
- package/lib/pdf/AcPdfPageLayout.d.ts +19 -0
- package/lib/pdf/AcPdfPageLayout.d.ts.map +1 -1
- package/lib/pdf/AcPdfPageLayout.js +30 -0
- package/lib/pdf/AcPdfPageLayout.js.map +1 -1
- package/lib/point/AcPdfPointSymbol.d.ts +38 -0
- package/lib/point/AcPdfPointSymbol.d.ts.map +1 -0
- package/lib/point/AcPdfPointSymbol.js +72 -0
- package/lib/point/AcPdfPointSymbol.js.map +1 -0
- package/lib/renderer/AcPdfEntity.d.ts +12 -3
- package/lib/renderer/AcPdfEntity.d.ts.map +1 -1
- package/lib/renderer/AcPdfEntity.js +7 -1
- package/lib/renderer/AcPdfEntity.js.map +1 -1
- package/lib/renderer/AcPdfMatrixUtil.d.ts +23 -0
- package/lib/renderer/AcPdfMatrixUtil.d.ts.map +1 -1
- package/lib/renderer/AcPdfMatrixUtil.js +15 -0
- package/lib/renderer/AcPdfMatrixUtil.js.map +1 -1
- package/lib/renderer/AcPdfRenderer.d.ts +22 -0
- package/lib/renderer/AcPdfRenderer.d.ts.map +1 -1
- package/lib/renderer/AcPdfRenderer.js +266 -100
- package/lib/renderer/AcPdfRenderer.js.map +1 -1
- package/lib/renderer/AcPdfStyle.d.ts +7 -0
- package/lib/renderer/AcPdfStyle.d.ts.map +1 -1
- package/lib/renderer/AcPdfStyle.js.map +1 -1
- package/lib/renderer/AcPdfStyleUtil.d.ts.map +1 -1
- package/lib/renderer/AcPdfStyleUtil.js +16 -7
- package/lib/renderer/AcPdfStyleUtil.js.map +1 -1
- package/lib/renderer/AcPdfTextLayout.d.ts.map +1 -1
- package/lib/renderer/AcPdfTextLayout.js +8 -2
- package/lib/renderer/AcPdfTextLayout.js.map +1 -1
- package/lib/viewport/AcPdfPaperSpaceExport.d.ts +14 -2
- package/lib/viewport/AcPdfPaperSpaceExport.d.ts.map +1 -1
- package/lib/viewport/AcPdfPaperSpaceExport.js +80 -3
- package/lib/viewport/AcPdfPaperSpaceExport.js.map +1 -1
- package/lib/viewport/AcPdfViewportContent.d.ts.map +1 -1
- package/lib/viewport/AcPdfViewportContent.js +4 -1
- package/lib/viewport/AcPdfViewportContent.js.map +1 -1
- package/package.json +5 -4
|
@@ -56,12 +56,13 @@ var __values = (this && this.__values) || function(o) {
|
|
|
56
56
|
};
|
|
57
57
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
58
58
|
};
|
|
59
|
-
import { AcCmColor, AcCmTransparency, acdbDrawTessellateOptions, acdbRasterizeOleMetafile, AcDbRenderingCache, AcGeMatrix3d, ACGI_DARK_THEME_FOREGROUND, ACGI_LIGHT_THEME_FOREGROUND, AcGiContext, acgiIsLightBackground, AcGiLineWeight } from '@mlightcad/data-model';
|
|
59
|
+
import { AcCmColor, AcCmTransparency, acdbDrawTessellateOptions, acdbRasterizeOleMetafile, AcDbRenderingCache, AcGeArea2d, AcGeMatrix3d, AcGePoint2d, AcGePolyline2d, ACGI_DARK_THEME_FOREGROUND, ACGI_LIGHT_THEME_FOREGROUND, AcGiContext, acgiIsLightBackground, AcGiLineWeight, AcGiMTextAttachmentPoint } from '@mlightcad/data-model';
|
|
60
60
|
import { shadingFromGradient } from '../hatch/AcPdfGradient';
|
|
61
61
|
import { tessellateHatchPattern } from '../hatch/AcPdfHatchTessellator';
|
|
62
|
-
import { isComplexLineType, walkLineType } from '../linetype/AcPdfLineTypeStroker';
|
|
62
|
+
import { isComplexLineType, isComplexShapeElement, isComplexTextElement, resolveLinetypeEmbeddedText, walkLineType } from '../linetype/AcPdfLineTypeStroker';
|
|
63
63
|
import { AcPdfDocumentWriter } from '../pdf/AcPdfDocumentWriter';
|
|
64
64
|
import { stripMtextCodes } from '../pdf/AcPdfMarkedContent';
|
|
65
|
+
import { buildPointSymbol, POINT_CENTER_DOT_RATIO, resolvePointDisplayScale } from '../point/AcPdfPointSymbol';
|
|
65
66
|
import { AcPdfEntity } from './AcPdfEntity';
|
|
66
67
|
import { AcPdfGroup } from './AcPdfGroup';
|
|
67
68
|
import { AcPdfStyleUtil } from './AcPdfStyleUtil';
|
|
@@ -282,18 +283,74 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
282
283
|
this.removeEntities(entities);
|
|
283
284
|
return this.pushEntity(new AcPdfGroup(entities));
|
|
284
285
|
};
|
|
286
|
+
/**
|
|
287
|
+
* Draws an AutoCAD point marker from `PDMODE` / `PDSIZE`.
|
|
288
|
+
*
|
|
289
|
+
* Mode 0 stays a filled dot. Every other mode strokes the same unit symbol
|
|
290
|
+
* as the canvas viewer, placed at `point`, instead of a filled disk.
|
|
291
|
+
*/
|
|
285
292
|
AcPdfRenderer.prototype.point = function (point, style) {
|
|
293
|
+
var e_2, _a, e_3, _b;
|
|
294
|
+
var _c;
|
|
286
295
|
var entity = new AcPdfEntity();
|
|
287
|
-
var
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
296
|
+
var mode = (_c = style.displayMode) !== null && _c !== void 0 ? _c : 0;
|
|
297
|
+
var symbol = buildPointSymbol(mode);
|
|
298
|
+
var scale = resolvePointDisplayScale(style.displaySize);
|
|
299
|
+
if (symbol.strokes.length > 0) {
|
|
300
|
+
var stroke = AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext);
|
|
301
|
+
delete stroke.dashArray;
|
|
302
|
+
try {
|
|
303
|
+
for (var _d = __values(symbol.strokes), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
304
|
+
var poly = _e.value;
|
|
305
|
+
var pts = poly.points.map(function (p) { return ({
|
|
306
|
+
x: point.x + p.x * scale,
|
|
307
|
+
y: point.y + p.y * scale
|
|
308
|
+
}); });
|
|
309
|
+
entity.addOp({
|
|
310
|
+
kind: 'stroke',
|
|
311
|
+
points: pts,
|
|
312
|
+
closed: poly.closed,
|
|
313
|
+
style: stroke
|
|
314
|
+
});
|
|
315
|
+
try {
|
|
316
|
+
for (var pts_1 = (e_3 = void 0, __values(pts)), pts_1_1 = pts_1.next(); !pts_1_1.done; pts_1_1 = pts_1.next()) {
|
|
317
|
+
var p = pts_1_1.value;
|
|
318
|
+
entity.box.expandByPoint(p);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
322
|
+
finally {
|
|
323
|
+
try {
|
|
324
|
+
if (pts_1_1 && !pts_1_1.done && (_b = pts_1.return)) _b.call(pts_1);
|
|
325
|
+
}
|
|
326
|
+
finally { if (e_3) throw e_3.error; }
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
331
|
+
finally {
|
|
332
|
+
try {
|
|
333
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
334
|
+
}
|
|
335
|
+
finally { if (e_2) throw e_2.error; }
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (symbol.centerDot) {
|
|
339
|
+
var r = symbol.strokes.length === 0
|
|
340
|
+
? style.displaySize > 0
|
|
341
|
+
? style.displaySize / 2
|
|
342
|
+
: DEFAULT_POINT_RADIUS
|
|
343
|
+
: scale * POINT_CENTER_DOT_RATIO;
|
|
344
|
+
entity.addOp({
|
|
345
|
+
kind: 'circle',
|
|
346
|
+
x: point.x,
|
|
347
|
+
y: point.y,
|
|
348
|
+
r: r,
|
|
349
|
+
style: AcPdfStyleUtil.pointStyle(this._subEntityTraits, this.styleContext)
|
|
350
|
+
});
|
|
351
|
+
entity.box.expandByPoint({ x: point.x - r, y: point.y - r });
|
|
352
|
+
entity.box.expandByPoint({ x: point.x + r, y: point.y + r });
|
|
353
|
+
}
|
|
297
354
|
return this.pushEntity(entity);
|
|
298
355
|
};
|
|
299
356
|
AcPdfRenderer.prototype.circularArc = function (arc) {
|
|
@@ -303,23 +360,23 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
303
360
|
return this.pushStrokedPolyline(ellipseArc.tessellate(acdbDrawTessellateOptions(this)), ellipseArc.box);
|
|
304
361
|
};
|
|
305
362
|
AcPdfRenderer.prototype.lines = function (points) {
|
|
306
|
-
var
|
|
363
|
+
var e_4, _a;
|
|
307
364
|
var entity = new AcPdfEntity();
|
|
308
365
|
var pts = toPdfPoints(points);
|
|
309
366
|
var style = AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext);
|
|
310
367
|
this.appendStrokedPoints(entity, pts, style);
|
|
311
368
|
try {
|
|
312
|
-
for (var
|
|
313
|
-
var p =
|
|
369
|
+
for (var pts_2 = __values(pts), pts_2_1 = pts_2.next(); !pts_2_1.done; pts_2_1 = pts_2.next()) {
|
|
370
|
+
var p = pts_2_1.value;
|
|
314
371
|
entity.box.expandByPoint(p);
|
|
315
372
|
}
|
|
316
373
|
}
|
|
317
|
-
catch (
|
|
374
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
318
375
|
finally {
|
|
319
376
|
try {
|
|
320
|
-
if (
|
|
377
|
+
if (pts_2_1 && !pts_2_1.done && (_a = pts_2.return)) _a.call(pts_2);
|
|
321
378
|
}
|
|
322
|
-
finally { if (
|
|
379
|
+
finally { if (e_4) throw e_4.error; }
|
|
323
380
|
}
|
|
324
381
|
return this.pushEntity(entity);
|
|
325
382
|
};
|
|
@@ -338,7 +395,7 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
338
395
|
return this.pushEntity(entity);
|
|
339
396
|
};
|
|
340
397
|
AcPdfRenderer.prototype.area = function (area) {
|
|
341
|
-
var
|
|
398
|
+
var e_5, _a, e_6, _b, e_7, _c;
|
|
342
399
|
var _d, _e;
|
|
343
400
|
var entity = new AcPdfEntity();
|
|
344
401
|
var loops = area.tessellate(acdbDrawTessellateOptions(this));
|
|
@@ -352,26 +409,26 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
352
409
|
var pts = toPdfPoints(loop);
|
|
353
410
|
pdfLoops.push(pts);
|
|
354
411
|
try {
|
|
355
|
-
for (var
|
|
356
|
-
var p =
|
|
412
|
+
for (var pts_3 = (e_6 = void 0, __values(pts)), pts_3_1 = pts_3.next(); !pts_3_1.done; pts_3_1 = pts_3.next()) {
|
|
413
|
+
var p = pts_3_1.value;
|
|
357
414
|
entity.box.expandByPoint(p);
|
|
358
415
|
}
|
|
359
416
|
}
|
|
360
|
-
catch (
|
|
417
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
361
418
|
finally {
|
|
362
419
|
try {
|
|
363
|
-
if (
|
|
420
|
+
if (pts_3_1 && !pts_3_1.done && (_b = pts_3.return)) _b.call(pts_3);
|
|
364
421
|
}
|
|
365
|
-
finally { if (
|
|
422
|
+
finally { if (e_6) throw e_6.error; }
|
|
366
423
|
}
|
|
367
424
|
}
|
|
368
425
|
}
|
|
369
|
-
catch (
|
|
426
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
370
427
|
finally {
|
|
371
428
|
try {
|
|
372
429
|
if (loops_1_1 && !loops_1_1.done && (_a = loops_1.return)) _a.call(loops_1);
|
|
373
430
|
}
|
|
374
|
-
finally { if (
|
|
431
|
+
finally { if (e_5) throw e_5.error; }
|
|
375
432
|
}
|
|
376
433
|
var style = AcPdfStyleUtil.fillStyle(this._subEntityTraits, this.styleContext);
|
|
377
434
|
var fillType = this._subEntityTraits.fillType;
|
|
@@ -404,12 +461,12 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
404
461
|
entity.addOp({ kind: 'stroke', points: segment, style: stroke });
|
|
405
462
|
}
|
|
406
463
|
}
|
|
407
|
-
catch (
|
|
464
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
408
465
|
finally {
|
|
409
466
|
try {
|
|
410
467
|
if (segments_1_1 && !segments_1_1.done && (_c = segments_1.return)) _c.call(segments_1);
|
|
411
468
|
}
|
|
412
|
-
finally { if (
|
|
469
|
+
finally { if (e_7) throw e_7.error; }
|
|
413
470
|
}
|
|
414
471
|
}
|
|
415
472
|
else if (pdfLoops.length > 0) {
|
|
@@ -421,6 +478,12 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
421
478
|
}
|
|
422
479
|
return this.pushEntity(entity);
|
|
423
480
|
};
|
|
481
|
+
AcPdfRenderer.prototype.offsetRing = function (outer, inner) {
|
|
482
|
+
var area = new AcGeArea2d();
|
|
483
|
+
area.add(new AcGePolyline2d(outer.map(function (point) { return new AcGePoint2d(point.x, point.y); }), true));
|
|
484
|
+
area.add(new AcGePolyline2d(inner.map(function (point) { return new AcGePoint2d(point.x, point.y); }), true));
|
|
485
|
+
return this.area(area);
|
|
486
|
+
};
|
|
424
487
|
AcPdfRenderer.prototype.mtext = function (mtext, style, _delay) {
|
|
425
488
|
var _this = this;
|
|
426
489
|
var _a;
|
|
@@ -456,7 +519,7 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
456
519
|
* not cover its characters so the caller falls back to vector glyphs.
|
|
457
520
|
*/
|
|
458
521
|
AcPdfRenderer.prototype.applyTextLayout = function (entity, mtext, fontName, fill, position) {
|
|
459
|
-
var
|
|
522
|
+
var e_8, _a, e_9, _b, e_10, _c, e_11, _d;
|
|
460
523
|
var _this = this;
|
|
461
524
|
var _e, _f;
|
|
462
525
|
var fonts = this._fonts;
|
|
@@ -492,28 +555,28 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
492
555
|
for (var _g = __values(layout.lines), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
493
556
|
var line = _h.value;
|
|
494
557
|
try {
|
|
495
|
-
for (var _j = (
|
|
558
|
+
for (var _j = (e_9 = void 0, __values(line.runs)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
496
559
|
var run = _k.value;
|
|
497
560
|
if (run.text !== '' && !fonts.covers(fontFor(run.font), run.text)) {
|
|
498
561
|
return false;
|
|
499
562
|
}
|
|
500
563
|
}
|
|
501
564
|
}
|
|
502
|
-
catch (
|
|
565
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
503
566
|
finally {
|
|
504
567
|
try {
|
|
505
568
|
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
506
569
|
}
|
|
507
|
-
finally { if (
|
|
570
|
+
finally { if (e_9) throw e_9.error; }
|
|
508
571
|
}
|
|
509
572
|
}
|
|
510
573
|
}
|
|
511
|
-
catch (
|
|
574
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
512
575
|
finally {
|
|
513
576
|
try {
|
|
514
577
|
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
515
578
|
}
|
|
516
|
-
finally { if (
|
|
579
|
+
finally { if (e_8) throw e_8.error; }
|
|
517
580
|
}
|
|
518
581
|
// Text plane frame. libredwg leaves MTEXT `rotation` at 0 and encodes the
|
|
519
582
|
// real angle in the direction vector, so derive the baseline angle from a
|
|
@@ -542,7 +605,7 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
542
605
|
for (var _l = __values(layout.lines), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
543
606
|
var line = _m.value;
|
|
544
607
|
var _loop_1 = function (run) {
|
|
545
|
-
var
|
|
608
|
+
var e_12, _q;
|
|
546
609
|
var x = line.dx + run.dx;
|
|
547
610
|
var y = line.dy + run.dy;
|
|
548
611
|
if (run.text !== '') {
|
|
@@ -605,7 +668,7 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
605
668
|
corners.push({ x: x + run.bar.dx0, y: by }, { x: x + run.bar.dx1, y: by });
|
|
606
669
|
}
|
|
607
670
|
try {
|
|
608
|
-
for (var corners_1 = (
|
|
671
|
+
for (var corners_1 = (e_12 = void 0, __values(corners)), corners_1_1 = corners_1.next(); !corners_1_1.done; corners_1_1 = corners_1.next()) {
|
|
609
672
|
var corner = corners_1_1.value;
|
|
610
673
|
entity.box.expandByPoint({
|
|
611
674
|
x: corner.x * cos + corner.y * upX,
|
|
@@ -613,36 +676,36 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
613
676
|
});
|
|
614
677
|
}
|
|
615
678
|
}
|
|
616
|
-
catch (
|
|
679
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
617
680
|
finally {
|
|
618
681
|
try {
|
|
619
682
|
if (corners_1_1 && !corners_1_1.done && (_q = corners_1.return)) _q.call(corners_1);
|
|
620
683
|
}
|
|
621
|
-
finally { if (
|
|
684
|
+
finally { if (e_12) throw e_12.error; }
|
|
622
685
|
}
|
|
623
686
|
}
|
|
624
687
|
};
|
|
625
688
|
try {
|
|
626
|
-
for (var _o = (
|
|
689
|
+
for (var _o = (e_11 = void 0, __values(line.runs)), _p = _o.next(); !_p.done; _p = _o.next()) {
|
|
627
690
|
var run = _p.value;
|
|
628
691
|
_loop_1(run);
|
|
629
692
|
}
|
|
630
693
|
}
|
|
631
|
-
catch (
|
|
694
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
632
695
|
finally {
|
|
633
696
|
try {
|
|
634
697
|
if (_p && !_p.done && (_d = _o.return)) _d.call(_o);
|
|
635
698
|
}
|
|
636
|
-
finally { if (
|
|
699
|
+
finally { if (e_11) throw e_11.error; }
|
|
637
700
|
}
|
|
638
701
|
}
|
|
639
702
|
}
|
|
640
|
-
catch (
|
|
703
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
641
704
|
finally {
|
|
642
705
|
try {
|
|
643
706
|
if (_m && !_m.done && (_c = _l.return)) _c.call(_l);
|
|
644
707
|
}
|
|
645
|
-
finally { if (
|
|
708
|
+
finally { if (e_10) throw e_10.error; }
|
|
646
709
|
}
|
|
647
710
|
entity.applyMatrix(new AcGeMatrix3d().makeTranslation(position.x, position.y, 0));
|
|
648
711
|
return true;
|
|
@@ -678,7 +741,13 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
678
741
|
? result.actualText || stripMtextCodes(contents)
|
|
679
742
|
: undefined
|
|
680
743
|
};
|
|
681
|
-
|
|
744
|
+
// Empty results are usually "font not ready yet"; caching them would
|
|
745
|
+
// permanently suppress every later instance with the same key.
|
|
746
|
+
var hasGeometry = entry.primitives.triangles.length >= 6 ||
|
|
747
|
+
entry.primitives.polylines.length >= 2;
|
|
748
|
+
if (hasGeometry) {
|
|
749
|
+
_this._mtextGlyphCache.set(key, entry);
|
|
750
|
+
}
|
|
682
751
|
return entry;
|
|
683
752
|
});
|
|
684
753
|
this.trackGlyphInflight(this._mtextGlyphInflight, key, render);
|
|
@@ -864,78 +933,39 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
864
933
|
return __assign({ insunits: this._insunits, background: this._pageBackground, title: this._title, paper: this._paper, marginMm: this._marginMm, fitBox: this._fitBox, embedTextActualText: this._embedTextActualText, fonts: this._fonts }, overrides);
|
|
865
934
|
};
|
|
866
935
|
AcPdfRenderer.prototype.appendStrokedPoints = function (entity, pts, style) {
|
|
867
|
-
var
|
|
868
|
-
var _c;
|
|
936
|
+
var e_13, _a, e_14, _b;
|
|
869
937
|
var pattern = this._subEntityTraits.lineType.pattern;
|
|
870
938
|
if (isComplexLineType(pattern) && pattern) {
|
|
871
939
|
var scale = this._ltscale *
|
|
872
940
|
this._celtscale *
|
|
873
941
|
this._subEntityTraits.lineTypeScale;
|
|
874
942
|
var walked = walkLineType(pts, pattern, scale);
|
|
875
|
-
var
|
|
943
|
+
var dashless = __assign(__assign({}, style), { dashArray: undefined });
|
|
876
944
|
try {
|
|
877
|
-
for (var
|
|
878
|
-
var stroke =
|
|
879
|
-
entity.addOp({ kind: 'stroke', points: stroke, style:
|
|
945
|
+
for (var _c = __values(walked.strokes), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
946
|
+
var stroke = _d.value;
|
|
947
|
+
entity.addOp({ kind: 'stroke', points: stroke, style: dashless });
|
|
880
948
|
}
|
|
881
949
|
}
|
|
882
|
-
catch (
|
|
950
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
883
951
|
finally {
|
|
884
952
|
try {
|
|
885
|
-
if (
|
|
953
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
886
954
|
}
|
|
887
|
-
finally { if (
|
|
955
|
+
finally { if (e_13) throw e_13.error; }
|
|
888
956
|
}
|
|
889
|
-
var _loop_2 = function (shape) {
|
|
890
|
-
var ds = Math.max(style.lineWidth, 0.5) * 2;
|
|
891
|
-
entity.addOp({
|
|
892
|
-
kind: 'stroke',
|
|
893
|
-
points: [
|
|
894
|
-
{ x: shape.x, y: shape.y },
|
|
895
|
-
{
|
|
896
|
-
x: shape.x + Math.cos(shape.angle) * ds,
|
|
897
|
-
y: shape.y + Math.sin(shape.angle) * ds
|
|
898
|
-
}
|
|
899
|
-
],
|
|
900
|
-
style: dashless_1
|
|
901
|
-
});
|
|
902
|
-
if (this_1._glyphProvider && (shape.element.shapeName || shape.element.text)) {
|
|
903
|
-
var pending_3 = Promise.resolve(this_1._glyphProvider.renderShape({
|
|
904
|
-
position: { x: shape.x, y: shape.y, z: 0 },
|
|
905
|
-
size: (_c = shape.element.scale) !== null && _c !== void 0 ? _c : ds,
|
|
906
|
-
rotation: shape.angle,
|
|
907
|
-
name: shape.element.shapeName,
|
|
908
|
-
shapeNumber: shape.element.shapeNumber,
|
|
909
|
-
widthFactor: 1,
|
|
910
|
-
obliqingAngle: 0
|
|
911
|
-
}, undefined)).then(function (result) {
|
|
912
|
-
// Glyph geometry is text-local; this entity mixes world-space
|
|
913
|
-
// stroke marks, so paint the glyph through a child entity that
|
|
914
|
-
// carries the placement translation on its own matrix.
|
|
915
|
-
var glyphNode = new AcPdfEntity();
|
|
916
|
-
applyGlyphs(glyphNode, result.primitives, result.box, dashless_1, {
|
|
917
|
-
rgb: dashless_1.rgb,
|
|
918
|
-
opacity: dashless_1.opacity
|
|
919
|
-
});
|
|
920
|
-
glyphNode.applyMatrix(new AcGeMatrix3d().makeTranslation(shape.x, shape.y, 0));
|
|
921
|
-
entity.addChild(glyphNode);
|
|
922
|
-
});
|
|
923
|
-
this_1._pending.push(pending_3);
|
|
924
|
-
}
|
|
925
|
-
};
|
|
926
|
-
var this_1 = this;
|
|
927
957
|
try {
|
|
928
|
-
for (var
|
|
929
|
-
var
|
|
930
|
-
|
|
958
|
+
for (var _e = __values(walked.placements), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
959
|
+
var placement = _f.value;
|
|
960
|
+
this.appendComplexLineTypePlacement(entity, placement, scale, dashless);
|
|
931
961
|
}
|
|
932
962
|
}
|
|
933
|
-
catch (
|
|
963
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
934
964
|
finally {
|
|
935
965
|
try {
|
|
936
|
-
if (
|
|
966
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
937
967
|
}
|
|
938
|
-
finally { if (
|
|
968
|
+
finally { if (e_14) throw e_14.error; }
|
|
939
969
|
}
|
|
940
970
|
return;
|
|
941
971
|
}
|
|
@@ -943,6 +973,142 @@ var AcPdfRenderer = /** @class */ (function () {
|
|
|
943
973
|
entity.addOp({ kind: 'stroke', points: pts, style: style });
|
|
944
974
|
}
|
|
945
975
|
};
|
|
976
|
+
/**
|
|
977
|
+
* Injects TEXT/SHAPE glyphs for one complex-linetype placement.
|
|
978
|
+
*
|
|
979
|
+
* Matches {@link AcTrComplexLineBuilder}: TEXT via MiddleCenter MTEXT,
|
|
980
|
+
* SHAPE via shape glyphs, with LibreDWG blank-text description fallback.
|
|
981
|
+
*/
|
|
982
|
+
AcPdfRenderer.prototype.appendComplexLineTypePlacement = function (entity, placement, lineTypeScale, dashless) {
|
|
983
|
+
var _a;
|
|
984
|
+
var provider = this._glyphProvider;
|
|
985
|
+
if (!provider) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
var flag = placement.element.elementTypeFlag;
|
|
989
|
+
var size = Math.max(((_a = placement.element.scale) !== null && _a !== void 0 ? _a : 0.1) * lineTypeScale, 1e-6);
|
|
990
|
+
var textStyle = this.resolveComplexLineTypeTextStyle(placement);
|
|
991
|
+
var fill = AcPdfStyleUtil.fillStyle(this._subEntityTraits, this.styleContext);
|
|
992
|
+
if (isComplexTextElement(flag)) {
|
|
993
|
+
var text = resolveLinetypeEmbeddedText(placement.element.text, this._subEntityTraits.lineType.description);
|
|
994
|
+
if (text.trim().length === 0) {
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
var mtext = {
|
|
998
|
+
text: text,
|
|
999
|
+
height: size,
|
|
1000
|
+
width: 0,
|
|
1001
|
+
position: { x: placement.x, y: placement.y, z: 0 },
|
|
1002
|
+
rotation: placement.angle,
|
|
1003
|
+
attachmentPoint: AcGiMTextAttachmentPoint.MiddleCenter,
|
|
1004
|
+
widthFactor: textStyle.widthFactor || 1
|
|
1005
|
+
};
|
|
1006
|
+
var mapped = this.resolveStyle(textStyle);
|
|
1007
|
+
// Embedded labels are only a fraction of a unit tall. The page minimum
|
|
1008
|
+
// stroke is often thicker than the letter, so SHX strokes become blobs
|
|
1009
|
+
// that stay blocky at any zoom. Real PDF text is resolution-independent;
|
|
1010
|
+
// the vector fallback uses a width proportional to the text height.
|
|
1011
|
+
var glyphStroke = __assign(__assign({}, dashless), { lineWidth: size * 0.06, exactWidth: true });
|
|
1012
|
+
var pending_3 = this.paintComplexLineTypeText(entity, mtext, mapped, fill, glyphStroke, provider);
|
|
1013
|
+
this._pending.push(pending_3);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (isComplexShapeElement(flag) ||
|
|
1017
|
+
placement.element.shapeNumber != null ||
|
|
1018
|
+
placement.element.shapeName) {
|
|
1019
|
+
var shape = {
|
|
1020
|
+
name: placement.element.shapeName,
|
|
1021
|
+
shapeNumber: placement.element.shapeNumber,
|
|
1022
|
+
size: size,
|
|
1023
|
+
position: { x: placement.x, y: placement.y, z: 0 },
|
|
1024
|
+
rotation: placement.angle,
|
|
1025
|
+
widthFactor: textStyle.widthFactor || 1
|
|
1026
|
+
};
|
|
1027
|
+
var mapped = this.resolveStyle(textStyle);
|
|
1028
|
+
var glyphStroke_1 = __assign(__assign({}, dashless), { lineWidth: size * 0.06, exactWidth: true });
|
|
1029
|
+
var pending_4 = Promise.resolve(provider.renderShape(shape, mapped)).then(function (result) {
|
|
1030
|
+
var glyphNode = new AcPdfEntity();
|
|
1031
|
+
applyGlyphs(glyphNode, result.primitives, result.box, glyphStroke_1, fill);
|
|
1032
|
+
glyphNode.applyMatrix(new AcGeMatrix3d().makeTranslation(placement.x, placement.y, 0));
|
|
1033
|
+
entity.addChild(glyphNode);
|
|
1034
|
+
});
|
|
1035
|
+
this._pending.push(pending_4);
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
/**
|
|
1039
|
+
* Paints one linetype TEXT placement.
|
|
1040
|
+
*
|
|
1041
|
+
* Prefers real PDF text (resolution-independent). Falls back to the glyph
|
|
1042
|
+
* provider when the font cannot be embedded (typical for SHX).
|
|
1043
|
+
*/
|
|
1044
|
+
AcPdfRenderer.prototype.paintComplexLineTypeText = function (entity, mtext, style, fill, glyphStroke, provider) {
|
|
1045
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1046
|
+
var position, ok, textNode, result, glyphNode;
|
|
1047
|
+
return __generator(this, function (_a) {
|
|
1048
|
+
switch (_a.label) {
|
|
1049
|
+
case 0:
|
|
1050
|
+
position = { x: mtext.position.x, y: mtext.position.y };
|
|
1051
|
+
if (!(this._textMode === 'text' && this._fonts)) return [3 /*break*/, 2];
|
|
1052
|
+
return [4 /*yield*/, this._fonts.load(style.font)];
|
|
1053
|
+
case 1:
|
|
1054
|
+
ok = _a.sent();
|
|
1055
|
+
if (ok) {
|
|
1056
|
+
textNode = new AcPdfEntity();
|
|
1057
|
+
if (this.applyTextLayout(textNode, mtext, style.font, fill, position)) {
|
|
1058
|
+
entity.addChild(textNode);
|
|
1059
|
+
return [2 /*return*/];
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
_a.label = 2;
|
|
1063
|
+
case 2: return [4 /*yield*/, provider.renderMText(mtext, style)];
|
|
1064
|
+
case 3:
|
|
1065
|
+
result = _a.sent();
|
|
1066
|
+
glyphNode = new AcPdfEntity();
|
|
1067
|
+
applyGlyphs(glyphNode, result.primitives, result.box, glyphStroke, fill);
|
|
1068
|
+
glyphNode.applyMatrix(new AcGeMatrix3d().makeTranslation(position.x, position.y, 0));
|
|
1069
|
+
entity.addChild(glyphNode);
|
|
1070
|
+
return [2 /*return*/];
|
|
1071
|
+
}
|
|
1072
|
+
});
|
|
1073
|
+
});
|
|
1074
|
+
};
|
|
1075
|
+
AcPdfRenderer.prototype.resolveComplexLineTypeTextStyle = function (placement) {
|
|
1076
|
+
var _a;
|
|
1077
|
+
var empty = {
|
|
1078
|
+
name: '',
|
|
1079
|
+
standardFlag: 0,
|
|
1080
|
+
fixedTextHeight: 0,
|
|
1081
|
+
widthFactor: 1,
|
|
1082
|
+
obliqueAngle: 0,
|
|
1083
|
+
textGenerationFlag: 0,
|
|
1084
|
+
lastHeight: 0,
|
|
1085
|
+
font: '',
|
|
1086
|
+
bigFont: '',
|
|
1087
|
+
extendedFont: ''
|
|
1088
|
+
};
|
|
1089
|
+
var database = this._context.database;
|
|
1090
|
+
var styleObjectId = placement.element.styleObjectId;
|
|
1091
|
+
if (database && styleObjectId) {
|
|
1092
|
+
var record = database.openObjectForRead(styleObjectId);
|
|
1093
|
+
if (record === null || record === void 0 ? void 0 : record.textStyle) {
|
|
1094
|
+
return __assign({}, record.textStyle);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
var styleName = (_a = placement.element.style) === null || _a === void 0 ? void 0 : _a.trim();
|
|
1098
|
+
if (database && styleName) {
|
|
1099
|
+
var record = database.tables.textStyleTable.getAt(styleName);
|
|
1100
|
+
if (record === null || record === void 0 ? void 0 : record.textStyle) {
|
|
1101
|
+
return __assign({}, record.textStyle);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
if (database) {
|
|
1105
|
+
var standard = database.tables.textStyleTable.getAt('Standard');
|
|
1106
|
+
if (standard === null || standard === void 0 ? void 0 : standard.textStyle) {
|
|
1107
|
+
return __assign({}, standard.textStyle);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
return empty;
|
|
1111
|
+
};
|
|
946
1112
|
AcPdfRenderer.prototype.pushStrokedPolyline = function (points, box) {
|
|
947
1113
|
var entity = new AcPdfEntity();
|
|
948
1114
|
var pts = toPdfPoints(points);
|
|
@@ -1035,7 +1201,7 @@ function applyGlyphs(entity, primitives, box, strokeStyle, fillStyle) {
|
|
|
1035
1201
|
function blobToImageOp(blob, style) {
|
|
1036
1202
|
return __awaiter(this, void 0, void 0, function () {
|
|
1037
1203
|
var boundary, type, format, raster, converted, minX, minY, maxX, maxY, boundary_1, boundary_1_1, pt, bytes, _a;
|
|
1038
|
-
var
|
|
1204
|
+
var e_15, _b;
|
|
1039
1205
|
return __generator(this, function (_c) {
|
|
1040
1206
|
switch (_c.label) {
|
|
1041
1207
|
case 0:
|
|
@@ -1078,12 +1244,12 @@ function blobToImageOp(blob, style) {
|
|
|
1078
1244
|
maxY = Math.max(maxY, pt.y);
|
|
1079
1245
|
}
|
|
1080
1246
|
}
|
|
1081
|
-
catch (
|
|
1247
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
1082
1248
|
finally {
|
|
1083
1249
|
try {
|
|
1084
1250
|
if (boundary_1_1 && !boundary_1_1.done && (_b = boundary_1.return)) _b.call(boundary_1);
|
|
1085
1251
|
}
|
|
1086
|
-
finally { if (
|
|
1252
|
+
finally { if (e_15) throw e_15.error; }
|
|
1087
1253
|
}
|
|
1088
1254
|
_a = Uint8Array.bind;
|
|
1089
1255
|
return [4 /*yield*/, raster.arrayBuffer()];
|