pdf-codec 5.7.3 → 5.8.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 +6 -3
- package/dist/afm-widths.cjs +247 -4
- package/dist/afm-widths.js +244 -1
- package/dist/builtin-encoding.cjs +75 -16
- package/dist/builtin-encoding.d.cts +10 -3
- package/dist/builtin-encoding.d.ts +10 -3
- package/dist/builtin-encoding.js +74 -15
- package/dist/content-write.cjs +2 -2
- package/dist/content-write.js +1 -1
- package/dist/core-font-glyph-orders.cjs +62 -0
- package/dist/core-font-glyph-orders.d.cts +10 -0
- package/dist/core-font-glyph-orders.d.ts +10 -0
- package/dist/core-font-glyph-orders.js +61 -0
- package/dist/encoding.cjs +273 -5
- package/dist/encoding.d.cts +1 -2
- package/dist/encoding.d.ts +1 -2
- package/dist/encoding.js +271 -2
- package/dist/font-read.cjs +52 -18
- package/dist/font-read.js +49 -15
- package/dist/font-style.cjs +12 -1
- package/dist/font-style.d.cts +9 -1
- package/dist/font-style.d.ts +9 -1
- package/dist/font-style.js +12 -2
- package/dist/glyph-data/adobe-glyph-list.cjs +7 -0
- package/dist/glyph-data/adobe-glyph-list.d.cts +5 -0
- package/dist/glyph-data/adobe-glyph-list.d.ts +5 -0
- package/dist/glyph-data/adobe-glyph-list.js +5 -0
- package/dist/glyph-data/core-font-glyph-orders.cjs +5 -0
- package/dist/glyph-data/core-font-glyph-orders.d.cts +4 -0
- package/dist/glyph-data/core-font-glyph-orders.d.ts +4 -0
- package/dist/glyph-data/core-font-glyph-orders.js +4 -0
- package/dist/glyph-names.cjs +63 -0
- package/dist/glyph-names.d.cts +9 -0
- package/dist/glyph-names.d.ts +9 -0
- package/dist/glyph-names.js +62 -0
- package/dist/index.cjs +3 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/measure.cjs +3 -2
- package/dist/measure.js +2 -1
- package/dist/text-group.cjs +19 -2
- package/dist/text-group.d.cts +13 -1
- package/dist/text-group.d.ts +13 -1
- package/dist/text-group.js +18 -3
- package/dist/winansi.cjs +162 -4
- package/dist/winansi.d.cts +1 -2
- package/dist/winansi.d.ts +1 -2
- package/dist/winansi.js +161 -2
- package/dist/write.cjs +1 -1
- package/dist/write.js +1 -1
- package/package.json +1 -1
- package/dist/afm-widths-BNI8qa2S.js +0 -710
- package/dist/afm-widths-sjaRvmQX.cjs +0 -769
- package/dist/encoding-glyph-unicode.cjs +0 -353
- package/dist/encoding-glyph-unicode.d.cts +0 -4
- package/dist/encoding-glyph-unicode.d.ts +0 -4
- package/dist/encoding-glyph-unicode.js +0 -352
package/dist/builtin-encoding.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { standardGlyphName } from "./encoding-standard-tables.js";
|
|
2
|
-
import { a as glyphNameToUnicode } from "./afm-widths-BNI8qa2S.js";
|
|
3
2
|
import { hasBytes, parseSfnt, sfntTableBytes, u16, u8 } from "./sfnt.js";
|
|
4
3
|
import { cffStringForSid, parseCffDict, readCffIndex } from "./cff.js";
|
|
5
4
|
import { readCmapSubtables } from "./cmap-table.js";
|
|
6
|
-
import {
|
|
5
|
+
import { coreFaceGlyphOrder } from "./core-font-glyph-orders.js";
|
|
6
|
+
import { withoutSubsetTag } from "./font-style.js";
|
|
7
|
+
import { parseHead, parseMaxp, parseName, parsePostGlyphNames } from "./font-tables.js";
|
|
8
|
+
import { glyphNameToUnicode } from "./glyph-names.js";
|
|
7
9
|
//#region src/builtin-encoding.ts
|
|
8
10
|
const PRIVATE_USE_BMP_START = 57344;
|
|
9
11
|
const PRIVATE_USE_BMP_END = 63743;
|
|
@@ -15,7 +17,7 @@ function isPrivateUse(codePoint) {
|
|
|
15
17
|
return codePoint >= PRIVATE_USE_BMP_START && codePoint <= PRIVATE_USE_BMP_END || codePoint >= PRIVATE_USE_PLANE_A_START && codePoint <= PRIVATE_USE_PLANE_A_END || codePoint >= PRIVATE_USE_PLANE_B_START && codePoint <= PRIVATE_USE_PLANE_B_END;
|
|
16
18
|
}
|
|
17
19
|
function encodingFromSources(sources) {
|
|
18
|
-
const { codeToGlyphId, codeToName, glyphIdToName, glyphIdToUnicode } = sources;
|
|
20
|
+
const { codeToGlyphId, codeToName, glyphIdToName, nameToGlyphId, glyphIdToUnicode } = sources;
|
|
19
21
|
const glyphUnicode = (glyphId) => {
|
|
20
22
|
const name = glyphIdToName?.(glyphId);
|
|
21
23
|
return (name !== void 0 ? glyphNameToUnicode(name) : void 0) ?? glyphIdToUnicode?.(glyphId);
|
|
@@ -31,9 +33,24 @@ function encodingFromSources(sources) {
|
|
|
31
33
|
};
|
|
32
34
|
return codeToName !== void 0 || codeToGlyphId !== void 0 || glyphIdToName !== void 0 || glyphIdToUnicode !== void 0 ? {
|
|
33
35
|
codeToUnicode: codeUnicode,
|
|
34
|
-
glyphIdToUnicode: glyphUnicode
|
|
36
|
+
glyphIdToUnicode: glyphUnicode,
|
|
37
|
+
glyphIdOfName: (name) => nameToGlyphId?.(name)
|
|
35
38
|
} : void 0;
|
|
36
39
|
}
|
|
40
|
+
function invertGlyphNames(glyphIdToName, glyphCount) {
|
|
41
|
+
let inverse;
|
|
42
|
+
return (name) => {
|
|
43
|
+
if (inverse === void 0) {
|
|
44
|
+
const built = /* @__PURE__ */ new Map();
|
|
45
|
+
for (let glyphId = 0; glyphId < glyphCount; glyphId++) {
|
|
46
|
+
const glyphName = glyphIdToName(glyphId);
|
|
47
|
+
if (glyphName !== void 0 && !built.has(glyphName)) built.set(glyphName, glyphId);
|
|
48
|
+
}
|
|
49
|
+
inverse = built;
|
|
50
|
+
}
|
|
51
|
+
return inverse.get(name);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
37
54
|
const SYMBOL_CMAP_CODE_BASE = 61440;
|
|
38
55
|
const CMAP_PLATFORM_MICROSOFT = 3;
|
|
39
56
|
const CMAP_MICROSOFT_ENCODING_SYMBOL = 0;
|
|
@@ -55,17 +72,43 @@ function invertUnicodeSubtable(subtable) {
|
|
|
55
72
|
});
|
|
56
73
|
inverse = built;
|
|
57
74
|
}
|
|
58
|
-
|
|
75
|
+
const codePoint = inverse.get(glyphId);
|
|
76
|
+
return codePoint === void 0 ? void 0 : String.fromCodePoint(codePoint);
|
|
59
77
|
};
|
|
60
78
|
}
|
|
61
|
-
|
|
79
|
+
const HHEA_NUMBER_OF_H_METRICS_OFFSET = 34;
|
|
80
|
+
const HMTX_LONG_HOR_METRIC_SIZE = 4;
|
|
81
|
+
function advanceWidths(font) {
|
|
82
|
+
const hhea = sfntTableBytes(font, "hhea");
|
|
83
|
+
const hmtx = sfntTableBytes(font, "hmtx");
|
|
84
|
+
if (hhea === void 0 || hmtx === void 0 || !hasBytes(hhea, HHEA_NUMBER_OF_H_METRICS_OFFSET, 2)) return;
|
|
85
|
+
const metricCount = u16(hhea, HHEA_NUMBER_OF_H_METRICS_OFFSET);
|
|
86
|
+
if (metricCount === 0 || !hasBytes(hmtx, 0, metricCount * HMTX_LONG_HOR_METRIC_SIZE)) return;
|
|
87
|
+
return (glyphId) => u16(hmtx, Math.min(glyphId, metricCount - 1) * HMTX_LONG_HOR_METRIC_SIZE);
|
|
88
|
+
}
|
|
89
|
+
function coreFaceSource(font, fontName) {
|
|
90
|
+
const name = parseName(font)?.postScriptName ?? fontName;
|
|
91
|
+
const unitsPerEm = parseHead(font)?.unitsPerEm;
|
|
92
|
+
const advanceOf = advanceWidths(font);
|
|
93
|
+
if (name === void 0 || unitsPerEm === void 0 || advanceOf === void 0) return;
|
|
94
|
+
const order = coreFaceGlyphOrder(withoutSubsetTag(name), unitsPerEm);
|
|
95
|
+
if (order === void 0) return;
|
|
96
|
+
return (glyphId) => order(glyphId, advanceOf(glyphId));
|
|
97
|
+
}
|
|
98
|
+
function trueTypeSources(font, fontName) {
|
|
62
99
|
const subtables = readCmapSubtables(font);
|
|
63
100
|
const symbol = symbolSubtable(subtables);
|
|
64
101
|
const unicode = unicodeSubtable(subtables);
|
|
102
|
+
const symbolLookup = symbol !== void 0 ? (code) => symbol.lookup(SYMBOL_CMAP_CODE_BASE | code) ?? symbol.lookup(code) : unicode !== void 0 ? (code) => unicode.lookup(SYMBOL_CMAP_CODE_BASE | code) : void 0;
|
|
103
|
+
const glyphIdToName = parsePostGlyphNames(font);
|
|
104
|
+
const glyphCount = parseMaxp(font)?.numGlyphs;
|
|
105
|
+
const fromCmap = unicode !== void 0 ? invertUnicodeSubtable(unicode) : void 0;
|
|
106
|
+
const fromCoreFace = coreFaceSource(font, fontName);
|
|
65
107
|
return {
|
|
66
|
-
codeToGlyphId:
|
|
67
|
-
glyphIdToName
|
|
68
|
-
|
|
108
|
+
codeToGlyphId: symbolLookup,
|
|
109
|
+
glyphIdToName,
|
|
110
|
+
nameToGlyphId: glyphIdToName !== void 0 && glyphCount !== void 0 ? invertGlyphNames(glyphIdToName, glyphCount) : void 0,
|
|
111
|
+
glyphIdToUnicode: fromCmap === void 0 && fromCoreFace === void 0 ? void 0 : (glyphId) => fromCmap?.(glyphId) ?? fromCoreFace?.(glyphId)
|
|
69
112
|
};
|
|
70
113
|
}
|
|
71
114
|
const CFF_HEADER_SIZE = 4;
|
|
@@ -170,17 +213,26 @@ function cffSources(bytes, predefinedEncodingApplies) {
|
|
|
170
213
|
const sid = sidByGlyph.get(glyphId);
|
|
171
214
|
return sid === void 0 ? void 0 : cffStringForSid(sid, stringIndex);
|
|
172
215
|
};
|
|
216
|
+
const nameToGlyphId = glyphIdToName === void 0 ? void 0 : invertGlyphNames(glyphIdToName, glyphCount);
|
|
173
217
|
const encodingOffset = topDict.get(16)?.[0] ?? CFF_PREDEFINED_ENCODING_STANDARD;
|
|
174
218
|
if (encodingOffset === CFF_PREDEFINED_ENCODING_STANDARD) return predefinedEncodingApplies ? {
|
|
175
219
|
codeToName: standardGlyphName,
|
|
176
|
-
glyphIdToName
|
|
177
|
-
|
|
220
|
+
glyphIdToName,
|
|
221
|
+
nameToGlyphId
|
|
222
|
+
} : {
|
|
223
|
+
glyphIdToName,
|
|
224
|
+
nameToGlyphId
|
|
225
|
+
};
|
|
178
226
|
const glyphBySid = /* @__PURE__ */ new Map();
|
|
179
227
|
for (const [glyphId, sid] of sidByGlyph ?? []) if (!glyphBySid.has(sid)) glyphBySid.set(sid, glyphId);
|
|
180
228
|
const glyphByCode = readCffEncoding(bytes, encodingOffset, glyphCount, glyphBySid);
|
|
181
|
-
return glyphByCode === void 0 ? {
|
|
229
|
+
return glyphByCode === void 0 ? {
|
|
230
|
+
glyphIdToName,
|
|
231
|
+
nameToGlyphId
|
|
232
|
+
} : {
|
|
182
233
|
codeToGlyphId: (code) => glyphByCode.get(code),
|
|
183
|
-
glyphIdToName
|
|
234
|
+
glyphIdToName,
|
|
235
|
+
nameToGlyphId
|
|
184
236
|
};
|
|
185
237
|
}
|
|
186
238
|
function matchesAscii(bytes, offset, text) {
|
|
@@ -211,15 +263,22 @@ function type1Sources(bytes) {
|
|
|
211
263
|
}
|
|
212
264
|
return nameByCode.size === 0 ? void 0 : { codeToName: (code) => nameByCode.get(code) };
|
|
213
265
|
}
|
|
214
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Reads whatever encoding an embedded font program carries in itself.
|
|
268
|
+
* @param program - the decoded bytes of a /FontFile, /FontFile2 or /FontFile3 stream
|
|
269
|
+
* @param fontName - the font dictionary's /BaseFont, which identifies a core face only when the program's own 'name' table states no PostScript name; absent when the program is read on its own
|
|
270
|
+
* @returns the program's encoding, or undefined when it states nothing this codec can read (a program in a format not read here, or one too damaged to parse), in which case the caller must fall back rather than treat the absence as a mapping
|
|
271
|
+
*/
|
|
272
|
+
function readFontProgramEncoding(program, fontName) {
|
|
215
273
|
const font = parseSfnt(program);
|
|
216
274
|
if (font !== void 0) {
|
|
217
275
|
const cff = sfntTableBytes(font, "CFF ");
|
|
218
|
-
const container = trueTypeSources(font);
|
|
276
|
+
const container = trueTypeSources(font, fontName);
|
|
219
277
|
const outlines = cff === void 0 ? void 0 : cffSources(cff, false);
|
|
220
278
|
return encodingFromSources({
|
|
221
279
|
codeToGlyphId: container.codeToGlyphId ?? outlines?.codeToGlyphId,
|
|
222
280
|
glyphIdToName: container.glyphIdToName ?? outlines?.glyphIdToName,
|
|
281
|
+
nameToGlyphId: container.nameToGlyphId ?? outlines?.nameToGlyphId,
|
|
223
282
|
glyphIdToUnicode: container.glyphIdToUnicode
|
|
224
283
|
});
|
|
225
284
|
}
|
package/dist/content-write.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_afm_widths = require("./afm-widths-sjaRvmQX.cjs");
|
|
3
2
|
const require_objects = require("./objects.cjs");
|
|
4
3
|
const require_bytes_writer = require("./bytes/writer.cjs");
|
|
5
4
|
const require_serialize = require("./serialize.cjs");
|
|
6
5
|
const require_matrix = require("./matrix.cjs");
|
|
7
6
|
const require_embedded_font = require("./embedded-font.cjs");
|
|
7
|
+
const require_winansi = require("./winansi.cjs");
|
|
8
8
|
//#region src/content-write.ts
|
|
9
9
|
const GLYPH_SPACE_UNITS_PER_EM = 1e3;
|
|
10
10
|
const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
|
|
@@ -45,7 +45,7 @@ function writeShowTextBlock(writer, item, resourceName, scalePercent, show) {
|
|
|
45
45
|
writer.writeAscii("ET\n");
|
|
46
46
|
}
|
|
47
47
|
function writeStandardText(writer, item, standardName, resourceName, measurer) {
|
|
48
|
-
const encoded =
|
|
48
|
+
const encoded = require_winansi.encodeForShow(item.text, standardName);
|
|
49
49
|
const scale = measurer.horizontalScaleFor(item.font);
|
|
50
50
|
writeShowTextBlock(writer, item, resourceName, scale * PERCENT_SCALE_FACTOR, {
|
|
51
51
|
operand: require_objects.pdfHexString(encoded.codes),
|
package/dist/content-write.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { c as encodeForShow } from "./afm-widths-BNI8qa2S.js";
|
|
2
1
|
import { pdfArray, pdfHexString, pdfNum } from "./objects.js";
|
|
3
2
|
import { ByteWriter } from "./bytes/writer.js";
|
|
4
3
|
import { formatNumber, writeObject } from "./serialize.js";
|
|
5
4
|
import { BEZIER_KAPPA, multiplyMatrices, rotationMatrix, scaleMatrix, translationMatrix } from "./matrix.js";
|
|
6
5
|
import { encodeForShowEmbedded } from "./embedded-font.js";
|
|
6
|
+
import { encodeForShow } from "./winansi.js";
|
|
7
7
|
//#region src/content-write.ts
|
|
8
8
|
const GLYPH_SPACE_UNITS_PER_EM = 1e3;
|
|
9
9
|
const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_glyph_data_core_font_glyph_orders = require("./glyph-data/core-font-glyph-orders.cjs");
|
|
3
|
+
let fflate = require("fflate");
|
|
4
|
+
let byte_codec = require("byte-codec");
|
|
5
|
+
//#region src/core-font-glyph-orders.ts
|
|
6
|
+
const FACE_COUNT_SIZE = 2;
|
|
7
|
+
const NAME_LENGTH_SIZE = 1;
|
|
8
|
+
const FACE_HEADER_SIZE = 4;
|
|
9
|
+
const CODE_POINT_COUNT_SIZE = 1;
|
|
10
|
+
const CODE_POINT_SIZE = 3;
|
|
11
|
+
const ADVANCE_SIZE = 2;
|
|
12
|
+
let faces;
|
|
13
|
+
function readFaces() {
|
|
14
|
+
if (faces !== void 0) return faces;
|
|
15
|
+
const bytes = (0, fflate.inflateSync)((0, byte_codec.base64ToBytes)(require_glyph_data_core_font_glyph_orders.CORE_FONT_GLYPH_ORDERS_DEFLATED_BASE64));
|
|
16
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
17
|
+
const read = /* @__PURE__ */ new Map();
|
|
18
|
+
let at = FACE_COUNT_SIZE;
|
|
19
|
+
for (let face = 0; face < view.getUint16(0); face++) {
|
|
20
|
+
const nameLength = view.getUint8(at);
|
|
21
|
+
at += NAME_LENGTH_SIZE;
|
|
22
|
+
const name = String.fromCharCode(...bytes.subarray(at, at + nameLength));
|
|
23
|
+
at += nameLength;
|
|
24
|
+
const unitsPerEm = view.getUint16(at);
|
|
25
|
+
const glyphCount = view.getUint16(at + 2);
|
|
26
|
+
at += FACE_HEADER_SIZE;
|
|
27
|
+
const texts = [];
|
|
28
|
+
const advances = new Uint16Array(glyphCount);
|
|
29
|
+
for (let glyphId = 0; glyphId < glyphCount; glyphId++) {
|
|
30
|
+
const codePointCount = view.getUint8(at);
|
|
31
|
+
at += CODE_POINT_COUNT_SIZE;
|
|
32
|
+
const codePoints = [];
|
|
33
|
+
for (let i = 0; i < codePointCount; i++) {
|
|
34
|
+
codePoints.push(view.getUint8(at) << 16 | view.getUint16(at + 1));
|
|
35
|
+
at += CODE_POINT_SIZE;
|
|
36
|
+
}
|
|
37
|
+
texts.push(codePoints.length === 0 ? void 0 : String.fromCodePoint(...codePoints));
|
|
38
|
+
advances[glyphId] = view.getUint16(at);
|
|
39
|
+
at += ADVANCE_SIZE;
|
|
40
|
+
}
|
|
41
|
+
read.set(name, {
|
|
42
|
+
unitsPerEm,
|
|
43
|
+
texts,
|
|
44
|
+
advances
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
faces = read;
|
|
48
|
+
return read;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The glyph order of a core face, checked glyph by glyph against the program that claims to be it.
|
|
52
|
+
* @param postScriptName - the face's PostScript name without any subset tag, as the program's own 'name' table states it or, for a program with none, as the font dictionary's /BaseFont does
|
|
53
|
+
* @param unitsPerEm - the program's own design grid; a program on another grid is not the face, whatever its name
|
|
54
|
+
* @returns a lookup from a glyph id and the program's own advance width for that glyph to the character the face draws there, answering undefined wherever the width disagrees with the face's or the face draws no character; or undefined when the name is not a core face or the grid is not the face's
|
|
55
|
+
*/
|
|
56
|
+
function coreFaceGlyphOrder(postScriptName, unitsPerEm) {
|
|
57
|
+
const face = readFaces().get(postScriptName);
|
|
58
|
+
if (face?.unitsPerEm !== unitsPerEm) return;
|
|
59
|
+
return (glyphId, advanceWidth) => face.advances[glyphId] === advanceWidth ? face.texts[glyphId] : void 0;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
exports.coreFaceGlyphOrder = coreFaceGlyphOrder;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/core-font-glyph-orders.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The glyph order of a core face, checked glyph by glyph against the program that claims to be it.
|
|
4
|
+
* @param postScriptName - the face's PostScript name without any subset tag, as the program's own 'name' table states it or, for a program with none, as the font dictionary's /BaseFont does
|
|
5
|
+
* @param unitsPerEm - the program's own design grid; a program on another grid is not the face, whatever its name
|
|
6
|
+
* @returns a lookup from a glyph id and the program's own advance width for that glyph to the character the face draws there, answering undefined wherever the width disagrees with the face's or the face draws no character; or undefined when the name is not a core face or the grid is not the face's
|
|
7
|
+
*/
|
|
8
|
+
declare function coreFaceGlyphOrder(postScriptName: string, unitsPerEm: number): ((glyphId: number, advanceWidth: number) => string | undefined) | undefined;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { coreFaceGlyphOrder };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/core-font-glyph-orders.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The glyph order of a core face, checked glyph by glyph against the program that claims to be it.
|
|
4
|
+
* @param postScriptName - the face's PostScript name without any subset tag, as the program's own 'name' table states it or, for a program with none, as the font dictionary's /BaseFont does
|
|
5
|
+
* @param unitsPerEm - the program's own design grid; a program on another grid is not the face, whatever its name
|
|
6
|
+
* @returns a lookup from a glyph id and the program's own advance width for that glyph to the character the face draws there, answering undefined wherever the width disagrees with the face's or the face draws no character; or undefined when the name is not a core face or the grid is not the face's
|
|
7
|
+
*/
|
|
8
|
+
declare function coreFaceGlyphOrder(postScriptName: string, unitsPerEm: number): ((glyphId: number, advanceWidth: number) => string | undefined) | undefined;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { coreFaceGlyphOrder };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CORE_FONT_GLYPH_ORDERS_DEFLATED_BASE64 } from "./glyph-data/core-font-glyph-orders.js";
|
|
2
|
+
import { inflateSync } from "fflate";
|
|
3
|
+
import { base64ToBytes } from "byte-codec";
|
|
4
|
+
//#region src/core-font-glyph-orders.ts
|
|
5
|
+
const FACE_COUNT_SIZE = 2;
|
|
6
|
+
const NAME_LENGTH_SIZE = 1;
|
|
7
|
+
const FACE_HEADER_SIZE = 4;
|
|
8
|
+
const CODE_POINT_COUNT_SIZE = 1;
|
|
9
|
+
const CODE_POINT_SIZE = 3;
|
|
10
|
+
const ADVANCE_SIZE = 2;
|
|
11
|
+
let faces;
|
|
12
|
+
function readFaces() {
|
|
13
|
+
if (faces !== void 0) return faces;
|
|
14
|
+
const bytes = inflateSync(base64ToBytes(CORE_FONT_GLYPH_ORDERS_DEFLATED_BASE64));
|
|
15
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
16
|
+
const read = /* @__PURE__ */ new Map();
|
|
17
|
+
let at = FACE_COUNT_SIZE;
|
|
18
|
+
for (let face = 0; face < view.getUint16(0); face++) {
|
|
19
|
+
const nameLength = view.getUint8(at);
|
|
20
|
+
at += NAME_LENGTH_SIZE;
|
|
21
|
+
const name = String.fromCharCode(...bytes.subarray(at, at + nameLength));
|
|
22
|
+
at += nameLength;
|
|
23
|
+
const unitsPerEm = view.getUint16(at);
|
|
24
|
+
const glyphCount = view.getUint16(at + 2);
|
|
25
|
+
at += FACE_HEADER_SIZE;
|
|
26
|
+
const texts = [];
|
|
27
|
+
const advances = new Uint16Array(glyphCount);
|
|
28
|
+
for (let glyphId = 0; glyphId < glyphCount; glyphId++) {
|
|
29
|
+
const codePointCount = view.getUint8(at);
|
|
30
|
+
at += CODE_POINT_COUNT_SIZE;
|
|
31
|
+
const codePoints = [];
|
|
32
|
+
for (let i = 0; i < codePointCount; i++) {
|
|
33
|
+
codePoints.push(view.getUint8(at) << 16 | view.getUint16(at + 1));
|
|
34
|
+
at += CODE_POINT_SIZE;
|
|
35
|
+
}
|
|
36
|
+
texts.push(codePoints.length === 0 ? void 0 : String.fromCodePoint(...codePoints));
|
|
37
|
+
advances[glyphId] = view.getUint16(at);
|
|
38
|
+
at += ADVANCE_SIZE;
|
|
39
|
+
}
|
|
40
|
+
read.set(name, {
|
|
41
|
+
unitsPerEm,
|
|
42
|
+
texts,
|
|
43
|
+
advances
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
faces = read;
|
|
47
|
+
return read;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The glyph order of a core face, checked glyph by glyph against the program that claims to be it.
|
|
51
|
+
* @param postScriptName - the face's PostScript name without any subset tag, as the program's own 'name' table states it or, for a program with none, as the font dictionary's /BaseFont does
|
|
52
|
+
* @param unitsPerEm - the program's own design grid; a program on another grid is not the face, whatever its name
|
|
53
|
+
* @returns a lookup from a glyph id and the program's own advance width for that glyph to the character the face draws there, answering undefined wherever the width disagrees with the face's or the face draws no character; or undefined when the name is not a core face or the grid is not the face's
|
|
54
|
+
*/
|
|
55
|
+
function coreFaceGlyphOrder(postScriptName, unitsPerEm) {
|
|
56
|
+
const face = readFaces().get(postScriptName);
|
|
57
|
+
if (face?.unitsPerEm !== unitsPerEm) return;
|
|
58
|
+
return (glyphId, advanceWidth) => face.advances[glyphId] === advanceWidth ? face.texts[glyphId] : void 0;
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { coreFaceGlyphOrder };
|
package/dist/encoding.cjs
CHANGED
|
@@ -1,6 +1,274 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const require_encoding_standard_tables = require("./encoding-standard-tables.cjs");
|
|
3
|
+
//#region src/encoding.ts
|
|
4
|
+
const WINANSI_GLYPH_NAMES = [
|
|
5
|
+
"",
|
|
6
|
+
"",
|
|
7
|
+
"",
|
|
8
|
+
"",
|
|
9
|
+
"",
|
|
10
|
+
"",
|
|
11
|
+
"",
|
|
12
|
+
"",
|
|
13
|
+
"",
|
|
14
|
+
"",
|
|
15
|
+
"",
|
|
16
|
+
"",
|
|
17
|
+
"",
|
|
18
|
+
"",
|
|
19
|
+
"",
|
|
20
|
+
"",
|
|
21
|
+
"",
|
|
22
|
+
"",
|
|
23
|
+
"",
|
|
24
|
+
"",
|
|
25
|
+
"",
|
|
26
|
+
"",
|
|
27
|
+
"",
|
|
28
|
+
"",
|
|
29
|
+
"",
|
|
30
|
+
"",
|
|
31
|
+
"",
|
|
32
|
+
"",
|
|
33
|
+
"",
|
|
34
|
+
"",
|
|
35
|
+
"",
|
|
36
|
+
"",
|
|
37
|
+
"space",
|
|
38
|
+
"exclam",
|
|
39
|
+
"quotedbl",
|
|
40
|
+
"numbersign",
|
|
41
|
+
"dollar",
|
|
42
|
+
"percent",
|
|
43
|
+
"ampersand",
|
|
44
|
+
"quotesingle",
|
|
45
|
+
"parenleft",
|
|
46
|
+
"parenright",
|
|
47
|
+
"asterisk",
|
|
48
|
+
"plus",
|
|
49
|
+
"comma",
|
|
50
|
+
"hyphen",
|
|
51
|
+
"period",
|
|
52
|
+
"slash",
|
|
53
|
+
"zero",
|
|
54
|
+
"one",
|
|
55
|
+
"two",
|
|
56
|
+
"three",
|
|
57
|
+
"four",
|
|
58
|
+
"five",
|
|
59
|
+
"six",
|
|
60
|
+
"seven",
|
|
61
|
+
"eight",
|
|
62
|
+
"nine",
|
|
63
|
+
"colon",
|
|
64
|
+
"semicolon",
|
|
65
|
+
"less",
|
|
66
|
+
"equal",
|
|
67
|
+
"greater",
|
|
68
|
+
"question",
|
|
69
|
+
"at",
|
|
70
|
+
"A",
|
|
71
|
+
"B",
|
|
72
|
+
"C",
|
|
73
|
+
"D",
|
|
74
|
+
"E",
|
|
75
|
+
"F",
|
|
76
|
+
"G",
|
|
77
|
+
"H",
|
|
78
|
+
"I",
|
|
79
|
+
"J",
|
|
80
|
+
"K",
|
|
81
|
+
"L",
|
|
82
|
+
"M",
|
|
83
|
+
"N",
|
|
84
|
+
"O",
|
|
85
|
+
"P",
|
|
86
|
+
"Q",
|
|
87
|
+
"R",
|
|
88
|
+
"S",
|
|
89
|
+
"T",
|
|
90
|
+
"U",
|
|
91
|
+
"V",
|
|
92
|
+
"W",
|
|
93
|
+
"X",
|
|
94
|
+
"Y",
|
|
95
|
+
"Z",
|
|
96
|
+
"bracketleft",
|
|
97
|
+
"backslash",
|
|
98
|
+
"bracketright",
|
|
99
|
+
"asciicircum",
|
|
100
|
+
"underscore",
|
|
101
|
+
"grave",
|
|
102
|
+
"a",
|
|
103
|
+
"b",
|
|
104
|
+
"c",
|
|
105
|
+
"d",
|
|
106
|
+
"e",
|
|
107
|
+
"f",
|
|
108
|
+
"g",
|
|
109
|
+
"h",
|
|
110
|
+
"i",
|
|
111
|
+
"j",
|
|
112
|
+
"k",
|
|
113
|
+
"l",
|
|
114
|
+
"m",
|
|
115
|
+
"n",
|
|
116
|
+
"o",
|
|
117
|
+
"p",
|
|
118
|
+
"q",
|
|
119
|
+
"r",
|
|
120
|
+
"s",
|
|
121
|
+
"t",
|
|
122
|
+
"u",
|
|
123
|
+
"v",
|
|
124
|
+
"w",
|
|
125
|
+
"x",
|
|
126
|
+
"y",
|
|
127
|
+
"z",
|
|
128
|
+
"braceleft",
|
|
129
|
+
"bar",
|
|
130
|
+
"braceright",
|
|
131
|
+
"asciitilde",
|
|
132
|
+
"bullet",
|
|
133
|
+
"Euro",
|
|
134
|
+
"bullet",
|
|
135
|
+
"quotesinglbase",
|
|
136
|
+
"florin",
|
|
137
|
+
"quotedblbase",
|
|
138
|
+
"ellipsis",
|
|
139
|
+
"dagger",
|
|
140
|
+
"daggerdbl",
|
|
141
|
+
"circumflex",
|
|
142
|
+
"perthousand",
|
|
143
|
+
"Scaron",
|
|
144
|
+
"guilsinglleft",
|
|
145
|
+
"OE",
|
|
146
|
+
"bullet",
|
|
147
|
+
"Zcaron",
|
|
148
|
+
"bullet",
|
|
149
|
+
"bullet",
|
|
150
|
+
"quoteleft",
|
|
151
|
+
"quoteright",
|
|
152
|
+
"quotedblleft",
|
|
153
|
+
"quotedblright",
|
|
154
|
+
"bullet",
|
|
155
|
+
"endash",
|
|
156
|
+
"emdash",
|
|
157
|
+
"tilde",
|
|
158
|
+
"trademark",
|
|
159
|
+
"scaron",
|
|
160
|
+
"guilsinglright",
|
|
161
|
+
"oe",
|
|
162
|
+
"bullet",
|
|
163
|
+
"zcaron",
|
|
164
|
+
"Ydieresis",
|
|
165
|
+
"space",
|
|
166
|
+
"exclamdown",
|
|
167
|
+
"cent",
|
|
168
|
+
"sterling",
|
|
169
|
+
"currency",
|
|
170
|
+
"yen",
|
|
171
|
+
"brokenbar",
|
|
172
|
+
"section",
|
|
173
|
+
"dieresis",
|
|
174
|
+
"copyright",
|
|
175
|
+
"ordfeminine",
|
|
176
|
+
"guillemotleft",
|
|
177
|
+
"logicalnot",
|
|
178
|
+
"hyphen",
|
|
179
|
+
"registered",
|
|
180
|
+
"macron",
|
|
181
|
+
"degree",
|
|
182
|
+
"plusminus",
|
|
183
|
+
"twosuperior",
|
|
184
|
+
"threesuperior",
|
|
185
|
+
"acute",
|
|
186
|
+
"mu",
|
|
187
|
+
"paragraph",
|
|
188
|
+
"periodcentered",
|
|
189
|
+
"cedilla",
|
|
190
|
+
"onesuperior",
|
|
191
|
+
"ordmasculine",
|
|
192
|
+
"guillemotright",
|
|
193
|
+
"onequarter",
|
|
194
|
+
"onehalf",
|
|
195
|
+
"threequarters",
|
|
196
|
+
"questiondown",
|
|
197
|
+
"Agrave",
|
|
198
|
+
"Aacute",
|
|
199
|
+
"Acircumflex",
|
|
200
|
+
"Atilde",
|
|
201
|
+
"Adieresis",
|
|
202
|
+
"Aring",
|
|
203
|
+
"AE",
|
|
204
|
+
"Ccedilla",
|
|
205
|
+
"Egrave",
|
|
206
|
+
"Eacute",
|
|
207
|
+
"Ecircumflex",
|
|
208
|
+
"Edieresis",
|
|
209
|
+
"Igrave",
|
|
210
|
+
"Iacute",
|
|
211
|
+
"Icircumflex",
|
|
212
|
+
"Idieresis",
|
|
213
|
+
"Eth",
|
|
214
|
+
"Ntilde",
|
|
215
|
+
"Ograve",
|
|
216
|
+
"Oacute",
|
|
217
|
+
"Ocircumflex",
|
|
218
|
+
"Otilde",
|
|
219
|
+
"Odieresis",
|
|
220
|
+
"multiply",
|
|
221
|
+
"Oslash",
|
|
222
|
+
"Ugrave",
|
|
223
|
+
"Uacute",
|
|
224
|
+
"Ucircumflex",
|
|
225
|
+
"Udieresis",
|
|
226
|
+
"Yacute",
|
|
227
|
+
"Thorn",
|
|
228
|
+
"germandbls",
|
|
229
|
+
"agrave",
|
|
230
|
+
"aacute",
|
|
231
|
+
"acircumflex",
|
|
232
|
+
"atilde",
|
|
233
|
+
"adieresis",
|
|
234
|
+
"aring",
|
|
235
|
+
"ae",
|
|
236
|
+
"ccedilla",
|
|
237
|
+
"egrave",
|
|
238
|
+
"eacute",
|
|
239
|
+
"ecircumflex",
|
|
240
|
+
"edieresis",
|
|
241
|
+
"igrave",
|
|
242
|
+
"iacute",
|
|
243
|
+
"icircumflex",
|
|
244
|
+
"idieresis",
|
|
245
|
+
"eth",
|
|
246
|
+
"ntilde",
|
|
247
|
+
"ograve",
|
|
248
|
+
"oacute",
|
|
249
|
+
"ocircumflex",
|
|
250
|
+
"otilde",
|
|
251
|
+
"odieresis",
|
|
252
|
+
"divide",
|
|
253
|
+
"oslash",
|
|
254
|
+
"ugrave",
|
|
255
|
+
"uacute",
|
|
256
|
+
"ucircumflex",
|
|
257
|
+
"udieresis",
|
|
258
|
+
"yacute",
|
|
259
|
+
"thorn",
|
|
260
|
+
"ydieresis"
|
|
261
|
+
];
|
|
262
|
+
function winAnsiGlyphName(code) {
|
|
263
|
+
const name = WINANSI_GLYPH_NAMES[code];
|
|
264
|
+
return name === void 0 || name === "" ? void 0 : name;
|
|
265
|
+
}
|
|
266
|
+
function namedEncodingGlyphName(encodingName) {
|
|
267
|
+
if (encodingName === "WinAnsiEncoding") return winAnsiGlyphName;
|
|
268
|
+
if (encodingName === "MacRomanEncoding") return require_encoding_standard_tables.macRomanGlyphName;
|
|
269
|
+
if (encodingName === "StandardEncoding") return require_encoding_standard_tables.standardGlyphName;
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
exports.WINANSI_GLYPH_NAMES = WINANSI_GLYPH_NAMES;
|
|
273
|
+
exports.namedEncodingGlyphName = namedEncodingGlyphName;
|
|
274
|
+
exports.winAnsiGlyphName = winAnsiGlyphName;
|
package/dist/encoding.d.cts
CHANGED
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
declare const WINANSI_GLYPH_NAMES: readonly string[];
|
|
3
3
|
declare function winAnsiGlyphName(code: number): string | undefined;
|
|
4
4
|
declare function namedEncodingGlyphName(encodingName: string): ((code: number) => string | undefined) | undefined;
|
|
5
|
-
declare function glyphNameToUnicode(name: string): number | undefined;
|
|
6
5
|
//#endregion
|
|
7
|
-
export { WINANSI_GLYPH_NAMES,
|
|
6
|
+
export { WINANSI_GLYPH_NAMES, namedEncodingGlyphName, winAnsiGlyphName };
|
package/dist/encoding.d.ts
CHANGED
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
declare const WINANSI_GLYPH_NAMES: readonly string[];
|
|
3
3
|
declare function winAnsiGlyphName(code: number): string | undefined;
|
|
4
4
|
declare function namedEncodingGlyphName(encodingName: string): ((code: number) => string | undefined) | undefined;
|
|
5
|
-
declare function glyphNameToUnicode(name: string): number | undefined;
|
|
6
5
|
//#endregion
|
|
7
|
-
export { WINANSI_GLYPH_NAMES,
|
|
6
|
+
export { WINANSI_GLYPH_NAMES, namedEncodingGlyphName, winAnsiGlyphName };
|