pdf-codec 1.4.2 → 1.6.0
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/README.md +56 -15
- package/dist/assets/caladea-bold.cjs +5 -0
- package/dist/assets/caladea-bold.d.cts +4 -0
- package/dist/assets/caladea-bold.d.ts +4 -0
- package/dist/assets/caladea-bold.js +4 -0
- package/dist/assets/caladea-bolditalic.cjs +5 -0
- package/dist/assets/caladea-bolditalic.d.cts +4 -0
- package/dist/assets/caladea-bolditalic.d.ts +4 -0
- package/dist/assets/caladea-bolditalic.js +4 -0
- package/dist/assets/caladea-italic.cjs +5 -0
- package/dist/assets/caladea-italic.d.cts +4 -0
- package/dist/assets/caladea-italic.d.ts +4 -0
- package/dist/assets/caladea-italic.js +4 -0
- package/dist/assets/caladea-regular.cjs +5 -0
- package/dist/assets/caladea-regular.d.cts +4 -0
- package/dist/assets/caladea-regular.d.ts +4 -0
- package/dist/assets/caladea-regular.js +4 -0
- package/dist/assets/carlito-bold.cjs +5 -0
- package/dist/assets/carlito-bold.d.cts +4 -0
- package/dist/assets/carlito-bold.d.ts +4 -0
- package/dist/assets/carlito-bold.js +4 -0
- package/dist/assets/carlito-bolditalic.cjs +5 -0
- package/dist/assets/carlito-bolditalic.d.cts +4 -0
- package/dist/assets/carlito-bolditalic.d.ts +4 -0
- package/dist/assets/carlito-bolditalic.js +4 -0
- package/dist/assets/carlito-italic.cjs +5 -0
- package/dist/assets/carlito-italic.d.cts +4 -0
- package/dist/assets/carlito-italic.d.ts +4 -0
- package/dist/assets/carlito-italic.js +4 -0
- package/dist/assets/carlito-regular.cjs +5 -0
- package/dist/assets/carlito-regular.d.cts +4 -0
- package/dist/assets/carlito-regular.d.ts +4 -0
- package/dist/assets/carlito-regular.js +4 -0
- package/dist/cff-probe.cjs +133 -0
- package/dist/cff-probe.d.cts +10 -0
- package/dist/cff-probe.d.ts +10 -0
- package/dist/cff-probe.js +132 -0
- package/dist/cmap-table.cjs +108 -0
- package/dist/cmap-table.d.cts +6 -0
- package/dist/cmap-table.d.ts +6 -0
- package/dist/cmap-table.js +107 -0
- package/dist/content-write.cjs +36 -17
- package/dist/content-write.d.cts +9 -2
- package/dist/content-write.d.ts +9 -2
- package/dist/content-write.js +35 -16
- package/dist/crypto/aes.cjs +166 -0
- package/dist/crypto/aes.d.cts +6 -0
- package/dist/crypto/aes.d.ts +6 -0
- package/dist/crypto/aes.js +163 -0
- package/dist/crypto/md5.cjs +215 -0
- package/dist/crypto/md5.d.cts +4 -0
- package/dist/crypto/md5.d.ts +4 -0
- package/dist/crypto/md5.js +214 -0
- package/dist/crypto/rc4.cjs +29 -0
- package/dist/crypto/rc4.d.cts +4 -0
- package/dist/crypto/rc4.d.ts +4 -0
- package/dist/crypto/rc4.js +28 -0
- package/dist/crypto/sha2.cjs +261 -0
- package/dist/crypto/sha2.d.cts +6 -0
- package/dist/crypto/sha2.d.ts +6 -0
- package/dist/crypto/sha2.js +258 -0
- package/dist/diagnostics.cjs +7 -0
- package/dist/diagnostics.d.cts +4 -1
- package/dist/diagnostics.d.ts +4 -1
- package/dist/diagnostics.js +7 -1
- package/dist/document.cjs +38 -2
- package/dist/document.js +38 -2
- package/dist/embedded-font-CLedn-mT.d.cts +42 -0
- package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
- package/dist/embedded-font-write.cjs +92 -0
- package/dist/embedded-font-write.d.cts +22 -0
- package/dist/embedded-font-write.d.ts +22 -0
- package/dist/embedded-font-write.js +90 -0
- package/dist/embedded-font.cjs +142 -0
- package/dist/embedded-font.d.cts +2 -0
- package/dist/embedded-font.d.ts +2 -0
- package/dist/embedded-font.js +138 -0
- package/dist/encrypt.cjs +264 -0
- package/dist/encrypt.d.cts +11 -0
- package/dist/encrypt.d.ts +11 -0
- package/dist/encrypt.js +263 -0
- package/dist/filters.cjs +19 -1
- package/dist/filters.js +19 -1
- package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
- package/dist/font-registry-yby02snZ.d.cts +38 -0
- package/dist/font-registry.cjs +152 -0
- package/dist/font-registry.d.cts +2 -0
- package/dist/font-registry.d.ts +2 -0
- package/dist/font-registry.js +150 -0
- package/dist/font-substitutes.cjs +13 -0
- package/dist/font-substitutes.d.cts +5 -0
- package/dist/font-substitutes.d.ts +5 -0
- package/dist/font-substitutes.js +12 -0
- package/dist/font-tables.cjs +127 -0
- package/dist/font-tables.d.cts +43 -0
- package/dist/font-tables.d.ts +43 -0
- package/dist/font-tables.js +122 -0
- package/dist/fonts.cjs +1 -0
- package/dist/fonts.d.cts +2 -1
- package/dist/fonts.d.ts +2 -1
- package/dist/fonts.js +1 -1
- package/dist/glyf.cjs +127 -0
- package/dist/glyf.d.cts +31 -0
- package/dist/glyf.d.ts +31 -0
- package/dist/glyf.js +125 -0
- package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
- package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
- package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
- package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
- package/dist/image/ccitt.cjs +488 -0
- package/dist/image/ccitt.d.cts +17 -0
- package/dist/image/ccitt.d.ts +17 -0
- package/dist/image/ccitt.js +487 -0
- package/dist/images-read.cjs +1 -4
- package/dist/images-read.js +2 -5
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -3
- package/dist/interpret.cjs +173 -38
- package/dist/interpret.d.cts +27 -10
- package/dist/interpret.d.ts +27 -10
- package/dist/interpret.js +174 -39
- package/dist/math-font-write.cjs +3 -32
- package/dist/math-font-write.js +2 -31
- package/dist/math-font.cjs +7 -5
- package/dist/math-font.js +5 -3
- package/dist/math-table.d.cts +1 -1
- package/dist/math-table.d.ts +1 -1
- package/dist/{matrix-B3c2_a2f.d.cts → matrix-BHzJESll.d.cts} +2 -1
- package/dist/{matrix-B3c2_a2f.d.ts → matrix-BHzJESll.d.ts} +2 -1
- package/dist/matrix.cjs +2 -0
- package/dist/matrix.d.cts +2 -2
- package/dist/matrix.d.ts +2 -2
- package/dist/matrix.js +2 -1
- package/dist/measure.cjs +65 -14
- package/dist/measure.d.cts +8 -1
- package/dist/measure.d.ts +8 -1
- package/dist/measure.js +64 -15
- package/dist/objects.cjs +4 -0
- package/dist/objects.d.cts +2 -1
- package/dist/objects.d.ts +2 -1
- package/dist/objects.js +4 -1
- package/dist/read.cjs +43 -4
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +43 -4
- package/dist/sfnt-V08bb5ut.d.cts +21 -0
- package/dist/sfnt-V08bb5ut.d.ts +21 -0
- package/dist/sfnt-subset.cjs +250 -0
- package/dist/sfnt-subset.d.cts +11 -0
- package/dist/sfnt-subset.d.ts +11 -0
- package/dist/sfnt-subset.js +249 -0
- package/dist/sfnt.cjs +50 -4
- package/dist/sfnt.d.cts +2 -17
- package/dist/sfnt.d.ts +2 -17
- package/dist/sfnt.js +47 -5
- package/dist/tounicode.cjs +34 -0
- package/dist/tounicode.d.cts +5 -0
- package/dist/tounicode.d.ts +5 -0
- package/dist/tounicode.js +33 -0
- package/dist/write.cjs +81 -11
- package/dist/write.d.cts +6 -0
- package/dist/write.d.ts +6 -0
- package/dist/write.js +82 -12
- package/package.json +1 -1
- package/dist/math-cmap.cjs +0 -81
- package/dist/math-cmap.d.cts +0 -6
- package/dist/math-cmap.d.ts +0 -6
- package/dist/math-cmap.js +0 -80
package/dist/interpret.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { asArray, asName, asNumber, dictGet } from "./objects.js";
|
|
2
2
|
import { decodeStream } from "./filters.js";
|
|
3
|
-
import { IDENTITY_MATRIX, applyMatrix, multiplyMatrices, translationMatrix } from "./matrix.js";
|
|
3
|
+
import { BEZIER_KAPPA, IDENTITY_MATRIX, applyMatrix, multiplyMatrices, translationMatrix } from "./matrix.js";
|
|
4
4
|
import { readContentStream } from "./content-read.js";
|
|
5
5
|
import { COLOR_BLACK } from "document-schema.js";
|
|
6
6
|
//#region src/interpret.ts
|
|
@@ -75,26 +75,176 @@ function matrixFromOperands(operands) {
|
|
|
75
75
|
numAt(operands, 5)
|
|
76
76
|
];
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const SHAPE_ABS_TOLERANCE_PT = .001;
|
|
79
|
+
const SHAPE_REL_TOLERANCE = 1e-4;
|
|
80
|
+
function shapeTolerance(extentPt) {
|
|
81
|
+
return Math.max(SHAPE_ABS_TOLERANCE_PT, Math.abs(extentPt) * SHAPE_REL_TOLERANCE);
|
|
80
82
|
}
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
|
|
83
|
+
function nearlyEqual(a, b, tolerance) {
|
|
84
|
+
return Math.abs(a - b) <= tolerance;
|
|
85
|
+
}
|
|
86
|
+
function nearlyEqualPoints(a, b, tolerance) {
|
|
87
|
+
return nearlyEqual(a.x, b.x, tolerance) && nearlyEqual(a.y, b.y, tolerance);
|
|
88
|
+
}
|
|
89
|
+
function boundsOf(points) {
|
|
90
|
+
const xs = points.map((p) => p.x);
|
|
91
|
+
const ys = points.map((p) => p.y);
|
|
92
|
+
return {
|
|
93
|
+
minX: Math.min(...xs),
|
|
94
|
+
minY: Math.min(...ys),
|
|
95
|
+
maxX: Math.max(...xs),
|
|
96
|
+
maxY: Math.max(...ys)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function closedPolygonCorners(subpath) {
|
|
100
|
+
if (!subpath.closed) return;
|
|
101
|
+
const corners = [{
|
|
102
|
+
x: subpath.startXPt,
|
|
103
|
+
y: subpath.startYPt
|
|
104
|
+
}];
|
|
105
|
+
for (const segment of subpath.segments) {
|
|
106
|
+
if (segment.kind !== "line") return;
|
|
107
|
+
corners.push({
|
|
108
|
+
x: segment.xPt,
|
|
109
|
+
y: segment.yPt
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const first = corners[0];
|
|
113
|
+
const last = corners[corners.length - 1];
|
|
114
|
+
if (first === void 0 || last === void 0 || corners.length < 2) return;
|
|
115
|
+
const bounds = boundsOf(corners);
|
|
116
|
+
if (nearlyEqualPoints(first, last, shapeTolerance(Math.max(bounds.maxX - bounds.minX, bounds.maxY - bounds.minY)))) corners.pop();
|
|
117
|
+
return corners;
|
|
118
|
+
}
|
|
119
|
+
function detectRect(subpath, paint) {
|
|
120
|
+
const corners = closedPolygonCorners(subpath);
|
|
121
|
+
if (corners?.length !== 4) return;
|
|
122
|
+
const { minX, minY, maxX, maxY } = boundsOf(corners);
|
|
123
|
+
const widthPt = maxX - minX;
|
|
124
|
+
const heightPt = maxY - minY;
|
|
125
|
+
const tolX = shapeTolerance(widthPt);
|
|
126
|
+
const tolY = shapeTolerance(heightPt);
|
|
127
|
+
if (widthPt <= tolX || heightPt <= tolY) return;
|
|
128
|
+
for (const corner of corners) {
|
|
129
|
+
if (!nearlyEqual(corner.x, minX, tolX) && !nearlyEqual(corner.x, maxX, tolX)) return;
|
|
130
|
+
if (!nearlyEqual(corner.y, minY, tolY) && !nearlyEqual(corner.y, maxY, tolY)) return;
|
|
131
|
+
}
|
|
132
|
+
for (let i = 0; i < corners.length; i += 1) {
|
|
133
|
+
const from = corners[i];
|
|
134
|
+
const to = corners[(i + 1) % corners.length];
|
|
135
|
+
if (from === void 0 || to === void 0) return;
|
|
136
|
+
if (nearlyEqual(from.x, to.x, tolX) === nearlyEqual(from.y, to.y, tolY)) return;
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
kind: "rect",
|
|
140
|
+
xPt: minX,
|
|
141
|
+
yPt: minY,
|
|
142
|
+
widthPt,
|
|
143
|
+
heightPt,
|
|
144
|
+
fill: paint.fill,
|
|
145
|
+
stroke: paint.stroke
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function cardinalExtremeOf(point, center, rx, ry, tolX, tolY) {
|
|
149
|
+
if (nearlyEqual(point.y, center.y, tolY)) {
|
|
150
|
+
if (nearlyEqual(point.x, center.x + rx, tolX)) return "right";
|
|
151
|
+
if (nearlyEqual(point.x, center.x - rx, tolX)) return "left";
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (nearlyEqual(point.x, center.x, tolX)) {
|
|
155
|
+
if (nearlyEqual(point.y, center.y + ry, tolY)) return "top";
|
|
156
|
+
if (nearlyEqual(point.y, center.y - ry, tolY)) return "bottom";
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function expectedEllipseControl(atExtreme, atExtremeKind, otherEnd, center, kx, ky) {
|
|
160
|
+
if (atExtremeKind === "right" || atExtremeKind === "left") return {
|
|
161
|
+
x: atExtreme.x,
|
|
162
|
+
y: center.y + Math.sign(otherEnd.y - center.y) * ky
|
|
163
|
+
};
|
|
164
|
+
return {
|
|
165
|
+
x: center.x + Math.sign(otherEnd.x - center.x) * kx,
|
|
166
|
+
y: atExtreme.y
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function detectEllipse(subpath, paint) {
|
|
170
|
+
const segments = subpath.segments;
|
|
171
|
+
if (!subpath.closed || segments.length !== 4 || segments.some((segment) => segment.kind !== "cubic")) return;
|
|
172
|
+
const start = {
|
|
173
|
+
x: subpath.startXPt,
|
|
174
|
+
y: subpath.startYPt
|
|
175
|
+
};
|
|
176
|
+
const onCurve = [start];
|
|
177
|
+
for (const segment of segments.slice(0, 3)) onCurve.push({
|
|
178
|
+
x: segment.xPt,
|
|
179
|
+
y: segment.yPt
|
|
180
|
+
});
|
|
181
|
+
const { minX, minY, maxX, maxY } = boundsOf(onCurve);
|
|
182
|
+
const rx = (maxX - minX) / 2;
|
|
183
|
+
const ry = (maxY - minY) / 2;
|
|
184
|
+
const center = {
|
|
185
|
+
x: (minX + maxX) / 2,
|
|
186
|
+
y: (minY + maxY) / 2
|
|
187
|
+
};
|
|
188
|
+
const tolX = shapeTolerance(rx);
|
|
189
|
+
const tolY = shapeTolerance(ry);
|
|
190
|
+
if (rx <= tolX || ry <= tolY) return;
|
|
191
|
+
const finalSegment = segments[3];
|
|
192
|
+
if (finalSegment === void 0 || !nearlyEqualPoints({
|
|
193
|
+
x: finalSegment.xPt,
|
|
194
|
+
y: finalSegment.yPt
|
|
195
|
+
}, start, Math.max(tolX, tolY))) return;
|
|
196
|
+
const extremes = onCurve.map((point) => cardinalExtremeOf(point, center, rx, ry, tolX, tolY));
|
|
197
|
+
if (extremes.some((extreme) => extreme === void 0) || new Set(extremes).size !== 4) return;
|
|
198
|
+
const kx = rx * BEZIER_KAPPA;
|
|
199
|
+
const ky = ry * BEZIER_KAPPA;
|
|
200
|
+
const controlTolerance = Math.max(tolX, tolY);
|
|
201
|
+
for (let i = 0; i < 4; i += 1) {
|
|
202
|
+
const segment = segments[i];
|
|
203
|
+
const from = onCurve[i];
|
|
204
|
+
const fromKind = extremes[i];
|
|
205
|
+
const to = onCurve[(i + 1) % 4];
|
|
206
|
+
const toKind = extremes[(i + 1) % 4];
|
|
207
|
+
if (segment?.kind !== "cubic" || from === void 0 || to === void 0 || fromKind === void 0 || toKind === void 0) return;
|
|
208
|
+
const expectedC1 = expectedEllipseControl(from, fromKind, to, center, kx, ky);
|
|
209
|
+
const expectedC2 = expectedEllipseControl(to, toKind, from, center, kx, ky);
|
|
210
|
+
if (!nearlyEqualPoints({
|
|
211
|
+
x: segment.c1xPt,
|
|
212
|
+
y: segment.c1yPt
|
|
213
|
+
}, expectedC1, controlTolerance)) return;
|
|
214
|
+
if (!nearlyEqualPoints({
|
|
215
|
+
x: segment.c2xPt,
|
|
216
|
+
y: segment.c2yPt
|
|
217
|
+
}, expectedC2, controlTolerance)) return;
|
|
218
|
+
}
|
|
91
219
|
return {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
220
|
+
kind: "ellipse",
|
|
221
|
+
xPt: minX,
|
|
222
|
+
yPt: minY,
|
|
223
|
+
widthPt: maxX - minX,
|
|
224
|
+
heightPt: maxY - minY,
|
|
225
|
+
fill: paint.fill,
|
|
226
|
+
stroke: paint.stroke
|
|
96
227
|
};
|
|
97
228
|
}
|
|
229
|
+
function detectLine(subpath, paint) {
|
|
230
|
+
const segment = subpath.segments[0];
|
|
231
|
+
if (subpath.closed || subpath.segments.length !== 1 || segment?.kind !== "line") return;
|
|
232
|
+
if (paint.fill !== void 0 || paint.stroke === void 0) return;
|
|
233
|
+
return {
|
|
234
|
+
kind: "line",
|
|
235
|
+
x1Pt: subpath.startXPt,
|
|
236
|
+
y1Pt: subpath.startYPt,
|
|
237
|
+
x2Pt: segment.xPt,
|
|
238
|
+
y2Pt: segment.yPt,
|
|
239
|
+
color: paint.stroke.color,
|
|
240
|
+
widthPt: paint.stroke.widthPt
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function classifyShape(subpaths, paint) {
|
|
244
|
+
const subpath = subpaths[0];
|
|
245
|
+
if (subpaths.length !== 1 || subpath === void 0) return;
|
|
246
|
+
return detectRect(subpath, paint) ?? detectEllipse(subpath, paint) ?? detectLine(subpath, paint);
|
|
247
|
+
}
|
|
98
248
|
function interpretContentStream(bytes, resources, context) {
|
|
99
249
|
const items = [];
|
|
100
250
|
runContentStream(bytes, resources, {
|
|
@@ -120,7 +270,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
120
270
|
const gsStack = [];
|
|
121
271
|
let gs = initialState;
|
|
122
272
|
let ts = defaultTextState();
|
|
123
|
-
let pendingRect;
|
|
124
273
|
let pathSubpaths = [];
|
|
125
274
|
let currentSubpath;
|
|
126
275
|
const finalizeCurrentSubpath = () => {
|
|
@@ -130,7 +279,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
130
279
|
}
|
|
131
280
|
};
|
|
132
281
|
const resetPath = () => {
|
|
133
|
-
pendingRect = void 0;
|
|
134
282
|
pathSubpaths = [];
|
|
135
283
|
currentSubpath = void 0;
|
|
136
284
|
};
|
|
@@ -186,28 +334,22 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
186
334
|
return;
|
|
187
335
|
}
|
|
188
336
|
if ((operator === "s" || operator === "b" || operator === "b*") && currentSubpath !== void 0) currentSubpath.closed = true;
|
|
189
|
-
if ((operator === "f" || operator === "F" || operator === "f*") && currentSubpath === void 0 && pathSubpaths.length === 1 && pendingRect !== void 0) {
|
|
190
|
-
items.push({
|
|
191
|
-
kind: "rect",
|
|
192
|
-
...pendingRect,
|
|
193
|
-
color: gs.fillColor
|
|
194
|
-
});
|
|
195
|
-
resetPath();
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
337
|
finalizeCurrentSubpath();
|
|
199
338
|
if (pathSubpaths.length > 0) {
|
|
200
339
|
const isFillOp = operator === "f" || operator === "F" || operator === "f*" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
|
|
201
340
|
const isStrokeOp = operator === "S" || operator === "s" || operator === "B" || operator === "B*" || operator === "b" || operator === "b*";
|
|
202
|
-
|
|
203
|
-
kind: "path",
|
|
204
|
-
subpaths: pathSubpaths,
|
|
205
|
-
fillRule: paintFillRuleFor(operator),
|
|
341
|
+
const paint = {
|
|
206
342
|
fill: isFillOp ? gs.fillColor : void 0,
|
|
207
343
|
stroke: isStrokeOp ? {
|
|
208
344
|
color: gs.strokeColor,
|
|
209
345
|
widthPt: gs.lineWidth
|
|
210
346
|
} : void 0
|
|
347
|
+
};
|
|
348
|
+
items.push(classifyShape(pathSubpaths, paint) ?? {
|
|
349
|
+
kind: "path",
|
|
350
|
+
subpaths: pathSubpaths,
|
|
351
|
+
fillRule: paintFillRuleFor(operator),
|
|
352
|
+
...paint
|
|
211
353
|
});
|
|
212
354
|
}
|
|
213
355
|
resetPath();
|
|
@@ -394,7 +536,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
394
536
|
break;
|
|
395
537
|
}
|
|
396
538
|
case "re":
|
|
397
|
-
pendingRect = rectFromOperands(operands, gs.ctm);
|
|
398
539
|
appendRectSubpath(operands, gs.ctm);
|
|
399
540
|
break;
|
|
400
541
|
case "m": {
|
|
@@ -409,7 +550,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
409
550
|
segments: [],
|
|
410
551
|
closed: false
|
|
411
552
|
};
|
|
412
|
-
pendingRect = void 0;
|
|
413
553
|
break;
|
|
414
554
|
}
|
|
415
555
|
case "l": {
|
|
@@ -422,7 +562,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
422
562
|
xPt: p.x,
|
|
423
563
|
yPt: p.y
|
|
424
564
|
});
|
|
425
|
-
pendingRect = void 0;
|
|
426
565
|
break;
|
|
427
566
|
}
|
|
428
567
|
case "c": {
|
|
@@ -447,7 +586,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
447
586
|
xPt: p.x,
|
|
448
587
|
yPt: p.y
|
|
449
588
|
});
|
|
450
|
-
pendingRect = void 0;
|
|
451
589
|
break;
|
|
452
590
|
}
|
|
453
591
|
case "v":
|
|
@@ -471,7 +609,6 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
471
609
|
yPt: p.y
|
|
472
610
|
});
|
|
473
611
|
}
|
|
474
|
-
pendingRect = void 0;
|
|
475
612
|
break;
|
|
476
613
|
case "y": {
|
|
477
614
|
const c1 = applyMatrix(gs.ctm, {
|
|
@@ -491,12 +628,10 @@ function runContentStream(bytes, resources, initialState, context, items, depth)
|
|
|
491
628
|
xPt: p.x,
|
|
492
629
|
yPt: p.y
|
|
493
630
|
});
|
|
494
|
-
pendingRect = void 0;
|
|
495
631
|
break;
|
|
496
632
|
}
|
|
497
633
|
case "h":
|
|
498
634
|
if (currentSubpath !== void 0) currentSubpath.closed = true;
|
|
499
|
-
pendingRect = void 0;
|
|
500
635
|
break;
|
|
501
636
|
case "w":
|
|
502
637
|
gs = {
|
package/dist/math-font-write.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
3
2
|
const require_objects = require("./objects.cjs");
|
|
3
|
+
const require_bytes_flate = require("./bytes/flate.cjs");
|
|
4
|
+
const require_tounicode = require("./tounicode.cjs");
|
|
4
5
|
//#region src/math-font-write.ts
|
|
5
6
|
const FLAG_SYMBOLIC = 4;
|
|
6
7
|
const NOMINAL_STEM_V = 80;
|
|
@@ -37,36 +38,6 @@ function buildFontFileStream(font, compress) {
|
|
|
37
38
|
} : { Subtype: require_objects.pdfName("CIDFontType0C") });
|
|
38
39
|
return require_objects.pdfStream(dict, compress ? require_bytes_flate.deflate(font.cffBytes) : font.cffBytes);
|
|
39
40
|
}
|
|
40
|
-
function codePointToUtf16BEHex(codePoint) {
|
|
41
|
-
const text = String.fromCodePoint(codePoint);
|
|
42
|
-
let hex = "";
|
|
43
|
-
for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(16).padStart(4, "0");
|
|
44
|
-
return hex;
|
|
45
|
-
}
|
|
46
|
-
function buildToUnicodeCMap(usedGlyphs) {
|
|
47
|
-
const sortedGids = [...usedGlyphs.keys()].sort((a, b) => a - b);
|
|
48
|
-
const lines = [
|
|
49
|
-
"/CIDInit /ProcSet findresource begin",
|
|
50
|
-
"12 dict begin",
|
|
51
|
-
"begincmap",
|
|
52
|
-
"/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def",
|
|
53
|
-
"/CMapName /Adobe-Identity-UCS def",
|
|
54
|
-
"/CMapType 2 def",
|
|
55
|
-
"1 begincodespacerange",
|
|
56
|
-
"<0000> <FFFF>",
|
|
57
|
-
"endcodespacerange",
|
|
58
|
-
`${sortedGids.length} beginbfchar`
|
|
59
|
-
];
|
|
60
|
-
for (const gid of sortedGids) {
|
|
61
|
-
const codePoint = usedGlyphs.get(gid);
|
|
62
|
-
if (codePoint === void 0) continue;
|
|
63
|
-
lines.push(`<${gid.toString(16).padStart(4, "0")}> <${codePointToUtf16BEHex(codePoint)}>`);
|
|
64
|
-
}
|
|
65
|
-
lines.push("endbfchar", "endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
|
|
66
|
-
const text = `${lines.join("\n")}\n`;
|
|
67
|
-
const bytes = new TextEncoder().encode(text);
|
|
68
|
-
return require_objects.pdfStream(require_objects.pdfDict({}), bytes);
|
|
69
|
-
}
|
|
70
41
|
function buildMathFontObjects(font, usedGlyphs, refs, compress) {
|
|
71
42
|
const cidFont = require_objects.pdfDict({
|
|
72
43
|
Type: require_objects.pdfName("Font"),
|
|
@@ -93,7 +64,7 @@ function buildMathFontObjects(font, usedGlyphs, refs, compress) {
|
|
|
93
64
|
cidFont,
|
|
94
65
|
descriptor: buildFontDescriptor(font, refs.fontFileRef),
|
|
95
66
|
fontFile: buildFontFileStream(font, compress),
|
|
96
|
-
toUnicode: buildToUnicodeCMap(usedGlyphs)
|
|
67
|
+
toUnicode: require_tounicode.buildToUnicodeCMap(usedGlyphs)
|
|
97
68
|
};
|
|
98
69
|
}
|
|
99
70
|
//#endregion
|
package/dist/math-font-write.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { deflate } from "./bytes/flate.js";
|
|
2
1
|
import { pdfArray, pdfDict, pdfHexString, pdfName, pdfNum, pdfStream } from "./objects.js";
|
|
2
|
+
import { deflate } from "./bytes/flate.js";
|
|
3
|
+
import { buildToUnicodeCMap } from "./tounicode.js";
|
|
3
4
|
//#region src/math-font-write.ts
|
|
4
5
|
const FLAG_SYMBOLIC = 4;
|
|
5
6
|
const NOMINAL_STEM_V = 80;
|
|
@@ -36,36 +37,6 @@ function buildFontFileStream(font, compress) {
|
|
|
36
37
|
} : { Subtype: pdfName("CIDFontType0C") });
|
|
37
38
|
return pdfStream(dict, compress ? deflate(font.cffBytes) : font.cffBytes);
|
|
38
39
|
}
|
|
39
|
-
function codePointToUtf16BEHex(codePoint) {
|
|
40
|
-
const text = String.fromCodePoint(codePoint);
|
|
41
|
-
let hex = "";
|
|
42
|
-
for (let i = 0; i < text.length; i++) hex += text.charCodeAt(i).toString(16).padStart(4, "0");
|
|
43
|
-
return hex;
|
|
44
|
-
}
|
|
45
|
-
function buildToUnicodeCMap(usedGlyphs) {
|
|
46
|
-
const sortedGids = [...usedGlyphs.keys()].sort((a, b) => a - b);
|
|
47
|
-
const lines = [
|
|
48
|
-
"/CIDInit /ProcSet findresource begin",
|
|
49
|
-
"12 dict begin",
|
|
50
|
-
"begincmap",
|
|
51
|
-
"/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def",
|
|
52
|
-
"/CMapName /Adobe-Identity-UCS def",
|
|
53
|
-
"/CMapType 2 def",
|
|
54
|
-
"1 begincodespacerange",
|
|
55
|
-
"<0000> <FFFF>",
|
|
56
|
-
"endcodespacerange",
|
|
57
|
-
`${sortedGids.length} beginbfchar`
|
|
58
|
-
];
|
|
59
|
-
for (const gid of sortedGids) {
|
|
60
|
-
const codePoint = usedGlyphs.get(gid);
|
|
61
|
-
if (codePoint === void 0) continue;
|
|
62
|
-
lines.push(`<${gid.toString(16).padStart(4, "0")}> <${codePointToUtf16BEHex(codePoint)}>`);
|
|
63
|
-
}
|
|
64
|
-
lines.push("endbfchar", "endcmap", "CMapName currentdict /CMap defineresource pop", "end", "end");
|
|
65
|
-
const text = `${lines.join("\n")}\n`;
|
|
66
|
-
const bytes = new TextEncoder().encode(text);
|
|
67
|
-
return pdfStream(pdfDict({}), bytes);
|
|
68
|
-
}
|
|
69
40
|
function buildMathFontObjects(font, usedGlyphs, refs, compress) {
|
|
70
41
|
const cidFont = pdfDict({
|
|
71
42
|
Type: pdfName("Font"),
|
package/dist/math-font.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
+
const require_cmap_table = require("./cmap-table.cjs");
|
|
2
4
|
const require_util_base64 = require("./util/base64.cjs");
|
|
5
|
+
const require_hmtx_table = require("./hmtx-table.cjs");
|
|
3
6
|
const require_assets_stix_two_math_font = require("./assets/stix-two-math-font.cjs");
|
|
4
|
-
const require_sfnt = require("./sfnt.cjs");
|
|
5
|
-
const require_math_cmap = require("./math-cmap.cjs");
|
|
6
|
-
const require_math_hmtx = require("./math-hmtx.cjs");
|
|
7
7
|
const require_math_table = require("./math-table.cjs");
|
|
8
8
|
//#region src/math-font.ts
|
|
9
9
|
function toPt(designUnits, unitsPerEm, sizePt) {
|
|
@@ -65,6 +65,7 @@ function loadMathFont() {
|
|
|
65
65
|
if (cached !== void 0) return cached;
|
|
66
66
|
const bytes = require_util_base64.base64ToBytes(require_assets_stix_two_math_font.STIX_TWO_MATH_FONT_BASE64);
|
|
67
67
|
const sfnt = require_sfnt.parseSfnt(bytes);
|
|
68
|
+
if (sfnt === void 0) throw new Error("embedded math font is not a readable sfnt container");
|
|
68
69
|
const headBytes = require_sfnt.sfntTableBytes(sfnt, "head");
|
|
69
70
|
const hheaBytes = require_sfnt.sfntTableBytes(sfnt, "hhea");
|
|
70
71
|
const os2Bytes = require_sfnt.sfntTableBytes(sfnt, "OS/2");
|
|
@@ -76,8 +77,9 @@ function loadMathFont() {
|
|
|
76
77
|
const bboxMin = [require_sfnt.i16(headBytes, 36), require_sfnt.i16(headBytes, 38)];
|
|
77
78
|
const bboxMax = [require_sfnt.i16(headBytes, 40), require_sfnt.i16(headBytes, 42)];
|
|
78
79
|
const capHeight = os2Bytes === void 0 ? ascentDesignUnits : require_sfnt.i16(os2Bytes, 88);
|
|
79
|
-
const cmap =
|
|
80
|
-
|
|
80
|
+
const cmap = require_cmap_table.buildCmapLookup(sfnt);
|
|
81
|
+
if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
|
|
82
|
+
const hmtx = require_hmtx_table.parseHmtx(sfnt);
|
|
81
83
|
const math = require_math_table.parseMathTable(sfnt);
|
|
82
84
|
cached = {
|
|
83
85
|
font: {
|
package/dist/math-font.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { i16, parseSfnt, sfntTableBytes, u16 } from "./sfnt.js";
|
|
2
|
+
import { buildCmapLookup } from "./cmap-table.js";
|
|
1
3
|
import { base64ToBytes } from "./util/base64.js";
|
|
4
|
+
import { parseHmtx } from "./hmtx-table.js";
|
|
2
5
|
import { STIX_TWO_MATH_FONT_BASE64 } from "./assets/stix-two-math-font.js";
|
|
3
|
-
import { i16, parseSfnt, sfntTableBytes, u16 } from "./sfnt.js";
|
|
4
|
-
import { buildCmapLookup } from "./math-cmap.js";
|
|
5
|
-
import { parseHmtx } from "./math-hmtx.js";
|
|
6
6
|
import { parseMathTable } from "./math-table.js";
|
|
7
7
|
//#region src/math-font.ts
|
|
8
8
|
function toPt(designUnits, unitsPerEm, sizePt) {
|
|
@@ -64,6 +64,7 @@ function loadMathFont() {
|
|
|
64
64
|
if (cached !== void 0) return cached;
|
|
65
65
|
const bytes = base64ToBytes(STIX_TWO_MATH_FONT_BASE64);
|
|
66
66
|
const sfnt = parseSfnt(bytes);
|
|
67
|
+
if (sfnt === void 0) throw new Error("embedded math font is not a readable sfnt container");
|
|
67
68
|
const headBytes = sfntTableBytes(sfnt, "head");
|
|
68
69
|
const hheaBytes = sfntTableBytes(sfnt, "hhea");
|
|
69
70
|
const os2Bytes = sfntTableBytes(sfnt, "OS/2");
|
|
@@ -76,6 +77,7 @@ function loadMathFont() {
|
|
|
76
77
|
const bboxMax = [i16(headBytes, 40), i16(headBytes, 42)];
|
|
77
78
|
const capHeight = os2Bytes === void 0 ? ascentDesignUnits : i16(os2Bytes, 88);
|
|
78
79
|
const cmap = buildCmapLookup(sfnt);
|
|
80
|
+
if (cmap === void 0) throw new Error("embedded math font has no readable cmap subtable");
|
|
79
81
|
const hmtx = parseHmtx(sfnt);
|
|
80
82
|
const math = parseMathTable(sfnt);
|
|
81
83
|
cached = {
|
package/dist/math-table.d.cts
CHANGED
package/dist/math-table.d.ts
CHANGED
|
@@ -9,10 +9,11 @@ interface Point {
|
|
|
9
9
|
declare function applyMatrix(m: Matrix, point: Point): Point;
|
|
10
10
|
declare function translationMatrix(x: number, y: number): Matrix;
|
|
11
11
|
declare function scaleMatrix(sx: number, sy: number): Matrix;
|
|
12
|
+
declare const BEZIER_KAPPA = 0.5522847498;
|
|
12
13
|
declare function rotationMatrix(degrees: number): Matrix;
|
|
13
14
|
declare function matrixScaleX(m: Matrix): number;
|
|
14
15
|
declare function matrixScaleY(m: Matrix): number;
|
|
15
16
|
declare function matrixRotationDegrees(m: Matrix): number;
|
|
16
17
|
declare function rotatePointAboutCenter(point: Point, center: Point, degrees: number): Point;
|
|
17
18
|
//#endregion
|
|
18
|
-
export {
|
|
19
|
+
export { applyMatrix as a, matrixScaleY as c, rotationMatrix as d, scaleMatrix as f, Point as i, multiplyMatrices as l, IDENTITY_MATRIX as n, matrixRotationDegrees as o, translationMatrix as p, Matrix as r, matrixScaleX as s, BEZIER_KAPPA as t, rotatePointAboutCenter as u };
|
|
@@ -9,10 +9,11 @@ interface Point {
|
|
|
9
9
|
declare function applyMatrix(m: Matrix, point: Point): Point;
|
|
10
10
|
declare function translationMatrix(x: number, y: number): Matrix;
|
|
11
11
|
declare function scaleMatrix(sx: number, sy: number): Matrix;
|
|
12
|
+
declare const BEZIER_KAPPA = 0.5522847498;
|
|
12
13
|
declare function rotationMatrix(degrees: number): Matrix;
|
|
13
14
|
declare function matrixScaleX(m: Matrix): number;
|
|
14
15
|
declare function matrixScaleY(m: Matrix): number;
|
|
15
16
|
declare function matrixRotationDegrees(m: Matrix): number;
|
|
16
17
|
declare function rotatePointAboutCenter(point: Point, center: Point, degrees: number): Point;
|
|
17
18
|
//#endregion
|
|
18
|
-
export {
|
|
19
|
+
export { applyMatrix as a, matrixScaleY as c, rotationMatrix as d, scaleMatrix as f, Point as i, multiplyMatrices as l, IDENTITY_MATRIX as n, matrixRotationDegrees as o, translationMatrix as p, Matrix as r, matrixScaleX as s, BEZIER_KAPPA as t, rotatePointAboutCenter as u };
|
package/dist/matrix.cjs
CHANGED
|
@@ -47,6 +47,7 @@ function scaleMatrix(sx, sy) {
|
|
|
47
47
|
0
|
|
48
48
|
];
|
|
49
49
|
}
|
|
50
|
+
const BEZIER_KAPPA = .5522847498;
|
|
50
51
|
function rotationMatrix(degrees) {
|
|
51
52
|
const radians = degrees * Math.PI / 180;
|
|
52
53
|
const cos = Math.cos(radians);
|
|
@@ -81,6 +82,7 @@ function rotatePointAboutCenter(point, center, degrees) {
|
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
84
|
//#endregion
|
|
85
|
+
exports.BEZIER_KAPPA = BEZIER_KAPPA;
|
|
84
86
|
exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
|
|
85
87
|
exports.applyMatrix = applyMatrix;
|
|
86
88
|
exports.matrixRotationDegrees = matrixRotationDegrees;
|
package/dist/matrix.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
|
1
|
+
import { a as applyMatrix, c as matrixScaleY, d as rotationMatrix, f as scaleMatrix, i as Point, l as multiplyMatrices, n as IDENTITY_MATRIX, o as matrixRotationDegrees, p as translationMatrix, r as Matrix, s as matrixScaleX, t as BEZIER_KAPPA, u as rotatePointAboutCenter } from "./matrix-BHzJESll.cjs";
|
|
2
|
+
export { BEZIER_KAPPA, IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
package/dist/matrix.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
|
1
|
+
import { a as applyMatrix, c as matrixScaleY, d as rotationMatrix, f as scaleMatrix, i as Point, l as multiplyMatrices, n as IDENTITY_MATRIX, o as matrixRotationDegrees, p as translationMatrix, r as Matrix, s as matrixScaleX, t as BEZIER_KAPPA, u as rotatePointAboutCenter } from "./matrix-BHzJESll.js";
|
|
2
|
+
export { BEZIER_KAPPA, IDENTITY_MATRIX, Matrix, Point, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
package/dist/matrix.js
CHANGED
|
@@ -46,6 +46,7 @@ function scaleMatrix(sx, sy) {
|
|
|
46
46
|
0
|
|
47
47
|
];
|
|
48
48
|
}
|
|
49
|
+
const BEZIER_KAPPA = .5522847498;
|
|
49
50
|
function rotationMatrix(degrees) {
|
|
50
51
|
const radians = degrees * Math.PI / 180;
|
|
51
52
|
const cos = Math.cos(radians);
|
|
@@ -80,4 +81,4 @@ function rotatePointAboutCenter(point, center, degrees) {
|
|
|
80
81
|
};
|
|
81
82
|
}
|
|
82
83
|
//#endregion
|
|
83
|
-
export { IDENTITY_MATRIX, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
|
84
|
+
export { BEZIER_KAPPA, IDENTITY_MATRIX, applyMatrix, matrixRotationDegrees, matrixScaleX, matrixScaleY, multiplyMatrices, rotatePointAboutCenter, rotationMatrix, scaleMatrix, translationMatrix };
|
package/dist/measure.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_afm_widths = require("./afm-widths-BoeTOK2r.cjs");
|
|
3
|
-
const
|
|
3
|
+
const require_embedded_font = require("./embedded-font.cjs");
|
|
4
|
+
const require_font_registry = require("./font-registry.cjs");
|
|
4
5
|
//#region src/measure.ts
|
|
6
|
+
const GLYPH_SPACE_UNITS_PER_EM = 1e3;
|
|
5
7
|
const DEFAULT_WIDTH_CORRECTIONS = {
|
|
6
8
|
calibri: .92,
|
|
7
9
|
aptos: .93,
|
|
@@ -13,42 +15,91 @@ const DEFAULT_WIDTH_CORRECTIONS = {
|
|
|
13
15
|
function normalizeFamilyKey(family) {
|
|
14
16
|
return family.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
15
17
|
}
|
|
16
|
-
|
|
18
|
+
const EMBEDDED_HORIZONTAL_SCALE = 1;
|
|
19
|
+
const DEFAULT_VERTICAL_METRIC_POLICY = "hhea";
|
|
20
|
+
function verticalMetricsFor(face, policy) {
|
|
21
|
+
const m = face.metrics;
|
|
22
|
+
const hhea = {
|
|
23
|
+
ascentGlyphSpace: m.ascentGlyphSpace,
|
|
24
|
+
descentGlyphSpace: m.descentGlyphSpace,
|
|
25
|
+
lineGapGlyphSpace: m.lineGapGlyphSpace
|
|
26
|
+
};
|
|
27
|
+
if (policy === "os2Typo") {
|
|
28
|
+
if (m.typoAscentGlyphSpace === void 0 || m.typoDescentGlyphSpace === void 0 || m.typoLineGapGlyphSpace === void 0) return hhea;
|
|
29
|
+
return {
|
|
30
|
+
ascentGlyphSpace: m.typoAscentGlyphSpace,
|
|
31
|
+
descentGlyphSpace: m.typoDescentGlyphSpace,
|
|
32
|
+
lineGapGlyphSpace: m.typoLineGapGlyphSpace
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (policy === "os2Win") {
|
|
36
|
+
if (m.winAscentGlyphSpace === void 0 || m.winDescentGlyphSpace === void 0) return hhea;
|
|
37
|
+
return {
|
|
38
|
+
ascentGlyphSpace: m.winAscentGlyphSpace,
|
|
39
|
+
descentGlyphSpace: m.winDescentGlyphSpace,
|
|
40
|
+
lineGapGlyphSpace: 0
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return hhea;
|
|
44
|
+
}
|
|
45
|
+
function createFontMeasurer(registry, options = {}) {
|
|
17
46
|
const corrections = {
|
|
18
47
|
...DEFAULT_WIDTH_CORRECTIONS,
|
|
19
48
|
...options.widthCorrectionByFamily
|
|
20
49
|
};
|
|
21
|
-
|
|
50
|
+
const verticalPolicy = options.verticalMetrics ?? "hhea";
|
|
51
|
+
function standardWidthCorrectionFor(family) {
|
|
22
52
|
return corrections[normalizeFamilyKey(family)] ?? 1;
|
|
23
53
|
}
|
|
24
|
-
function
|
|
25
|
-
return
|
|
54
|
+
function resolve(font) {
|
|
55
|
+
return require_font_registry.resolveFaceWithRegistry(registry, font);
|
|
26
56
|
}
|
|
27
57
|
return {
|
|
28
58
|
widthOfTextAtSize(text, font, sizePt) {
|
|
29
|
-
const
|
|
30
|
-
return width1000 /
|
|
59
|
+
const face = resolve(font);
|
|
60
|
+
if (face.kind === "embedded") return require_embedded_font.encodeForShowEmbedded(text, face.face).width1000 / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
61
|
+
const { width1000 } = require_afm_widths.encodeForShow(text, face.standardName);
|
|
62
|
+
return width1000 / GLYPH_SPACE_UNITS_PER_EM * sizePt * standardWidthCorrectionFor(font.family);
|
|
31
63
|
},
|
|
32
64
|
lineHeightAtSize(font, sizePt) {
|
|
33
|
-
|
|
65
|
+
const face = resolve(font);
|
|
66
|
+
if (face.kind === "embedded") {
|
|
67
|
+
const vertical = verticalMetricsFor(face.face, verticalPolicy);
|
|
68
|
+
return (vertical.ascentGlyphSpace - vertical.descentGlyphSpace + vertical.lineGapGlyphSpace) / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
69
|
+
}
|
|
70
|
+
return require_afm_widths.STANDARD_METRICS[face.standardName].lineHeightEm * sizePt;
|
|
34
71
|
},
|
|
35
72
|
ascenderAtSize(font, sizePt) {
|
|
36
|
-
|
|
73
|
+
const face = resolve(font);
|
|
74
|
+
if (face.kind === "embedded") return verticalMetricsFor(face.face, verticalPolicy).ascentGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
75
|
+
return require_afm_widths.STANDARD_METRICS[face.standardName].ascender / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
37
76
|
},
|
|
38
77
|
descenderAtSize(font, sizePt) {
|
|
39
|
-
|
|
78
|
+
const face = resolve(font);
|
|
79
|
+
if (face.kind === "embedded") return verticalMetricsFor(face.face, verticalPolicy).descentGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
80
|
+
return require_afm_widths.STANDARD_METRICS[face.standardName].descender / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
40
81
|
},
|
|
41
82
|
underlineAtSize(font, sizePt) {
|
|
42
|
-
const
|
|
83
|
+
const face = resolve(font);
|
|
84
|
+
if (face.kind === "embedded") return {
|
|
85
|
+
offsetPt: face.face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt,
|
|
86
|
+
thicknessPt: face.face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt
|
|
87
|
+
};
|
|
88
|
+
const metrics = require_afm_widths.STANDARD_METRICS[face.standardName];
|
|
43
89
|
return {
|
|
44
|
-
offsetPt: metrics.underlinePosition /
|
|
45
|
-
thicknessPt: metrics.underlineThickness /
|
|
90
|
+
offsetPt: metrics.underlinePosition / GLYPH_SPACE_UNITS_PER_EM * sizePt,
|
|
91
|
+
thicknessPt: metrics.underlineThickness / GLYPH_SPACE_UNITS_PER_EM * sizePt
|
|
46
92
|
};
|
|
47
93
|
},
|
|
48
94
|
horizontalScaleFor(font) {
|
|
49
|
-
return
|
|
95
|
+
return resolve(font).kind === "embedded" ? EMBEDDED_HORIZONTAL_SCALE : standardWidthCorrectionFor(font.family);
|
|
50
96
|
}
|
|
51
97
|
};
|
|
52
98
|
}
|
|
99
|
+
function createStandardFontMeasurer(options = {}) {
|
|
100
|
+
return createFontMeasurer(void 0, options);
|
|
101
|
+
}
|
|
53
102
|
//#endregion
|
|
103
|
+
exports.DEFAULT_VERTICAL_METRIC_POLICY = DEFAULT_VERTICAL_METRIC_POLICY;
|
|
104
|
+
exports.createFontMeasurer = createFontMeasurer;
|
|
54
105
|
exports.createStandardFontMeasurer = createStandardFontMeasurer;
|