@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,1188 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var __values = (this && this.__values) || function(o) {
|
|
49
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
50
|
+
if (m) return m.call(o);
|
|
51
|
+
if (o && typeof o.length === "number") return {
|
|
52
|
+
next: function () {
|
|
53
|
+
if (o && i >= o.length) o = void 0;
|
|
54
|
+
return { value: o && o[i++], done: !o };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
58
|
+
};
|
|
59
|
+
import { AcCmColor, AcCmTransparency, acdbDrawTessellateOptions, acdbRasterizeOleMetafile, AcDbRenderingCache, AcGeMatrix3d, ACGI_DARK_THEME_FOREGROUND, ACGI_LIGHT_THEME_FOREGROUND, AcGiContext, acgiIsLightBackground, AcGiLineWeight } from '@mlightcad/data-model';
|
|
60
|
+
import { shadingFromGradient } from '../hatch/AcPdfGradient';
|
|
61
|
+
import { tessellateHatchPattern } from '../hatch/AcPdfHatchTessellator';
|
|
62
|
+
import { isComplexLineType, walkLineType } from '../linetype/AcPdfLineTypeStroker';
|
|
63
|
+
import { AcPdfDocumentWriter } from '../pdf/AcPdfDocumentWriter';
|
|
64
|
+
import { stripMtextCodes } from '../pdf/AcPdfMarkedContent';
|
|
65
|
+
import { AcPdfEntity } from './AcPdfEntity';
|
|
66
|
+
import { AcPdfGroup } from './AcPdfGroup';
|
|
67
|
+
import { AcPdfStyleUtil } from './AcPdfStyleUtil';
|
|
68
|
+
import { ASCENT_RATIO, DESCENT_RATIO, layoutMText, OVERLINE_OFFSET_RATIO, STRIKE_OFFSET_RATIO, UNDERLINE_OFFSET_RATIO } from './AcPdfTextLayout';
|
|
69
|
+
var DEFAULT_POINT_RADIUS = 0.5;
|
|
70
|
+
/**
|
|
71
|
+
* AcGi backend that records vector drawables for PDF serialization.
|
|
72
|
+
*/
|
|
73
|
+
var AcPdfRenderer = /** @class */ (function () {
|
|
74
|
+
function AcPdfRenderer() {
|
|
75
|
+
this._entities = [];
|
|
76
|
+
this._fontMapping = {};
|
|
77
|
+
this._ltscale = 1;
|
|
78
|
+
this._celtscale = 1;
|
|
79
|
+
this._currentBackgroundColor = 0xffffff;
|
|
80
|
+
this._foregroundColor = 0x000000;
|
|
81
|
+
this._showLineWeight = false;
|
|
82
|
+
this._insunits = 4;
|
|
83
|
+
this._pageBackground = 'none';
|
|
84
|
+
this._embedTextActualText = true;
|
|
85
|
+
/** `'text'` paints MTEXT/TEXT as real PDF text through `_fonts`. */
|
|
86
|
+
this._textMode = 'vector';
|
|
87
|
+
this._pending = [];
|
|
88
|
+
/**
|
|
89
|
+
* Reuses rendered glyph primitives for identical text content + style.
|
|
90
|
+
*
|
|
91
|
+
* ATTRIB texts render once per INSERT instance, so drawings with thousands
|
|
92
|
+
* of block references carrying the same attribute values re-tessellate the
|
|
93
|
+
* same glyphs over and over; each result then dominated heap use. Cached
|
|
94
|
+
* entries are shared read-only and re-positioned through a per-entity
|
|
95
|
+
* translation matrix (paint bakes transformed copies, so sharing is safe).
|
|
96
|
+
*/
|
|
97
|
+
this._mtextGlyphCache = new Map();
|
|
98
|
+
this._shapeGlyphCache = new Map();
|
|
99
|
+
this._mtextGlyphInflight = new Map();
|
|
100
|
+
this._shapeGlyphInflight = new Map();
|
|
101
|
+
this._context = AcGiContext.fromBackgroundColor(this._currentBackgroundColor);
|
|
102
|
+
this._subEntityTraits = {
|
|
103
|
+
color: new AcCmColor(),
|
|
104
|
+
lineType: {
|
|
105
|
+
type: 'ByLayer',
|
|
106
|
+
name: 'Continuous',
|
|
107
|
+
standardFlag: 0,
|
|
108
|
+
description: 'Solid line',
|
|
109
|
+
totalPatternLength: 0
|
|
110
|
+
},
|
|
111
|
+
lineTypeScale: 1,
|
|
112
|
+
lineWeight: AcGiLineWeight.ByLayer,
|
|
113
|
+
fillType: {
|
|
114
|
+
solidFill: true,
|
|
115
|
+
patternAngle: 0,
|
|
116
|
+
definitionLines: []
|
|
117
|
+
},
|
|
118
|
+
transparency: new AcCmTransparency(),
|
|
119
|
+
thickness: 0,
|
|
120
|
+
layer: '0',
|
|
121
|
+
drawOrder: 0
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Clears the shared block rendering cache before PDF export.
|
|
126
|
+
*
|
|
127
|
+
* The cache stores drawable objects from the last renderer that populated it
|
|
128
|
+
* (typically Three.js). Reusing those entries during export causes failures
|
|
129
|
+
* when block references are resolved from cache.
|
|
130
|
+
*/
|
|
131
|
+
AcPdfRenderer.prepareExport = function () {
|
|
132
|
+
AcDbRenderingCache.instance.clear();
|
|
133
|
+
};
|
|
134
|
+
Object.defineProperty(AcPdfRenderer.prototype, "subEntityTraits", {
|
|
135
|
+
get: function () {
|
|
136
|
+
return this._subEntityTraits;
|
|
137
|
+
},
|
|
138
|
+
enumerable: false,
|
|
139
|
+
configurable: true
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(AcPdfRenderer.prototype, "context", {
|
|
142
|
+
get: function () {
|
|
143
|
+
return this._context;
|
|
144
|
+
},
|
|
145
|
+
enumerable: false,
|
|
146
|
+
configurable: true
|
|
147
|
+
});
|
|
148
|
+
AcPdfRenderer.prototype.setFontMapping = function (mapping) {
|
|
149
|
+
this._fontMapping = mapping;
|
|
150
|
+
};
|
|
151
|
+
Object.defineProperty(AcPdfRenderer.prototype, "ltscale", {
|
|
152
|
+
set: function (scale) {
|
|
153
|
+
this._ltscale = scale;
|
|
154
|
+
},
|
|
155
|
+
enumerable: false,
|
|
156
|
+
configurable: true
|
|
157
|
+
});
|
|
158
|
+
Object.defineProperty(AcPdfRenderer.prototype, "celtscale", {
|
|
159
|
+
set: function (scale) {
|
|
160
|
+
this._celtscale = scale;
|
|
161
|
+
},
|
|
162
|
+
enumerable: false,
|
|
163
|
+
configurable: true
|
|
164
|
+
});
|
|
165
|
+
Object.defineProperty(AcPdfRenderer.prototype, "currentBackgroundColor", {
|
|
166
|
+
get: function () {
|
|
167
|
+
return this._currentBackgroundColor;
|
|
168
|
+
},
|
|
169
|
+
set: function (value) {
|
|
170
|
+
this._currentBackgroundColor = value;
|
|
171
|
+
this._context.backgroundIsDark = !acgiIsLightBackground(value);
|
|
172
|
+
this._context.foregroundOnDark = ACGI_DARK_THEME_FOREGROUND;
|
|
173
|
+
this._context.foregroundOnLight = ACGI_LIGHT_THEME_FOREGROUND;
|
|
174
|
+
},
|
|
175
|
+
enumerable: false,
|
|
176
|
+
configurable: true
|
|
177
|
+
});
|
|
178
|
+
AcPdfRenderer.prototype.changeForeground = function (color) {
|
|
179
|
+
this._foregroundColor = color;
|
|
180
|
+
};
|
|
181
|
+
Object.defineProperty(AcPdfRenderer.prototype, "showLineWeight", {
|
|
182
|
+
get: function () {
|
|
183
|
+
return this._showLineWeight;
|
|
184
|
+
},
|
|
185
|
+
set: function (value) {
|
|
186
|
+
this._showLineWeight = value;
|
|
187
|
+
},
|
|
188
|
+
enumerable: false,
|
|
189
|
+
configurable: true
|
|
190
|
+
});
|
|
191
|
+
Object.defineProperty(AcPdfRenderer.prototype, "insunits", {
|
|
192
|
+
set: function (value) {
|
|
193
|
+
this._insunits = value;
|
|
194
|
+
},
|
|
195
|
+
enumerable: false,
|
|
196
|
+
configurable: true
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(AcPdfRenderer.prototype, "textFontManager", {
|
|
199
|
+
/** Bound font manager, or `undefined` while the host provided none. */
|
|
200
|
+
get: function () {
|
|
201
|
+
return this._fonts;
|
|
202
|
+
},
|
|
203
|
+
/**
|
|
204
|
+
* Enables `textMode: 'text'` with the document font manager. Called by the
|
|
205
|
+
* export entry point when the host provided a font resolver; text entities
|
|
206
|
+
* then paint as real PDF text when an embeddable, coverage-complete font
|
|
207
|
+
* is available, and fall back to vector glyphs otherwise.
|
|
208
|
+
*/
|
|
209
|
+
set: function (fonts) {
|
|
210
|
+
this._fonts = fonts;
|
|
211
|
+
this._textMode = 'text';
|
|
212
|
+
},
|
|
213
|
+
enumerable: false,
|
|
214
|
+
configurable: true
|
|
215
|
+
});
|
|
216
|
+
AcPdfRenderer.prototype.configureExport = function (options) {
|
|
217
|
+
var _a;
|
|
218
|
+
this._title = options.title;
|
|
219
|
+
this._paper = options.paper;
|
|
220
|
+
this._marginMm = options.marginMm;
|
|
221
|
+
this._pageBackground = (_a = options.background) !== null && _a !== void 0 ? _a : 'none';
|
|
222
|
+
this._glyphProvider = options.glyphProvider;
|
|
223
|
+
this._fitBox = options.fitBox;
|
|
224
|
+
this._embedTextActualText = options.embedTextActualText !== false;
|
|
225
|
+
this._textMode = options.textMode === 'text' ? 'text' : 'vector';
|
|
226
|
+
if (options.fontMapping) {
|
|
227
|
+
this.setFontMapping(options.fontMapping);
|
|
228
|
+
}
|
|
229
|
+
if (options.ltscale != null) {
|
|
230
|
+
this.ltscale = options.ltscale;
|
|
231
|
+
}
|
|
232
|
+
if (options.celtscale != null) {
|
|
233
|
+
this.celtscale = options.celtscale;
|
|
234
|
+
}
|
|
235
|
+
if (options.showLineWeight != null) {
|
|
236
|
+
this.showLineWeight = options.showLineWeight;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
Object.defineProperty(AcPdfRenderer.prototype, "styleContext", {
|
|
240
|
+
get: function () {
|
|
241
|
+
return {
|
|
242
|
+
ltscale: this._ltscale,
|
|
243
|
+
celtscale: this._celtscale,
|
|
244
|
+
backgroundColor: this._currentBackgroundColor,
|
|
245
|
+
foregroundColor: this._foregroundColor,
|
|
246
|
+
showLineWeight: this._showLineWeight,
|
|
247
|
+
insunits: this._insunits
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
enumerable: false,
|
|
251
|
+
configurable: true
|
|
252
|
+
});
|
|
253
|
+
AcPdfRenderer.prototype.pushEntity = function (entity) {
|
|
254
|
+
var _a;
|
|
255
|
+
entity.drawOrder = (_a = this._subEntityTraits.drawOrder) !== null && _a !== void 0 ? _a : 0;
|
|
256
|
+
if (!entity.layerName) {
|
|
257
|
+
entity.layerName = this._subEntityTraits.layer;
|
|
258
|
+
}
|
|
259
|
+
this._entities.push(entity);
|
|
260
|
+
return entity;
|
|
261
|
+
};
|
|
262
|
+
AcPdfRenderer.prototype.removeEntities = function (entities) {
|
|
263
|
+
var e_1, _a;
|
|
264
|
+
try {
|
|
265
|
+
for (var entities_1 = __values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
|
|
266
|
+
var entity = entities_1_1.value;
|
|
267
|
+
var index = this._entities.indexOf(entity);
|
|
268
|
+
if (index >= 0) {
|
|
269
|
+
this._entities.splice(index, 1);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
274
|
+
finally {
|
|
275
|
+
try {
|
|
276
|
+
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
277
|
+
}
|
|
278
|
+
finally { if (e_1) throw e_1.error; }
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
AcPdfRenderer.prototype.group = function (entities) {
|
|
282
|
+
this.removeEntities(entities);
|
|
283
|
+
return this.pushEntity(new AcPdfGroup(entities));
|
|
284
|
+
};
|
|
285
|
+
AcPdfRenderer.prototype.point = function (point, style) {
|
|
286
|
+
var entity = new AcPdfEntity();
|
|
287
|
+
var r = style.displaySize > 0 ? style.displaySize / 2 : DEFAULT_POINT_RADIUS;
|
|
288
|
+
entity.addOp({
|
|
289
|
+
kind: 'circle',
|
|
290
|
+
x: point.x,
|
|
291
|
+
y: point.y,
|
|
292
|
+
r: r,
|
|
293
|
+
style: AcPdfStyleUtil.pointStyle(this._subEntityTraits, this.styleContext)
|
|
294
|
+
});
|
|
295
|
+
entity.box.expandByPoint({ x: point.x - r, y: point.y - r });
|
|
296
|
+
entity.box.expandByPoint({ x: point.x + r, y: point.y + r });
|
|
297
|
+
return this.pushEntity(entity);
|
|
298
|
+
};
|
|
299
|
+
AcPdfRenderer.prototype.circularArc = function (arc) {
|
|
300
|
+
return this.pushStrokedPolyline(arc.tessellate(acdbDrawTessellateOptions(this)), arc.box);
|
|
301
|
+
};
|
|
302
|
+
AcPdfRenderer.prototype.ellipticalArc = function (ellipseArc) {
|
|
303
|
+
return this.pushStrokedPolyline(ellipseArc.tessellate(acdbDrawTessellateOptions(this)), ellipseArc.box);
|
|
304
|
+
};
|
|
305
|
+
AcPdfRenderer.prototype.lines = function (points) {
|
|
306
|
+
var e_2, _a;
|
|
307
|
+
var entity = new AcPdfEntity();
|
|
308
|
+
var pts = toPdfPoints(points);
|
|
309
|
+
var style = AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext);
|
|
310
|
+
this.appendStrokedPoints(entity, pts, style);
|
|
311
|
+
try {
|
|
312
|
+
for (var pts_1 = __values(pts), pts_1_1 = pts_1.next(); !pts_1_1.done; pts_1_1 = pts_1.next()) {
|
|
313
|
+
var p = pts_1_1.value;
|
|
314
|
+
entity.box.expandByPoint(p);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
318
|
+
finally {
|
|
319
|
+
try {
|
|
320
|
+
if (pts_1_1 && !pts_1_1.done && (_a = pts_1.return)) _a.call(pts_1);
|
|
321
|
+
}
|
|
322
|
+
finally { if (e_2) throw e_2.error; }
|
|
323
|
+
}
|
|
324
|
+
return this.pushEntity(entity);
|
|
325
|
+
};
|
|
326
|
+
AcPdfRenderer.prototype.lineSegments = function (array, itemSize, indices) {
|
|
327
|
+
var entity = new AcPdfEntity();
|
|
328
|
+
var style = AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext);
|
|
329
|
+
for (var i = 0; i + 1 < indices.length; i += 2) {
|
|
330
|
+
var ai = indices[i] * itemSize;
|
|
331
|
+
var bi = indices[i + 1] * itemSize;
|
|
332
|
+
var a = { x: array[ai], y: array[ai + 1] };
|
|
333
|
+
var b = { x: array[bi], y: array[bi + 1] };
|
|
334
|
+
entity.addOp({ kind: 'stroke', points: [a, b], style: style });
|
|
335
|
+
entity.box.expandByPoint(a);
|
|
336
|
+
entity.box.expandByPoint(b);
|
|
337
|
+
}
|
|
338
|
+
return this.pushEntity(entity);
|
|
339
|
+
};
|
|
340
|
+
AcPdfRenderer.prototype.area = function (area) {
|
|
341
|
+
var e_3, _a, e_4, _b, e_5, _c;
|
|
342
|
+
var _d, _e;
|
|
343
|
+
var entity = new AcPdfEntity();
|
|
344
|
+
var loops = area.tessellate(acdbDrawTessellateOptions(this));
|
|
345
|
+
var pdfLoops = [];
|
|
346
|
+
try {
|
|
347
|
+
for (var loops_1 = __values(loops), loops_1_1 = loops_1.next(); !loops_1_1.done; loops_1_1 = loops_1.next()) {
|
|
348
|
+
var loop = loops_1_1.value;
|
|
349
|
+
if (loop.length === 0) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
var pts = toPdfPoints(loop);
|
|
353
|
+
pdfLoops.push(pts);
|
|
354
|
+
try {
|
|
355
|
+
for (var pts_2 = (e_4 = void 0, __values(pts)), pts_2_1 = pts_2.next(); !pts_2_1.done; pts_2_1 = pts_2.next()) {
|
|
356
|
+
var p = pts_2_1.value;
|
|
357
|
+
entity.box.expandByPoint(p);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
361
|
+
finally {
|
|
362
|
+
try {
|
|
363
|
+
if (pts_2_1 && !pts_2_1.done && (_b = pts_2.return)) _b.call(pts_2);
|
|
364
|
+
}
|
|
365
|
+
finally { if (e_4) throw e_4.error; }
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
370
|
+
finally {
|
|
371
|
+
try {
|
|
372
|
+
if (loops_1_1 && !loops_1_1.done && (_a = loops_1.return)) _a.call(loops_1);
|
|
373
|
+
}
|
|
374
|
+
finally { if (e_3) throw e_3.error; }
|
|
375
|
+
}
|
|
376
|
+
var style = AcPdfStyleUtil.fillStyle(this._subEntityTraits, this.styleContext);
|
|
377
|
+
var fillType = this._subEntityTraits.fillType;
|
|
378
|
+
if (pdfLoops.length > 0 && fillType.gradient) {
|
|
379
|
+
var packed = (Math.round(style.rgb.r * 255) << 16) |
|
|
380
|
+
(Math.round(style.rgb.g * 255) << 8) |
|
|
381
|
+
Math.round(style.rgb.b * 255);
|
|
382
|
+
var shading = shadingFromGradient(fillType.gradient, pdfLoops, packed);
|
|
383
|
+
entity.addOp({
|
|
384
|
+
kind: 'gradient',
|
|
385
|
+
loops: pdfLoops,
|
|
386
|
+
shadingType: shading.shadingType,
|
|
387
|
+
coords: shading.coords,
|
|
388
|
+
c0: shading.c0,
|
|
389
|
+
c1: shading.c1,
|
|
390
|
+
strips: shading.strips,
|
|
391
|
+
style: style
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
else if (pdfLoops.length > 0 &&
|
|
395
|
+
!fillType.solidFill &&
|
|
396
|
+
((_d = fillType.definitionLines) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
397
|
+
var segments = tessellateHatchPattern(pdfLoops, fillType.definitionLines, (_e = fillType.patternAngle) !== null && _e !== void 0 ? _e : 0);
|
|
398
|
+
var stroke = AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext);
|
|
399
|
+
stroke.rgb = style.rgb;
|
|
400
|
+
stroke.dashArray = undefined;
|
|
401
|
+
try {
|
|
402
|
+
for (var segments_1 = __values(segments), segments_1_1 = segments_1.next(); !segments_1_1.done; segments_1_1 = segments_1.next()) {
|
|
403
|
+
var segment = segments_1_1.value;
|
|
404
|
+
entity.addOp({ kind: 'stroke', points: segment, style: stroke });
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
408
|
+
finally {
|
|
409
|
+
try {
|
|
410
|
+
if (segments_1_1 && !segments_1_1.done && (_c = segments_1.return)) _c.call(segments_1);
|
|
411
|
+
}
|
|
412
|
+
finally { if (e_5) throw e_5.error; }
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
else if (pdfLoops.length > 0) {
|
|
416
|
+
entity.addOp({
|
|
417
|
+
kind: 'fill',
|
|
418
|
+
loops: pdfLoops,
|
|
419
|
+
style: style
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
return this.pushEntity(entity);
|
|
423
|
+
};
|
|
424
|
+
AcPdfRenderer.prototype.mtext = function (mtext, style, _delay) {
|
|
425
|
+
var _this = this;
|
|
426
|
+
var _a;
|
|
427
|
+
var entity = new AcPdfEntity();
|
|
428
|
+
var mapped = this.resolveStyle(style);
|
|
429
|
+
var fill = AcPdfStyleUtil.fillStyle(this._subEntityTraits, this.styleContext);
|
|
430
|
+
var stroke = AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext);
|
|
431
|
+
// Capture synchronously: the source entity may move before promises resolve.
|
|
432
|
+
var position = { x: mtext.position.x, y: mtext.position.y };
|
|
433
|
+
if (this._textMode === 'text' && this._fonts) {
|
|
434
|
+
var fonts = this._fonts;
|
|
435
|
+
var fontName_1 = mapped.font;
|
|
436
|
+
var contents = (_a = mtext.text) !== null && _a !== void 0 ? _a : '';
|
|
437
|
+
if (contents.trim() !== '') {
|
|
438
|
+
var pending_1 = Promise.resolve(fonts.load(fontName_1)).then(function (ok) {
|
|
439
|
+
if (ok &&
|
|
440
|
+
_this.applyTextLayout(entity, mtext, fontName_1, fill, position)) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
// No embeddable program or the font misses glyphs: vector glyphs.
|
|
444
|
+
_this.applyVectorMtext(entity, mtext, mapped, fill, stroke, position);
|
|
445
|
+
});
|
|
446
|
+
this._pending.push(pending_1);
|
|
447
|
+
return this.pushEntity(entity);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
this.applyVectorMtext(entity, mtext, mapped, fill, stroke, position);
|
|
451
|
+
return this.pushEntity(entity);
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Lays `mtext` out as real PDF text runs (entity-local, then translated
|
|
455
|
+
* to `position`). Returns `false` when a laid-out run's mapped font does
|
|
456
|
+
* not cover its characters so the caller falls back to vector glyphs.
|
|
457
|
+
*/
|
|
458
|
+
AcPdfRenderer.prototype.applyTextLayout = function (entity, mtext, fontName, fill, position) {
|
|
459
|
+
var e_6, _a, e_7, _b, e_8, _c, e_9, _d;
|
|
460
|
+
var _this = this;
|
|
461
|
+
var _e, _f;
|
|
462
|
+
var fonts = this._fonts;
|
|
463
|
+
if (!fonts) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
// Run fonts (`\F`) map through the font-mapping table like entity fonts;
|
|
467
|
+
// unloaded run fonts measure through the entity font so line math stays
|
|
468
|
+
// stable (the per-run covers check below still rejects the entity then).
|
|
469
|
+
var measure = function (text, size, font) {
|
|
470
|
+
var _a;
|
|
471
|
+
if (font) {
|
|
472
|
+
var width = fonts.widthOfText((_a = _this._fontMapping[font]) !== null && _a !== void 0 ? _a : font, text, size);
|
|
473
|
+
if (width !== undefined) {
|
|
474
|
+
return width;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return fonts.widthOfText(fontName, text, size);
|
|
478
|
+
};
|
|
479
|
+
var layout = layoutMText({ data: mtext, measure: measure });
|
|
480
|
+
var joined = layout.lines.map(function (line) { return line.text; }).join('\n');
|
|
481
|
+
if (joined.trim() === '') {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
// Every run must paint: a missing or glyph-incomplete run font falls
|
|
485
|
+
// back to the entity font; if that misses too, the vector path takes over.
|
|
486
|
+
var fontFor = function (raw) {
|
|
487
|
+
var _a;
|
|
488
|
+
var mapped = raw ? ((_a = _this._fontMapping[raw]) !== null && _a !== void 0 ? _a : raw) : fontName;
|
|
489
|
+
return fonts.has(mapped) ? mapped : fontName;
|
|
490
|
+
};
|
|
491
|
+
try {
|
|
492
|
+
for (var _g = __values(layout.lines), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
493
|
+
var line = _h.value;
|
|
494
|
+
try {
|
|
495
|
+
for (var _j = (e_7 = void 0, __values(line.runs)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
496
|
+
var run = _k.value;
|
|
497
|
+
if (run.text !== '' && !fonts.covers(fontFor(run.font), run.text)) {
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
503
|
+
finally {
|
|
504
|
+
try {
|
|
505
|
+
if (_k && !_k.done && (_b = _j.return)) _b.call(_j);
|
|
506
|
+
}
|
|
507
|
+
finally { if (e_7) throw e_7.error; }
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
512
|
+
finally {
|
|
513
|
+
try {
|
|
514
|
+
if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
|
|
515
|
+
}
|
|
516
|
+
finally { if (e_6) throw e_6.error; }
|
|
517
|
+
}
|
|
518
|
+
// Text plane frame. libredwg leaves MTEXT `rotation` at 0 and encodes the
|
|
519
|
+
// real angle in the direction vector, so derive the baseline angle from a
|
|
520
|
+
// planar direction whenever present. Up = normal × baseline flattened to
|
|
521
|
+
// XY; a negative-Z extrusion (mirrored OCS) makes the projected frame
|
|
522
|
+
// left-handed, rendered as mirrored glyphs through the op's `flipX`.
|
|
523
|
+
var dv = mtext.directionVector;
|
|
524
|
+
var rotation = dv && Math.hypot(dv.x, dv.y) > 1e-9
|
|
525
|
+
? Math.atan2(dv.y, dv.x)
|
|
526
|
+
: ((_e = mtext.rotation) !== null && _e !== void 0 ? _e : 0);
|
|
527
|
+
var rotationDeg = (rotation * 180) / Math.PI;
|
|
528
|
+
// `normal` is typed only in newer data-model revisions (absent from the
|
|
529
|
+
// published ^1.14.6 typings, which also never populate it at runtime) —
|
|
530
|
+
// read it structurally so both revisions compile; when undefined the
|
|
531
|
+
// default +Z normal applies.
|
|
532
|
+
var n = mtext
|
|
533
|
+
.normal;
|
|
534
|
+
var nz = n && (n.x !== 0 || n.y !== 0 || n.z !== 0) ? n.z : 1;
|
|
535
|
+
var cos = Math.cos(rotation);
|
|
536
|
+
var sin = Math.sin(rotation);
|
|
537
|
+
var upX = -nz * sin;
|
|
538
|
+
var upY = nz * cos;
|
|
539
|
+
var flipX = nz < 0;
|
|
540
|
+
var angleDeg = flipX ? rotationDeg + 180 : rotationDeg;
|
|
541
|
+
try {
|
|
542
|
+
for (var _l = __values(layout.lines), _m = _l.next(); !_m.done; _m = _l.next()) {
|
|
543
|
+
var line = _m.value;
|
|
544
|
+
var _loop_1 = function (run) {
|
|
545
|
+
var e_10, _q;
|
|
546
|
+
var x = line.dx + run.dx;
|
|
547
|
+
var y = line.dy + run.dy;
|
|
548
|
+
if (run.text !== '') {
|
|
549
|
+
entity.addOp({
|
|
550
|
+
kind: 'text',
|
|
551
|
+
text: run.text,
|
|
552
|
+
hex: '',
|
|
553
|
+
font: fontFor(run.font),
|
|
554
|
+
size: run.size,
|
|
555
|
+
x: x * cos + y * upX,
|
|
556
|
+
y: x * sin + y * upY,
|
|
557
|
+
angleDeg: angleDeg,
|
|
558
|
+
hScale: run.hScale,
|
|
559
|
+
tracking: run.tracking,
|
|
560
|
+
obliqueDeg: run.obliqueDeg || undefined,
|
|
561
|
+
flipX: flipX,
|
|
562
|
+
style: run.rgb ? __assign(__assign({}, fill), { rgb: run.rgb }) : fill
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
// Stacked-fraction rules and run decorations draw as strokes in the
|
|
566
|
+
// same rotated frame, colored like the run.
|
|
567
|
+
var ruleStyle = {
|
|
568
|
+
rgb: (_f = run.rgb) !== null && _f !== void 0 ? _f : fill.rgb,
|
|
569
|
+
opacity: fill.opacity,
|
|
570
|
+
lineWidth: 0.03 * run.size
|
|
571
|
+
};
|
|
572
|
+
var addRule = function (x0, y0, x1, y1) {
|
|
573
|
+
entity.addOp({
|
|
574
|
+
kind: 'stroke',
|
|
575
|
+
points: [
|
|
576
|
+
{ x: x0 * cos + y0 * upX, y: x0 * sin + y0 * upY },
|
|
577
|
+
{ x: x1 * cos + y1 * upX, y: x1 * sin + y1 * upY }
|
|
578
|
+
],
|
|
579
|
+
style: ruleStyle
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
if (run.bar) {
|
|
583
|
+
addRule(x + run.bar.dx0, y + run.bar.dy, x + run.bar.dx1, y + run.bar.dy);
|
|
584
|
+
}
|
|
585
|
+
if (run.text !== '') {
|
|
586
|
+
if (run.underline) {
|
|
587
|
+
addRule(x, y + UNDERLINE_OFFSET_RATIO * run.size, x + run.width, y + UNDERLINE_OFFSET_RATIO * run.size);
|
|
588
|
+
}
|
|
589
|
+
if (run.overline) {
|
|
590
|
+
addRule(x, y + OVERLINE_OFFSET_RATIO * run.size, x + run.width, y + OVERLINE_OFFSET_RATIO * run.size);
|
|
591
|
+
}
|
|
592
|
+
if (run.strike) {
|
|
593
|
+
addRule(x, y + STRIKE_OFFSET_RATIO * run.size, x + run.width, y + STRIKE_OFFSET_RATIO * run.size);
|
|
594
|
+
}
|
|
595
|
+
var runAscent = run.dy + ASCENT_RATIO * run.size;
|
|
596
|
+
var runDescent = run.dy - DESCENT_RATIO * run.size;
|
|
597
|
+
var corners = [
|
|
598
|
+
{ x: x, y: runDescent },
|
|
599
|
+
{ x: x + run.width, y: runDescent },
|
|
600
|
+
{ x: x + run.width, y: runAscent },
|
|
601
|
+
{ x: x, y: runAscent }
|
|
602
|
+
];
|
|
603
|
+
if (run.bar) {
|
|
604
|
+
var by = y + run.bar.dy;
|
|
605
|
+
corners.push({ x: x + run.bar.dx0, y: by }, { x: x + run.bar.dx1, y: by });
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
for (var corners_1 = (e_10 = void 0, __values(corners)), corners_1_1 = corners_1.next(); !corners_1_1.done; corners_1_1 = corners_1.next()) {
|
|
609
|
+
var corner = corners_1_1.value;
|
|
610
|
+
entity.box.expandByPoint({
|
|
611
|
+
x: corner.x * cos + corner.y * upX,
|
|
612
|
+
y: corner.x * sin + corner.y * upY
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
617
|
+
finally {
|
|
618
|
+
try {
|
|
619
|
+
if (corners_1_1 && !corners_1_1.done && (_q = corners_1.return)) _q.call(corners_1);
|
|
620
|
+
}
|
|
621
|
+
finally { if (e_10) throw e_10.error; }
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
try {
|
|
626
|
+
for (var _o = (e_9 = void 0, __values(line.runs)), _p = _o.next(); !_p.done; _p = _o.next()) {
|
|
627
|
+
var run = _p.value;
|
|
628
|
+
_loop_1(run);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
632
|
+
finally {
|
|
633
|
+
try {
|
|
634
|
+
if (_p && !_p.done && (_d = _o.return)) _d.call(_o);
|
|
635
|
+
}
|
|
636
|
+
finally { if (e_9) throw e_9.error; }
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
641
|
+
finally {
|
|
642
|
+
try {
|
|
643
|
+
if (_m && !_m.done && (_c = _l.return)) _c.call(_l);
|
|
644
|
+
}
|
|
645
|
+
finally { if (e_8) throw e_8.error; }
|
|
646
|
+
}
|
|
647
|
+
entity.applyMatrix(new AcGeMatrix3d().makeTranslation(position.x, position.y, 0));
|
|
648
|
+
return true;
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* Vector-glyph fallback: tessellated text primitives through the glyph
|
|
652
|
+
* provider, deduplicated by content + style (`_mtextGlyphCache`).
|
|
653
|
+
*/
|
|
654
|
+
AcPdfRenderer.prototype.applyVectorMtext = function (entity, mtext, mapped, fill, stroke, position) {
|
|
655
|
+
var _this = this;
|
|
656
|
+
var _a;
|
|
657
|
+
var provider = this._glyphProvider;
|
|
658
|
+
if (!provider) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
var key = mtextGlyphKey(mtext, mapped);
|
|
662
|
+
var cached = this._mtextGlyphCache.get(key);
|
|
663
|
+
if (cached) {
|
|
664
|
+
this.applyCachedGlyphs(entity, cached, position, stroke, fill);
|
|
665
|
+
if (this._embedTextActualText && cached.actualText) {
|
|
666
|
+
entity.actualText = cached.actualText;
|
|
667
|
+
}
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
var contents = (_a = mtext.contents) !== null && _a !== void 0 ? _a : '';
|
|
671
|
+
var inflight = this._mtextGlyphInflight.get(key);
|
|
672
|
+
if (!inflight) {
|
|
673
|
+
var render = Promise.resolve(provider.renderMText(mtext, mapped)).then(function (result) {
|
|
674
|
+
var entry = {
|
|
675
|
+
primitives: result.primitives,
|
|
676
|
+
box: result.box,
|
|
677
|
+
actualText: _this._embedTextActualText
|
|
678
|
+
? result.actualText || stripMtextCodes(contents)
|
|
679
|
+
: undefined
|
|
680
|
+
};
|
|
681
|
+
_this._mtextGlyphCache.set(key, entry);
|
|
682
|
+
return entry;
|
|
683
|
+
});
|
|
684
|
+
this.trackGlyphInflight(this._mtextGlyphInflight, key, render);
|
|
685
|
+
var pending_2 = render.then(function (entry) {
|
|
686
|
+
_this.applyCachedGlyphs(entity, entry, position, stroke, fill);
|
|
687
|
+
if (_this._embedTextActualText && entry.actualText) {
|
|
688
|
+
entity.actualText = entry.actualText;
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
this._pending.push(pending_2);
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
// Identical glyph work already in flight: reuse its result instead of
|
|
695
|
+
// rendering the same text again.
|
|
696
|
+
var pending = inflight.then(function (entry) {
|
|
697
|
+
_this.applyCachedGlyphs(entity, entry, position, stroke, fill);
|
|
698
|
+
if (_this._embedTextActualText && entry.actualText) {
|
|
699
|
+
entity.actualText = entry.actualText;
|
|
700
|
+
}
|
|
701
|
+
});
|
|
702
|
+
this._pending.push(pending);
|
|
703
|
+
};
|
|
704
|
+
AcPdfRenderer.prototype.shape = function (shape, style, _delay) {
|
|
705
|
+
var _this = this;
|
|
706
|
+
var entity = new AcPdfEntity();
|
|
707
|
+
var provider = this._glyphProvider;
|
|
708
|
+
if (!provider) {
|
|
709
|
+
return this.pushEntity(entity);
|
|
710
|
+
}
|
|
711
|
+
var mapped = style ? this.resolveStyle(style) : style;
|
|
712
|
+
var fill = AcPdfStyleUtil.fillStyle(this._subEntityTraits, this.styleContext);
|
|
713
|
+
var stroke = AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext);
|
|
714
|
+
var position = { x: shape.position.x, y: shape.position.y };
|
|
715
|
+
var key = shapeGlyphKey(shape, mapped);
|
|
716
|
+
var cached = this._shapeGlyphCache.get(key);
|
|
717
|
+
if (cached) {
|
|
718
|
+
this.applyCachedGlyphs(entity, cached, position, stroke, fill);
|
|
719
|
+
return this.pushEntity(entity);
|
|
720
|
+
}
|
|
721
|
+
var inflight = this._shapeGlyphInflight.get(key);
|
|
722
|
+
if (!inflight) {
|
|
723
|
+
var render = Promise.resolve(provider.renderShape(shape, mapped)).then(function (result) {
|
|
724
|
+
var entry = {
|
|
725
|
+
primitives: result.primitives,
|
|
726
|
+
box: result.box
|
|
727
|
+
};
|
|
728
|
+
_this._shapeGlyphCache.set(key, entry);
|
|
729
|
+
return entry;
|
|
730
|
+
});
|
|
731
|
+
this.trackGlyphInflight(this._shapeGlyphInflight, key, render);
|
|
732
|
+
}
|
|
733
|
+
var pending = (inflight !== null && inflight !== void 0 ? inflight : this._shapeGlyphInflight.get(key)).then(function (entry) {
|
|
734
|
+
_this.applyCachedGlyphs(entity, entry, position, stroke, fill);
|
|
735
|
+
});
|
|
736
|
+
this._pending.push(pending);
|
|
737
|
+
return this.pushEntity(entity);
|
|
738
|
+
};
|
|
739
|
+
AcPdfRenderer.prototype.image = function (blob, style) {
|
|
740
|
+
var entity = new AcPdfEntity();
|
|
741
|
+
var pending = blobToImageOp(blob, style).then(function (op) {
|
|
742
|
+
if (!op) {
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
entity.addOp(op);
|
|
746
|
+
entity.box.expandByPoint({ x: op.x, y: op.y });
|
|
747
|
+
entity.box.expandByPoint({ x: op.x + op.width, y: op.y + op.height });
|
|
748
|
+
});
|
|
749
|
+
this._pending.push(pending);
|
|
750
|
+
return this.pushEntity(entity);
|
|
751
|
+
};
|
|
752
|
+
/**
|
|
753
|
+
* Waits for async glyph / image work scheduled by {@link mtext},
|
|
754
|
+
* {@link shape}, and {@link image}.
|
|
755
|
+
*
|
|
756
|
+
* Paper-space viewport export must call this before cloning model-space
|
|
757
|
+
* drawables; otherwise TEXT/MTEXT clones capture empty op lists.
|
|
758
|
+
*/
|
|
759
|
+
AcPdfRenderer.prototype.awaitPending = function () {
|
|
760
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
761
|
+
var pending;
|
|
762
|
+
return __generator(this, function (_a) {
|
|
763
|
+
switch (_a.label) {
|
|
764
|
+
case 0:
|
|
765
|
+
if (this._pending.length === 0) {
|
|
766
|
+
return [2 /*return*/];
|
|
767
|
+
}
|
|
768
|
+
pending = this._pending.splice(0, this._pending.length);
|
|
769
|
+
return [4 /*yield*/, Promise.all(pending)
|
|
770
|
+
// Glyph callbacks may have scheduled follow-up work.
|
|
771
|
+
];
|
|
772
|
+
case 1:
|
|
773
|
+
_a.sent();
|
|
774
|
+
if (!(this._pending.length > 0)) return [3 /*break*/, 3];
|
|
775
|
+
return [4 /*yield*/, this.awaitPending()];
|
|
776
|
+
case 2:
|
|
777
|
+
_a.sent();
|
|
778
|
+
_a.label = 3;
|
|
779
|
+
case 3: return [2 /*return*/];
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
});
|
|
783
|
+
};
|
|
784
|
+
/** Keeps one in-flight render per key; drops the entry once settled. */
|
|
785
|
+
AcPdfRenderer.prototype.trackGlyphInflight = function (map, key, promise) {
|
|
786
|
+
map.set(key, promise);
|
|
787
|
+
promise.then(function () {
|
|
788
|
+
if (map.get(key) === promise) {
|
|
789
|
+
map.delete(key);
|
|
790
|
+
}
|
|
791
|
+
}, function () {
|
|
792
|
+
map.delete(key);
|
|
793
|
+
});
|
|
794
|
+
};
|
|
795
|
+
/**
|
|
796
|
+
* Paints a cached glyph result into `entity`, re-positioning the shared
|
|
797
|
+
* text-local primitives at this instance's position via a translation
|
|
798
|
+
* matrix (ops stay shared; the writer maps them with a Form XObject or a
|
|
799
|
+
* numeric bake).
|
|
800
|
+
*/
|
|
801
|
+
AcPdfRenderer.prototype.applyCachedGlyphs = function (entity, entry, position, stroke, fill) {
|
|
802
|
+
applyGlyphs(entity, entry.primitives, entry.box, stroke, fill);
|
|
803
|
+
if (position.x !== 0 || position.y !== 0) {
|
|
804
|
+
entity.applyMatrix(new AcGeMatrix3d().makeTranslation(position.x, position.y, 0));
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
AcPdfRenderer.prototype.exportAsync = function (roots) {
|
|
808
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
809
|
+
var entities;
|
|
810
|
+
return __generator(this, function (_a) {
|
|
811
|
+
switch (_a.label) {
|
|
812
|
+
case 0: return [4 /*yield*/, this.awaitPending()
|
|
813
|
+
// Prefer explicit roots from top-level worldDraw return values. The
|
|
814
|
+
// internal `_entities` list is polluted by AcDbRenderingCache: it leaves
|
|
815
|
+
// untransformed block templates in place while returning applyMatrix'd
|
|
816
|
+
// clones that are never pushed here.
|
|
817
|
+
];
|
|
818
|
+
case 1:
|
|
819
|
+
_a.sent();
|
|
820
|
+
entities = roots !== null && roots !== void 0 ? roots : this._entities;
|
|
821
|
+
return [2 /*return*/, AcPdfDocumentWriter.write(entities, this.writeOptions())];
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
});
|
|
825
|
+
};
|
|
826
|
+
/**
|
|
827
|
+
* Paints one layout page into an existing document.
|
|
828
|
+
*
|
|
829
|
+
* Multi-layout exports reuse one {@link PDFDocument} (plus a shared OCG
|
|
830
|
+
* manager and image cache via `overrides`) so finished pages never have to
|
|
831
|
+
* be serialized, re-parsed and copied into a merge document.
|
|
832
|
+
*/
|
|
833
|
+
AcPdfRenderer.prototype.renderToDocument = function (doc_1, roots_1) {
|
|
834
|
+
return __awaiter(this, arguments, void 0, function (doc, roots, overrides) {
|
|
835
|
+
var entities;
|
|
836
|
+
if (overrides === void 0) { overrides = {}; }
|
|
837
|
+
return __generator(this, function (_a) {
|
|
838
|
+
switch (_a.label) {
|
|
839
|
+
case 0: return [4 /*yield*/, this.awaitPending()];
|
|
840
|
+
case 1:
|
|
841
|
+
_a.sent();
|
|
842
|
+
entities = roots !== null && roots !== void 0 ? roots : this._entities;
|
|
843
|
+
return [4 /*yield*/, AcPdfDocumentWriter.writePage(doc, entities, this.writeOptions(overrides))];
|
|
844
|
+
case 2:
|
|
845
|
+
_a.sent();
|
|
846
|
+
return [2 /*return*/];
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
});
|
|
850
|
+
};
|
|
851
|
+
/**
|
|
852
|
+
* Drops drawables accumulated in the renderer's internal entity list.
|
|
853
|
+
*
|
|
854
|
+
* Multi-page exports pass explicit roots to every page; the internal list
|
|
855
|
+
* only retains block templates and stale drawables. Clearing it between
|
|
856
|
+
* pages lets per-page paper-space geometry be collected while earlier
|
|
857
|
+
* pages remain alive only inside the shared PDF document.
|
|
858
|
+
*/
|
|
859
|
+
AcPdfRenderer.prototype.resetCollected = function () {
|
|
860
|
+
this._entities.length = 0;
|
|
861
|
+
};
|
|
862
|
+
AcPdfRenderer.prototype.writeOptions = function (overrides) {
|
|
863
|
+
if (overrides === void 0) { overrides = {}; }
|
|
864
|
+
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
|
+
};
|
|
866
|
+
AcPdfRenderer.prototype.appendStrokedPoints = function (entity, pts, style) {
|
|
867
|
+
var e_11, _a, e_12, _b;
|
|
868
|
+
var _c;
|
|
869
|
+
var pattern = this._subEntityTraits.lineType.pattern;
|
|
870
|
+
if (isComplexLineType(pattern) && pattern) {
|
|
871
|
+
var scale = this._ltscale *
|
|
872
|
+
this._celtscale *
|
|
873
|
+
this._subEntityTraits.lineTypeScale;
|
|
874
|
+
var walked = walkLineType(pts, pattern, scale);
|
|
875
|
+
var dashless_1 = __assign(__assign({}, style), { dashArray: undefined });
|
|
876
|
+
try {
|
|
877
|
+
for (var _d = __values(walked.strokes), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
878
|
+
var stroke = _e.value;
|
|
879
|
+
entity.addOp({ kind: 'stroke', points: stroke, style: dashless_1 });
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
883
|
+
finally {
|
|
884
|
+
try {
|
|
885
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
886
|
+
}
|
|
887
|
+
finally { if (e_11) throw e_11.error; }
|
|
888
|
+
}
|
|
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
|
+
try {
|
|
928
|
+
for (var _f = __values(walked.shapes), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
929
|
+
var shape = _g.value;
|
|
930
|
+
_loop_2(shape);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
934
|
+
finally {
|
|
935
|
+
try {
|
|
936
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
937
|
+
}
|
|
938
|
+
finally { if (e_12) throw e_12.error; }
|
|
939
|
+
}
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (pts.length >= 2) {
|
|
943
|
+
entity.addOp({ kind: 'stroke', points: pts, style: style });
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
AcPdfRenderer.prototype.pushStrokedPolyline = function (points, box) {
|
|
947
|
+
var entity = new AcPdfEntity();
|
|
948
|
+
var pts = toPdfPoints(points);
|
|
949
|
+
this.appendStrokedPoints(entity, pts, AcPdfStyleUtil.strokeStyle(this._subEntityTraits, this.styleContext));
|
|
950
|
+
entity.box.min.set(box.min.x, box.min.y);
|
|
951
|
+
entity.box.max.set(box.max.x, box.max.y);
|
|
952
|
+
return this.pushEntity(entity);
|
|
953
|
+
};
|
|
954
|
+
AcPdfRenderer.prototype.resolveStyle = function (style) {
|
|
955
|
+
var _a;
|
|
956
|
+
var mappedFont = (_a = this._fontMapping[style.font]) !== null && _a !== void 0 ? _a : style.font;
|
|
957
|
+
return mappedFont !== style.font ? __assign(__assign({}, style), { font: mappedFont }) : style;
|
|
958
|
+
};
|
|
959
|
+
return AcPdfRenderer;
|
|
960
|
+
}());
|
|
961
|
+
export { AcPdfRenderer };
|
|
962
|
+
function toPdfPoints(points) {
|
|
963
|
+
return points.map(function (p) { return ({ x: p.x, y: p.y }); });
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Cache key covering every mtext field that changes rendered geometry.
|
|
967
|
+
* `position` is excluded on purpose: reuse translates shared primitives.
|
|
968
|
+
* `style.lastHeight` is a scratch value that does not affect rendering.
|
|
969
|
+
*/
|
|
970
|
+
function mtextGlyphKey(mtext, style) {
|
|
971
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
972
|
+
return JSON.stringify([
|
|
973
|
+
(_a = mtext.text) !== null && _a !== void 0 ? _a : '',
|
|
974
|
+
mtext.height,
|
|
975
|
+
mtext.width,
|
|
976
|
+
(_b = mtext.rotation) !== null && _b !== void 0 ? _b : null,
|
|
977
|
+
(_c = mtext.directionVector) !== null && _c !== void 0 ? _c : null,
|
|
978
|
+
(_d = mtext.attachmentPoint) !== null && _d !== void 0 ? _d : null,
|
|
979
|
+
(_e = mtext.drawingDirection) !== null && _e !== void 0 ? _e : null,
|
|
980
|
+
(_f = mtext.lineSpaceFactor) !== null && _f !== void 0 ? _f : null,
|
|
981
|
+
(_g = mtext.widthFactor) !== null && _g !== void 0 ? _g : null,
|
|
982
|
+
glyphStyleKey(style)
|
|
983
|
+
]);
|
|
984
|
+
}
|
|
985
|
+
/** Cache key covering every shape field that changes rendered geometry. */
|
|
986
|
+
function shapeGlyphKey(shape, style) {
|
|
987
|
+
var _a, _b, _c, _d, _e;
|
|
988
|
+
return JSON.stringify([
|
|
989
|
+
(_a = shape.name) !== null && _a !== void 0 ? _a : null,
|
|
990
|
+
(_b = shape.shapeNumber) !== null && _b !== void 0 ? _b : null,
|
|
991
|
+
shape.size,
|
|
992
|
+
(_c = shape.rotation) !== null && _c !== void 0 ? _c : null,
|
|
993
|
+
(_d = shape.directionVector) !== null && _d !== void 0 ? _d : null,
|
|
994
|
+
(_e = shape.widthFactor) !== null && _e !== void 0 ? _e : null,
|
|
995
|
+
style ? glyphStyleKey(style) : null
|
|
996
|
+
]);
|
|
997
|
+
}
|
|
998
|
+
function glyphStyleKey(style) {
|
|
999
|
+
var _a;
|
|
1000
|
+
return [
|
|
1001
|
+
style.name,
|
|
1002
|
+
style.standardFlag,
|
|
1003
|
+
style.fixedTextHeight,
|
|
1004
|
+
style.widthFactor,
|
|
1005
|
+
style.obliqueAngle,
|
|
1006
|
+
style.textGenerationFlag,
|
|
1007
|
+
style.font,
|
|
1008
|
+
style.bigFont,
|
|
1009
|
+
(_a = style.extendedFont) !== null && _a !== void 0 ? _a : ''
|
|
1010
|
+
].join('\u0000');
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Paints a rendered glyph set into `entity` as one compact op per primitive
|
|
1014
|
+
* kind. Geometry is text-local (relative to the text's insertion point); the
|
|
1015
|
+
* caller positions it via `entity.applyMatrix`.
|
|
1016
|
+
*/
|
|
1017
|
+
function applyGlyphs(entity, primitives, box, strokeStyle, fillStyle) {
|
|
1018
|
+
if (primitives.triangles.length >= 6) {
|
|
1019
|
+
entity.addOp({
|
|
1020
|
+
kind: 'triangles',
|
|
1021
|
+
data: primitives.triangles,
|
|
1022
|
+
style: fillStyle
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
if (primitives.polylines.length >= 2) {
|
|
1026
|
+
entity.addOp({
|
|
1027
|
+
kind: 'polylines',
|
|
1028
|
+
data: primitives.polylines,
|
|
1029
|
+
style: strokeStyle
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
entity.box.min.set(box.min.x, box.min.y);
|
|
1033
|
+
entity.box.max.set(box.max.x, box.max.y);
|
|
1034
|
+
}
|
|
1035
|
+
function blobToImageOp(blob, style) {
|
|
1036
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1037
|
+
var boundary, type, format, raster, converted, minX, minY, maxX, maxY, boundary_1, boundary_1_1, pt, bytes, _a;
|
|
1038
|
+
var e_13, _b;
|
|
1039
|
+
return __generator(this, function (_c) {
|
|
1040
|
+
switch (_c.label) {
|
|
1041
|
+
case 0:
|
|
1042
|
+
boundary = style.boundary;
|
|
1043
|
+
if (!boundary || boundary.length < 2) {
|
|
1044
|
+
return [2 /*return*/, null];
|
|
1045
|
+
}
|
|
1046
|
+
type = blob.type || '';
|
|
1047
|
+
if (type.includes('svg')) {
|
|
1048
|
+
return [2 /*return*/, null];
|
|
1049
|
+
}
|
|
1050
|
+
raster = blob;
|
|
1051
|
+
if (!(type.includes('jpeg') || type.includes('jpg'))) return [3 /*break*/, 1];
|
|
1052
|
+
format = 'jpg';
|
|
1053
|
+
return [3 /*break*/, 4];
|
|
1054
|
+
case 1:
|
|
1055
|
+
if (!type.includes('png')) return [3 /*break*/, 2];
|
|
1056
|
+
format = 'png';
|
|
1057
|
+
return [3 /*break*/, 4];
|
|
1058
|
+
case 2: return [4 /*yield*/, convertToEmbeddablePng(blob)];
|
|
1059
|
+
case 3:
|
|
1060
|
+
converted = _c.sent();
|
|
1061
|
+
if (!converted) {
|
|
1062
|
+
return [2 /*return*/, null];
|
|
1063
|
+
}
|
|
1064
|
+
raster = converted;
|
|
1065
|
+
format = 'png';
|
|
1066
|
+
_c.label = 4;
|
|
1067
|
+
case 4:
|
|
1068
|
+
minX = Infinity;
|
|
1069
|
+
minY = Infinity;
|
|
1070
|
+
maxX = -Infinity;
|
|
1071
|
+
maxY = -Infinity;
|
|
1072
|
+
try {
|
|
1073
|
+
for (boundary_1 = __values(boundary), boundary_1_1 = boundary_1.next(); !boundary_1_1.done; boundary_1_1 = boundary_1.next()) {
|
|
1074
|
+
pt = boundary_1_1.value;
|
|
1075
|
+
minX = Math.min(minX, pt.x);
|
|
1076
|
+
minY = Math.min(minY, pt.y);
|
|
1077
|
+
maxX = Math.max(maxX, pt.x);
|
|
1078
|
+
maxY = Math.max(maxY, pt.y);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1082
|
+
finally {
|
|
1083
|
+
try {
|
|
1084
|
+
if (boundary_1_1 && !boundary_1_1.done && (_b = boundary_1.return)) _b.call(boundary_1);
|
|
1085
|
+
}
|
|
1086
|
+
finally { if (e_13) throw e_13.error; }
|
|
1087
|
+
}
|
|
1088
|
+
_a = Uint8Array.bind;
|
|
1089
|
+
return [4 /*yield*/, raster.arrayBuffer()];
|
|
1090
|
+
case 5:
|
|
1091
|
+
bytes = new (_a.apply(Uint8Array, [void 0, _c.sent()]))();
|
|
1092
|
+
return [2 /*return*/, {
|
|
1093
|
+
kind: 'image',
|
|
1094
|
+
bytes: bytes,
|
|
1095
|
+
format: format,
|
|
1096
|
+
x: minX,
|
|
1097
|
+
y: minY,
|
|
1098
|
+
width: maxX - minX,
|
|
1099
|
+
height: maxY - minY
|
|
1100
|
+
}];
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Converts a non-embeddable image blob (BMP / GIF raster or WMF / EMF
|
|
1107
|
+
* metafile) to PNG. Returns `undefined` when no conversion path applies or
|
|
1108
|
+
* decoding fails — callers then skip the image instead of failing the export.
|
|
1109
|
+
*/
|
|
1110
|
+
function convertToEmbeddablePng(blob) {
|
|
1111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1112
|
+
var type, _a;
|
|
1113
|
+
return __generator(this, function (_b) {
|
|
1114
|
+
switch (_b.label) {
|
|
1115
|
+
case 0:
|
|
1116
|
+
_b.trys.push([0, 4, , 5]);
|
|
1117
|
+
type = blob.type || '';
|
|
1118
|
+
if (!(type === 'image/wmf' || type === 'image/emf')) return [3 /*break*/, 2];
|
|
1119
|
+
return [4 /*yield*/, acdbRasterizeOleMetafile(blob)];
|
|
1120
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
1121
|
+
case 2: return [4 /*yield*/, decodeRasterBlobToPng(blob)];
|
|
1122
|
+
case 3: return [2 /*return*/, _b.sent()];
|
|
1123
|
+
case 4:
|
|
1124
|
+
_a = _b.sent();
|
|
1125
|
+
return [2 /*return*/, undefined];
|
|
1126
|
+
case 5: return [2 /*return*/];
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Decodes a browser-supported raster blob (BMP, GIF, WebP, …) and re-encodes
|
|
1133
|
+
* its first frame as PNG through a canvas.
|
|
1134
|
+
*/
|
|
1135
|
+
function decodeRasterBlobToPng(blob) {
|
|
1136
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1137
|
+
var bitmap, _a, canvas, ctx, canvas_1, ctx;
|
|
1138
|
+
return __generator(this, function (_b) {
|
|
1139
|
+
switch (_b.label) {
|
|
1140
|
+
case 0:
|
|
1141
|
+
if (typeof createImageBitmap !== 'function') {
|
|
1142
|
+
return [2 /*return*/, undefined];
|
|
1143
|
+
}
|
|
1144
|
+
_b.label = 1;
|
|
1145
|
+
case 1:
|
|
1146
|
+
_b.trys.push([1, 3, , 4]);
|
|
1147
|
+
return [4 /*yield*/, createImageBitmap(blob)];
|
|
1148
|
+
case 2:
|
|
1149
|
+
bitmap = _b.sent();
|
|
1150
|
+
return [3 /*break*/, 4];
|
|
1151
|
+
case 3:
|
|
1152
|
+
_a = _b.sent();
|
|
1153
|
+
return [2 /*return*/, undefined];
|
|
1154
|
+
case 4:
|
|
1155
|
+
_b.trys.push([4, , 9, 10]);
|
|
1156
|
+
if (!(typeof OffscreenCanvas === 'function')) return [3 /*break*/, 6];
|
|
1157
|
+
canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
|
1158
|
+
ctx = canvas.getContext('2d');
|
|
1159
|
+
if (!ctx) {
|
|
1160
|
+
return [2 /*return*/, undefined];
|
|
1161
|
+
}
|
|
1162
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
1163
|
+
return [4 /*yield*/, canvas.convertToBlob({ type: 'image/png' })];
|
|
1164
|
+
case 5: return [2 /*return*/, _b.sent()];
|
|
1165
|
+
case 6:
|
|
1166
|
+
if (!(typeof document !== 'undefined')) return [3 /*break*/, 8];
|
|
1167
|
+
canvas_1 = document.createElement('canvas');
|
|
1168
|
+
canvas_1.width = bitmap.width;
|
|
1169
|
+
canvas_1.height = bitmap.height;
|
|
1170
|
+
ctx = canvas_1.getContext('2d');
|
|
1171
|
+
if (!ctx) {
|
|
1172
|
+
return [2 /*return*/, undefined];
|
|
1173
|
+
}
|
|
1174
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
1175
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
1176
|
+
canvas_1.toBlob(function (out) { return resolve(out !== null && out !== void 0 ? out : undefined); }, 'image/png');
|
|
1177
|
+
})];
|
|
1178
|
+
case 7: return [2 /*return*/, _b.sent()];
|
|
1179
|
+
case 8: return [2 /*return*/, undefined];
|
|
1180
|
+
case 9:
|
|
1181
|
+
bitmap.close();
|
|
1182
|
+
return [7 /*endfinally*/];
|
|
1183
|
+
case 10: return [2 /*return*/];
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
//# sourceMappingURL=AcPdfRenderer.js.map
|