pdf-codec 3.5.4 → 3.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.
Files changed (42) hide show
  1. package/README.md +12 -2
  2. package/dist/{afm-widths-W02fJh-k.cjs → afm-widths-BTu0IDp2.cjs} +570 -1
  3. package/dist/{afm-widths-B6KdmpRF.js → afm-widths-De_QMWgC.js} +541 -2
  4. package/dist/afm-widths.cjs +1 -1
  5. package/dist/afm-widths.js +1 -1
  6. package/dist/builtin-encoding.cjs +221 -0
  7. package/dist/builtin-encoding.d.cts +8 -0
  8. package/dist/builtin-encoding.d.ts +8 -0
  9. package/dist/builtin-encoding.js +220 -0
  10. package/dist/cff.cjs +14 -0
  11. package/dist/cff.d.cts +4 -1
  12. package/dist/cff.d.ts +4 -1
  13. package/dist/cff.js +12 -1
  14. package/dist/cmap-table.cjs +76 -13
  15. package/dist/cmap-table.d.cts +9 -1
  16. package/dist/cmap-table.d.ts +9 -1
  17. package/dist/cmap-table.js +77 -15
  18. package/dist/content-write.cjs +1 -1
  19. package/dist/content-write.js +1 -1
  20. package/dist/encoding.cjs +6 -1
  21. package/dist/encoding.d.cts +6 -1
  22. package/dist/encoding.d.ts +6 -1
  23. package/dist/encoding.js +2 -2
  24. package/dist/font-read.cjs +56 -11
  25. package/dist/font-read.js +57 -12
  26. package/dist/font-tables.cjs +31 -0
  27. package/dist/font-tables.d.cts +3 -1
  28. package/dist/font-tables.d.ts +3 -1
  29. package/dist/font-tables.js +31 -2
  30. package/dist/index.cjs +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/interpret.cjs +72 -41
  33. package/dist/interpret.js +72 -41
  34. package/dist/math-font.cjs +1 -1
  35. package/dist/math-font.js +1 -1
  36. package/dist/measure.cjs +1 -1
  37. package/dist/measure.js +1 -1
  38. package/dist/winansi.cjs +1 -1
  39. package/dist/winansi.js +1 -1
  40. package/dist/write.cjs +1 -1
  41. package/dist/write.js +1 -1
  42. package/package.json +1 -1
@@ -3,6 +3,7 @@ const require_sfnt = require("./sfnt.cjs");
3
3
  //#region src/cmap-table.ts
4
4
  const CMAP_HEADER_SIZE = 4;
5
5
  const SUBTABLE_RECORD_SIZE = 8;
6
+ const MAX_UNICODE_CODE_POINT = 1114111;
6
7
  const FORMAT_4_HEADER_SIZE = 14;
7
8
  function parseFormat4(bytes, subtableOffset) {
8
9
  if (!require_sfnt.hasBytes(bytes, subtableOffset, FORMAT_4_HEADER_SIZE)) return;
@@ -26,7 +27,7 @@ function parseFormat4(bytes, subtableOffset) {
26
27
  idRangeOffset: require_sfnt.u16(bytes, idRangeOffsetPos)
27
28
  });
28
29
  }
29
- return (codePoint) => {
30
+ const lookup = (codePoint) => {
30
31
  if (codePoint > 65535) return;
31
32
  for (const segment of segments) {
32
33
  if (codePoint < segment.startCode || codePoint > segment.endCode) continue;
@@ -37,6 +38,18 @@ function parseFormat4(bytes, subtableOffset) {
37
38
  return glyphId === 0 ? void 0 : glyphId + segment.idDelta & 65535;
38
39
  }
39
40
  };
41
+ return {
42
+ lookup,
43
+ forEachMapping(visit) {
44
+ for (const segment of segments) {
45
+ const end = Math.min(segment.endCode, 65534);
46
+ for (let code = segment.startCode; code <= end; code++) {
47
+ const glyphId = lookup(code);
48
+ if (glyphId !== void 0 && glyphId !== 0) visit(code, glyphId);
49
+ }
50
+ }
51
+ }
52
+ };
40
53
  }
41
54
  const FORMAT_12_HEADER_SIZE = 16;
42
55
  const FORMAT_12_GROUP_SIZE = 12;
@@ -54,8 +67,35 @@ function parseFormat12(bytes, subtableOffset) {
54
67
  startGlyphId: require_sfnt.u32(bytes, recordOffset + 8)
55
68
  });
56
69
  }
57
- return (codePoint) => {
58
- for (const group of groups) if (codePoint >= group.startCharCode && codePoint <= group.endCharCode) return group.startGlyphId + (codePoint - group.startCharCode);
70
+ return {
71
+ lookup(codePoint) {
72
+ for (const group of groups) if (codePoint >= group.startCharCode && codePoint <= group.endCharCode) return group.startGlyphId + (codePoint - group.startCharCode);
73
+ },
74
+ forEachMapping(visit) {
75
+ for (const group of groups) {
76
+ const end = Math.min(group.endCharCode, MAX_UNICODE_CODE_POINT);
77
+ for (let code = group.startCharCode; code <= end; code++) visit(code, group.startGlyphId + (code - group.startCharCode));
78
+ }
79
+ }
80
+ };
81
+ }
82
+ const FORMAT_0_SIZE = 262;
83
+ function parseFormat0(bytes, subtableOffset) {
84
+ if (!require_sfnt.hasBytes(bytes, subtableOffset, FORMAT_0_SIZE)) return;
85
+ const glyphIdArrayOffset = subtableOffset + 6;
86
+ const lookup = (codePoint) => {
87
+ if (codePoint < 0 || codePoint > 255) return;
88
+ const glyphId = require_sfnt.u8(bytes, glyphIdArrayOffset + codePoint);
89
+ return glyphId === 0 ? void 0 : glyphId;
90
+ };
91
+ return {
92
+ lookup,
93
+ forEachMapping(visit) {
94
+ for (let code = 0; code <= 255; code++) {
95
+ const glyphId = lookup(code);
96
+ if (glyphId !== void 0) visit(code, glyphId);
97
+ }
98
+ }
59
99
  };
60
100
  }
61
101
  const FORMAT_6_HEADER_SIZE = 10;
@@ -65,12 +105,22 @@ function parseFormat6(bytes, subtableOffset) {
65
105
  const entryCount = require_sfnt.u16(bytes, subtableOffset + 8);
66
106
  const glyphIdArrayOffset = subtableOffset + FORMAT_6_HEADER_SIZE;
67
107
  if (!require_sfnt.hasBytes(bytes, glyphIdArrayOffset, entryCount * 2)) return;
68
- return (codePoint) => {
108
+ const lookup = (codePoint) => {
69
109
  const index = codePoint - firstCode;
70
110
  if (index < 0 || index >= entryCount) return;
71
111
  const glyphId = require_sfnt.u16(bytes, glyphIdArrayOffset + index * 2);
72
112
  return glyphId === 0 ? void 0 : glyphId;
73
113
  };
114
+ return {
115
+ lookup,
116
+ forEachMapping(visit) {
117
+ for (let index = 0; index < entryCount; index++) {
118
+ const code = firstCode + index;
119
+ const glyphId = lookup(code);
120
+ if (glyphId !== void 0) visit(code, glyphId);
121
+ }
122
+ }
123
+ };
74
124
  }
75
125
  function preferenceRank(subtable) {
76
126
  if (subtable.format === 12) {
@@ -81,28 +131,41 @@ function preferenceRank(subtable) {
81
131
  if (subtable.format === 4) return subtable.platformId === 3 && subtable.encodingId === 1 ? 3 : 4;
82
132
  return 5;
83
133
  }
84
- function buildCmapLookup(font) {
134
+ function parseSubtable(bytes, record) {
135
+ if (record.format === 12) return parseFormat12(bytes, record.offset);
136
+ if (record.format === 4) return parseFormat4(bytes, record.offset);
137
+ if (record.format === 6) return parseFormat6(bytes, record.offset);
138
+ return record.format === 0 ? parseFormat0(bytes, record.offset) : void 0;
139
+ }
140
+ function readCmapSubtables(font) {
85
141
  const cmapBytes = require_sfnt.sfntTableBytes(font, "cmap");
86
- if (cmapBytes === void 0 || !require_sfnt.hasBytes(cmapBytes, 0, CMAP_HEADER_SIZE)) return;
142
+ if (cmapBytes === void 0 || !require_sfnt.hasBytes(cmapBytes, 0, CMAP_HEADER_SIZE)) return [];
87
143
  const numTables = require_sfnt.u16(cmapBytes, 2);
88
- if (!require_sfnt.hasBytes(cmapBytes, CMAP_HEADER_SIZE, numTables * SUBTABLE_RECORD_SIZE)) return;
144
+ if (!require_sfnt.hasBytes(cmapBytes, CMAP_HEADER_SIZE, numTables * SUBTABLE_RECORD_SIZE)) return [];
89
145
  const subtables = [];
90
146
  for (let i = 0; i < numTables; i++) {
91
147
  const recordOffset = CMAP_HEADER_SIZE + i * SUBTABLE_RECORD_SIZE;
92
148
  const offset = require_sfnt.u32(cmapBytes, recordOffset + 4);
93
149
  if (!require_sfnt.hasBytes(cmapBytes, offset, 2)) continue;
94
- subtables.push({
150
+ const record = {
95
151
  platformId: require_sfnt.u16(cmapBytes, recordOffset),
96
152
  encodingId: require_sfnt.u16(cmapBytes, recordOffset + 2),
97
153
  offset,
98
154
  format: require_sfnt.u16(cmapBytes, offset)
155
+ };
156
+ const parsed = parseSubtable(cmapBytes, record);
157
+ if (parsed !== void 0) subtables.push({
158
+ platformId: record.platformId,
159
+ encodingId: record.encodingId,
160
+ format: record.format,
161
+ ...parsed
99
162
  });
100
163
  }
101
- const candidates = subtables.filter((s) => s.format === 4 || s.format === 6 || s.format === 12).sort((a, b) => preferenceRank(a) - preferenceRank(b));
102
- for (const candidate of candidates) {
103
- const lookup = candidate.format === 12 ? parseFormat12(cmapBytes, candidate.offset) : candidate.format === 4 ? parseFormat4(cmapBytes, candidate.offset) : parseFormat6(cmapBytes, candidate.offset);
104
- if (lookup !== void 0) return lookup;
105
- }
164
+ return subtables;
165
+ }
166
+ function buildCmapLookup(font) {
167
+ return readCmapSubtables(font).filter((s) => s.format === 4 || s.format === 6 || s.format === 12).sort((a, b) => preferenceRank(a) - preferenceRank(b))[0]?.lookup;
106
168
  }
107
169
  //#endregion
108
170
  exports.buildCmapLookup = buildCmapLookup;
171
+ exports.readCmapSubtables = readCmapSubtables;
@@ -1,6 +1,14 @@
1
1
  import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
2
  //#region src/cmap-table.d.ts
3
3
  type CmapLookup = (codePoint: number) => number | undefined;
4
+ interface CmapSubtable {
5
+ readonly platformId: number;
6
+ readonly encodingId: number;
7
+ readonly format: number;
8
+ readonly lookup: CmapLookup;
9
+ forEachMapping(visit: (code: number, glyphId: number) => void): void;
10
+ }
11
+ declare function readCmapSubtables(font: SfntFont): readonly CmapSubtable[];
4
12
  declare function buildCmapLookup(font: SfntFont): CmapLookup | undefined;
5
13
  //#endregion
6
- export { CmapLookup, buildCmapLookup };
14
+ export { CmapLookup, CmapSubtable, buildCmapLookup, readCmapSubtables };
@@ -1,6 +1,14 @@
1
1
  import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
2
  //#region src/cmap-table.d.ts
3
3
  type CmapLookup = (codePoint: number) => number | undefined;
4
+ interface CmapSubtable {
5
+ readonly platformId: number;
6
+ readonly encodingId: number;
7
+ readonly format: number;
8
+ readonly lookup: CmapLookup;
9
+ forEachMapping(visit: (code: number, glyphId: number) => void): void;
10
+ }
11
+ declare function readCmapSubtables(font: SfntFont): readonly CmapSubtable[];
4
12
  declare function buildCmapLookup(font: SfntFont): CmapLookup | undefined;
5
13
  //#endregion
6
- export { CmapLookup, buildCmapLookup };
14
+ export { CmapLookup, CmapSubtable, buildCmapLookup, readCmapSubtables };
@@ -1,7 +1,8 @@
1
- import { hasBytes, sfntTableBytes, u16, u32 } from "./sfnt.js";
1
+ import { hasBytes, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
2
2
  //#region src/cmap-table.ts
3
3
  const CMAP_HEADER_SIZE = 4;
4
4
  const SUBTABLE_RECORD_SIZE = 8;
5
+ const MAX_UNICODE_CODE_POINT = 1114111;
5
6
  const FORMAT_4_HEADER_SIZE = 14;
6
7
  function parseFormat4(bytes, subtableOffset) {
7
8
  if (!hasBytes(bytes, subtableOffset, FORMAT_4_HEADER_SIZE)) return;
@@ -25,7 +26,7 @@ function parseFormat4(bytes, subtableOffset) {
25
26
  idRangeOffset: u16(bytes, idRangeOffsetPos)
26
27
  });
27
28
  }
28
- return (codePoint) => {
29
+ const lookup = (codePoint) => {
29
30
  if (codePoint > 65535) return;
30
31
  for (const segment of segments) {
31
32
  if (codePoint < segment.startCode || codePoint > segment.endCode) continue;
@@ -36,6 +37,18 @@ function parseFormat4(bytes, subtableOffset) {
36
37
  return glyphId === 0 ? void 0 : glyphId + segment.idDelta & 65535;
37
38
  }
38
39
  };
40
+ return {
41
+ lookup,
42
+ forEachMapping(visit) {
43
+ for (const segment of segments) {
44
+ const end = Math.min(segment.endCode, 65534);
45
+ for (let code = segment.startCode; code <= end; code++) {
46
+ const glyphId = lookup(code);
47
+ if (glyphId !== void 0 && glyphId !== 0) visit(code, glyphId);
48
+ }
49
+ }
50
+ }
51
+ };
39
52
  }
40
53
  const FORMAT_12_HEADER_SIZE = 16;
41
54
  const FORMAT_12_GROUP_SIZE = 12;
@@ -53,8 +66,35 @@ function parseFormat12(bytes, subtableOffset) {
53
66
  startGlyphId: u32(bytes, recordOffset + 8)
54
67
  });
55
68
  }
56
- return (codePoint) => {
57
- for (const group of groups) if (codePoint >= group.startCharCode && codePoint <= group.endCharCode) return group.startGlyphId + (codePoint - group.startCharCode);
69
+ return {
70
+ lookup(codePoint) {
71
+ for (const group of groups) if (codePoint >= group.startCharCode && codePoint <= group.endCharCode) return group.startGlyphId + (codePoint - group.startCharCode);
72
+ },
73
+ forEachMapping(visit) {
74
+ for (const group of groups) {
75
+ const end = Math.min(group.endCharCode, MAX_UNICODE_CODE_POINT);
76
+ for (let code = group.startCharCode; code <= end; code++) visit(code, group.startGlyphId + (code - group.startCharCode));
77
+ }
78
+ }
79
+ };
80
+ }
81
+ const FORMAT_0_SIZE = 262;
82
+ function parseFormat0(bytes, subtableOffset) {
83
+ if (!hasBytes(bytes, subtableOffset, FORMAT_0_SIZE)) return;
84
+ const glyphIdArrayOffset = subtableOffset + 6;
85
+ const lookup = (codePoint) => {
86
+ if (codePoint < 0 || codePoint > 255) return;
87
+ const glyphId = u8(bytes, glyphIdArrayOffset + codePoint);
88
+ return glyphId === 0 ? void 0 : glyphId;
89
+ };
90
+ return {
91
+ lookup,
92
+ forEachMapping(visit) {
93
+ for (let code = 0; code <= 255; code++) {
94
+ const glyphId = lookup(code);
95
+ if (glyphId !== void 0) visit(code, glyphId);
96
+ }
97
+ }
58
98
  };
59
99
  }
60
100
  const FORMAT_6_HEADER_SIZE = 10;
@@ -64,12 +104,22 @@ function parseFormat6(bytes, subtableOffset) {
64
104
  const entryCount = u16(bytes, subtableOffset + 8);
65
105
  const glyphIdArrayOffset = subtableOffset + FORMAT_6_HEADER_SIZE;
66
106
  if (!hasBytes(bytes, glyphIdArrayOffset, entryCount * 2)) return;
67
- return (codePoint) => {
107
+ const lookup = (codePoint) => {
68
108
  const index = codePoint - firstCode;
69
109
  if (index < 0 || index >= entryCount) return;
70
110
  const glyphId = u16(bytes, glyphIdArrayOffset + index * 2);
71
111
  return glyphId === 0 ? void 0 : glyphId;
72
112
  };
113
+ return {
114
+ lookup,
115
+ forEachMapping(visit) {
116
+ for (let index = 0; index < entryCount; index++) {
117
+ const code = firstCode + index;
118
+ const glyphId = lookup(code);
119
+ if (glyphId !== void 0) visit(code, glyphId);
120
+ }
121
+ }
122
+ };
73
123
  }
74
124
  function preferenceRank(subtable) {
75
125
  if (subtable.format === 12) {
@@ -80,28 +130,40 @@ function preferenceRank(subtable) {
80
130
  if (subtable.format === 4) return subtable.platformId === 3 && subtable.encodingId === 1 ? 3 : 4;
81
131
  return 5;
82
132
  }
83
- function buildCmapLookup(font) {
133
+ function parseSubtable(bytes, record) {
134
+ if (record.format === 12) return parseFormat12(bytes, record.offset);
135
+ if (record.format === 4) return parseFormat4(bytes, record.offset);
136
+ if (record.format === 6) return parseFormat6(bytes, record.offset);
137
+ return record.format === 0 ? parseFormat0(bytes, record.offset) : void 0;
138
+ }
139
+ function readCmapSubtables(font) {
84
140
  const cmapBytes = sfntTableBytes(font, "cmap");
85
- if (cmapBytes === void 0 || !hasBytes(cmapBytes, 0, CMAP_HEADER_SIZE)) return;
141
+ if (cmapBytes === void 0 || !hasBytes(cmapBytes, 0, CMAP_HEADER_SIZE)) return [];
86
142
  const numTables = u16(cmapBytes, 2);
87
- if (!hasBytes(cmapBytes, CMAP_HEADER_SIZE, numTables * SUBTABLE_RECORD_SIZE)) return;
143
+ if (!hasBytes(cmapBytes, CMAP_HEADER_SIZE, numTables * SUBTABLE_RECORD_SIZE)) return [];
88
144
  const subtables = [];
89
145
  for (let i = 0; i < numTables; i++) {
90
146
  const recordOffset = CMAP_HEADER_SIZE + i * SUBTABLE_RECORD_SIZE;
91
147
  const offset = u32(cmapBytes, recordOffset + 4);
92
148
  if (!hasBytes(cmapBytes, offset, 2)) continue;
93
- subtables.push({
149
+ const record = {
94
150
  platformId: u16(cmapBytes, recordOffset),
95
151
  encodingId: u16(cmapBytes, recordOffset + 2),
96
152
  offset,
97
153
  format: u16(cmapBytes, offset)
154
+ };
155
+ const parsed = parseSubtable(cmapBytes, record);
156
+ if (parsed !== void 0) subtables.push({
157
+ platformId: record.platformId,
158
+ encodingId: record.encodingId,
159
+ format: record.format,
160
+ ...parsed
98
161
  });
99
162
  }
100
- const candidates = subtables.filter((s) => s.format === 4 || s.format === 6 || s.format === 12).sort((a, b) => preferenceRank(a) - preferenceRank(b));
101
- for (const candidate of candidates) {
102
- const lookup = candidate.format === 12 ? parseFormat12(cmapBytes, candidate.offset) : candidate.format === 4 ? parseFormat4(cmapBytes, candidate.offset) : parseFormat6(cmapBytes, candidate.offset);
103
- if (lookup !== void 0) return lookup;
104
- }
163
+ return subtables;
164
+ }
165
+ function buildCmapLookup(font) {
166
+ return readCmapSubtables(font).filter((s) => s.format === 4 || s.format === 6 || s.format === 12).sort((a, b) => preferenceRank(a) - preferenceRank(b))[0]?.lookup;
105
167
  }
106
168
  //#endregion
107
- export { buildCmapLookup };
169
+ export { buildCmapLookup, readCmapSubtables };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-W02fJh-k.cjs");
2
+ const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
3
3
  const require_objects = require("./objects.cjs");
4
4
  const require_bytes_writer = require("./bytes/writer.cjs");
5
5
  const require_serialize = require("./serialize.cjs");
@@ -1,4 +1,4 @@
1
- import { u as encodeForShow } from "./afm-widths-B6KdmpRF.js";
1
+ import { h as encodeForShow } from "./afm-widths-De_QMWgC.js";
2
2
  import { pdfArray, pdfHexString, pdfNum } from "./objects.js";
3
3
  import { ByteWriter } from "./bytes/writer.js";
4
4
  import { formatNumber, writeObject } from "./serialize.js";
package/dist/encoding.cjs CHANGED
@@ -1,9 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-W02fJh-k.cjs");
2
+ const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
3
+ exports.MACROMAN_GLYPH_NAMES = require_afm_widths.MACROMAN_GLYPH_NAMES;
4
+ exports.STANDARD_GLYPH_NAMES = require_afm_widths.STANDARD_GLYPH_NAMES;
3
5
  exports.SYMBOL_GLYPH_NAMES = require_afm_widths.SYMBOL_GLYPH_NAMES;
4
6
  exports.WINANSI_GLYPH_NAMES = require_afm_widths.WINANSI_GLYPH_NAMES;
5
7
  exports.ZAPFDINGBATS_GLYPH_NAMES = require_afm_widths.ZAPFDINGBATS_GLYPH_NAMES;
6
8
  exports.glyphNameToUnicode = require_afm_widths.glyphNameToUnicode;
9
+ exports.macRomanGlyphName = require_afm_widths.macRomanGlyphName;
10
+ exports.namedEncodingGlyphName = require_afm_widths.namedEncodingGlyphName;
11
+ exports.standardGlyphName = require_afm_widths.standardGlyphName;
7
12
  exports.symbolGlyphName = require_afm_widths.symbolGlyphName;
8
13
  exports.winAnsiGlyphName = require_afm_widths.winAnsiGlyphName;
9
14
  exports.zapfDingbatsGlyphName = require_afm_widths.zapfDingbatsGlyphName;
@@ -4,7 +4,12 @@ declare function winAnsiGlyphName(code: number): string | undefined;
4
4
  declare const SYMBOL_GLYPH_NAMES: readonly string[];
5
5
  declare function symbolGlyphName(code: number): string | undefined;
6
6
  declare const ZAPFDINGBATS_GLYPH_NAMES: readonly string[];
7
+ declare const STANDARD_GLYPH_NAMES: readonly string[];
8
+ declare function standardGlyphName(code: number): string | undefined;
9
+ declare const MACROMAN_GLYPH_NAMES: readonly string[];
10
+ declare function macRomanGlyphName(code: number): string | undefined;
11
+ declare function namedEncodingGlyphName(encodingName: string): ((code: number) => string | undefined) | undefined;
7
12
  declare function zapfDingbatsGlyphName(code: number): string | undefined;
8
13
  declare function glyphNameToUnicode(name: string): number | undefined;
9
14
  //#endregion
10
- export { SYMBOL_GLYPH_NAMES, WINANSI_GLYPH_NAMES, ZAPFDINGBATS_GLYPH_NAMES, glyphNameToUnicode, symbolGlyphName, winAnsiGlyphName, zapfDingbatsGlyphName };
15
+ export { MACROMAN_GLYPH_NAMES, STANDARD_GLYPH_NAMES, SYMBOL_GLYPH_NAMES, WINANSI_GLYPH_NAMES, ZAPFDINGBATS_GLYPH_NAMES, glyphNameToUnicode, macRomanGlyphName, namedEncodingGlyphName, standardGlyphName, symbolGlyphName, winAnsiGlyphName, zapfDingbatsGlyphName };
@@ -4,7 +4,12 @@ declare function winAnsiGlyphName(code: number): string | undefined;
4
4
  declare const SYMBOL_GLYPH_NAMES: readonly string[];
5
5
  declare function symbolGlyphName(code: number): string | undefined;
6
6
  declare const ZAPFDINGBATS_GLYPH_NAMES: readonly string[];
7
+ declare const STANDARD_GLYPH_NAMES: readonly string[];
8
+ declare function standardGlyphName(code: number): string | undefined;
9
+ declare const MACROMAN_GLYPH_NAMES: readonly string[];
10
+ declare function macRomanGlyphName(code: number): string | undefined;
11
+ declare function namedEncodingGlyphName(encodingName: string): ((code: number) => string | undefined) | undefined;
7
12
  declare function zapfDingbatsGlyphName(code: number): string | undefined;
8
13
  declare function glyphNameToUnicode(name: string): number | undefined;
9
14
  //#endregion
10
- export { SYMBOL_GLYPH_NAMES, WINANSI_GLYPH_NAMES, ZAPFDINGBATS_GLYPH_NAMES, glyphNameToUnicode, symbolGlyphName, winAnsiGlyphName, zapfDingbatsGlyphName };
15
+ export { MACROMAN_GLYPH_NAMES, STANDARD_GLYPH_NAMES, SYMBOL_GLYPH_NAMES, WINANSI_GLYPH_NAMES, ZAPFDINGBATS_GLYPH_NAMES, glyphNameToUnicode, macRomanGlyphName, namedEncodingGlyphName, standardGlyphName, symbolGlyphName, winAnsiGlyphName, zapfDingbatsGlyphName };
package/dist/encoding.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as ZAPFDINGBATS_GLYPH_NAMES, c as winAnsiGlyphName, i as WINANSI_GLYPH_NAMES, l as zapfDingbatsGlyphName, o as glyphNameToUnicode, r as SYMBOL_GLYPH_NAMES, s as symbolGlyphName } from "./afm-widths-B6KdmpRF.js";
2
- export { SYMBOL_GLYPH_NAMES, WINANSI_GLYPH_NAMES, ZAPFDINGBATS_GLYPH_NAMES, glyphNameToUnicode, symbolGlyphName, winAnsiGlyphName, zapfDingbatsGlyphName };
1
+ import { a as SYMBOL_GLYPH_NAMES, c as glyphNameToUnicode, d as standardGlyphName, f as symbolGlyphName, i as STANDARD_GLYPH_NAMES, l as macRomanGlyphName, m as zapfDingbatsGlyphName, o as WINANSI_GLYPH_NAMES, p as winAnsiGlyphName, r as MACROMAN_GLYPH_NAMES, s as ZAPFDINGBATS_GLYPH_NAMES, u as namedEncodingGlyphName } from "./afm-widths-De_QMWgC.js";
2
+ export { MACROMAN_GLYPH_NAMES, STANDARD_GLYPH_NAMES, SYMBOL_GLYPH_NAMES, WINANSI_GLYPH_NAMES, ZAPFDINGBATS_GLYPH_NAMES, glyphNameToUnicode, macRomanGlyphName, namedEncodingGlyphName, standardGlyphName, symbolGlyphName, winAnsiGlyphName, zapfDingbatsGlyphName };
@@ -1,7 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_afm_widths = require("./afm-widths-W02fJh-k.cjs");
2
+ const require_afm_widths = require("./afm-widths-BTu0IDp2.cjs");
3
3
  const require_objects = require("./objects.cjs");
4
4
  const require_filters = require("./filters.cjs");
5
+ const require_builtin_encoding = require("./builtin-encoding.cjs");
5
6
  const require_cmap = require("./cmap.cjs");
6
7
  const require_fonts = require("./fonts.cjs");
7
8
  const require_font_style = require("./font-style.cjs");
@@ -23,11 +24,26 @@ function builtinSymbolGlyphNameLookup(baseFamily) {
23
24
  if (baseFamily === "Symbol") return require_afm_widths.symbolGlyphName;
24
25
  if (baseFamily === "ZapfDingbats") return require_afm_widths.zapfDingbatsGlyphName;
25
26
  }
26
- function glyphNameToUnicodeWithUniFallback(name) {
27
- const direct = require_afm_widths.glyphNameToUnicode(name);
28
- if (direct !== void 0) return direct;
29
- const uniMatch = /^uni([0-9A-Fa-f]{4,6})$/.exec(name);
30
- return uniMatch?.[1] !== void 0 ? Number.parseInt(uniMatch[1], 16) : void 0;
27
+ function readFontProgram(descriptor, context) {
28
+ if (descriptor === void 0) return;
29
+ for (const key of [
30
+ "FontFile2",
31
+ "FontFile3",
32
+ "FontFile"
33
+ ]) {
34
+ const stream = context.resolver.resolve(require_objects.dictGet(descriptor, key));
35
+ if (stream?.kind !== "stream") continue;
36
+ const decoded = require_filters.decodeStream(stream.raw, stream.dict, context.sink);
37
+ const encoding = require_builtin_encoding.readFontProgramEncoding(decoded.bytes);
38
+ if (encoding !== void 0) return encoding;
39
+ }
40
+ }
41
+ function lazyFontProgram(descriptor, context) {
42
+ let read;
43
+ return () => {
44
+ read ??= { encoding: readFontProgram(descriptor, context) };
45
+ return read.encoding;
46
+ };
31
47
  }
32
48
  function readDifferencesMap(differences) {
33
49
  const map = /* @__PURE__ */ new Map();
@@ -71,13 +87,36 @@ function buildSimpleFont(fontDict, context) {
71
87
  const encodingObj = require_objects.dictGet(fontDict, "Encoding");
72
88
  const encodingDict = context.resolver.resolveDict(encodingObj);
73
89
  const baseEncodingName = require_objects.asName(encodingDict !== void 0 ? require_objects.dictGet(encodingDict, "BaseEncoding") : encodingObj);
74
- if (baseEncodingName !== void 0 && baseEncodingName !== "WinAnsiEncoding") context.sink({
90
+ const namedBaseGlyphName = baseEncodingName !== void 0 ? require_afm_widths.namedEncodingGlyphName(baseEncodingName) : void 0;
91
+ if (baseEncodingName !== void 0 && namedBaseGlyphName === void 0) context.sink({
75
92
  code: "char/encoding-approximated",
76
93
  severity: "info",
77
94
  message: `base encoding "${baseEncodingName}" has no dedicated table here and is approximated as WinAnsiEncoding`
78
95
  });
79
96
  const differencesMap = readDifferencesMap(encodingDict !== void 0 ? require_objects.asArray(require_objects.dictGet(encodingDict, "Differences")) : void 0);
80
- const fallbackGlyphName = builtinGlyphName ?? (symbolic ? () => void 0 : require_afm_widths.winAnsiGlyphName);
97
+ const programEncoding = lazyFontProgram(descriptor, context);
98
+ const symbolEncoded = symbolic || builtinGlyphName !== void 0;
99
+ const byGlyphName = (source) => (code) => {
100
+ const name = source(code);
101
+ return name === void 0 ? void 0 : require_afm_widths.glyphNameToUnicode(name);
102
+ };
103
+ const fromProgram = (code) => programEncoding()?.codeToUnicode(code);
104
+ const namedBase = namedBaseGlyphName === void 0 ? void 0 : byGlyphName(namedBaseGlyphName);
105
+ const resolvers = [byGlyphName((code) => differencesMap.get(code)), ...symbolEncoded ? [
106
+ fromProgram,
107
+ builtinGlyphName === void 0 ? void 0 : byGlyphName(builtinGlyphName),
108
+ namedBase
109
+ ] : [
110
+ namedBase,
111
+ fromProgram,
112
+ byGlyphName(require_afm_widths.winAnsiGlyphName)
113
+ ]].filter((resolver) => resolver !== void 0);
114
+ const unicodeForCode = (code) => {
115
+ for (const resolve of resolvers) {
116
+ const unicode = resolve(code);
117
+ if (unicode !== void 0) return unicode;
118
+ }
119
+ };
81
120
  const decodeToUnicode = (codes) => {
82
121
  let out = "";
83
122
  let unmapped = 0;
@@ -87,10 +126,9 @@ function buildSimpleFont(fontDict, context) {
87
126
  out += viaToUnicode;
88
127
  continue;
89
128
  }
90
- const name = differencesMap.get(code) ?? fallbackGlyphName(code);
91
- const unicode = name !== void 0 ? glyphNameToUnicodeWithUniFallback(name) : void 0;
129
+ const unicode = unicodeForCode(code);
92
130
  if (unicode !== void 0) {
93
- out += String.fromCharCode(unicode);
131
+ out += String.fromCodePoint(unicode);
94
132
  continue;
95
133
  }
96
134
  unmapped++;
@@ -149,6 +187,8 @@ function buildCompositeFont(fontDict, context) {
149
187
  const widthMap = readCidWidths(descendantDict !== void 0 ? require_objects.asArray(require_objects.dictGet(descendantDict, "W")) : void 0);
150
188
  const widthOf = (cid) => widthMap.get(cid) ?? dw;
151
189
  const toUnicode = readToUnicodeCMap(fontDict, context);
190
+ const cidToGidMap = descendantDict !== void 0 ? require_objects.dictGet(descendantDict, "CIDToGIDMap") : void 0;
191
+ const programEncoding = require_objects.isName(require_objects.dictGet(fontDict, "Encoding"), "Identity-H") && (cidToGidMap === void 0 || require_objects.isName(cidToGidMap, "Identity")) ? lazyFontProgram(descriptor, context) : void 0;
152
192
  const decodeToUnicode = (codes) => {
153
193
  let out = "";
154
194
  let glyphCount = 0;
@@ -161,6 +201,11 @@ function buildCompositeFont(fontDict, context) {
161
201
  out += mapped;
162
202
  continue;
163
203
  }
204
+ const fromProgram = programEncoding?.()?.glyphIdToUnicode(cid);
205
+ if (fromProgram !== void 0) {
206
+ out += String.fromCodePoint(fromProgram);
207
+ continue;
208
+ }
164
209
  unmapped++;
165
210
  out += REPLACEMENT_CHARACTER;
166
211
  }
package/dist/font-read.js CHANGED
@@ -1,6 +1,7 @@
1
- import { c as winAnsiGlyphName, l as zapfDingbatsGlyphName, n as widthOfCode, o as glyphNameToUnicode, s as symbolGlyphName } from "./afm-widths-B6KdmpRF.js";
2
- import { asArray, asName, asNumber, dictGet } from "./objects.js";
1
+ import { c as glyphNameToUnicode, f as symbolGlyphName, m as zapfDingbatsGlyphName, n as widthOfCode, p as winAnsiGlyphName, u as namedEncodingGlyphName } from "./afm-widths-De_QMWgC.js";
2
+ import { asArray, asName, asNumber, dictGet, isName } from "./objects.js";
3
3
  import { decodeStream } from "./filters.js";
4
+ import { readFontProgramEncoding } from "./builtin-encoding.js";
4
5
  import { parseToUnicodeCMap } from "./cmap.js";
5
6
  import { resolveStandardFont } from "./fonts.js";
6
7
  import { styleFromBaseFontName } from "./font-style.js";
@@ -22,11 +23,26 @@ function builtinSymbolGlyphNameLookup(baseFamily) {
22
23
  if (baseFamily === "Symbol") return symbolGlyphName;
23
24
  if (baseFamily === "ZapfDingbats") return zapfDingbatsGlyphName;
24
25
  }
25
- function glyphNameToUnicodeWithUniFallback(name) {
26
- const direct = glyphNameToUnicode(name);
27
- if (direct !== void 0) return direct;
28
- const uniMatch = /^uni([0-9A-Fa-f]{4,6})$/.exec(name);
29
- return uniMatch?.[1] !== void 0 ? Number.parseInt(uniMatch[1], 16) : void 0;
26
+ function readFontProgram(descriptor, context) {
27
+ if (descriptor === void 0) return;
28
+ for (const key of [
29
+ "FontFile2",
30
+ "FontFile3",
31
+ "FontFile"
32
+ ]) {
33
+ const stream = context.resolver.resolve(dictGet(descriptor, key));
34
+ if (stream?.kind !== "stream") continue;
35
+ const decoded = decodeStream(stream.raw, stream.dict, context.sink);
36
+ const encoding = readFontProgramEncoding(decoded.bytes);
37
+ if (encoding !== void 0) return encoding;
38
+ }
39
+ }
40
+ function lazyFontProgram(descriptor, context) {
41
+ let read;
42
+ return () => {
43
+ read ??= { encoding: readFontProgram(descriptor, context) };
44
+ return read.encoding;
45
+ };
30
46
  }
31
47
  function readDifferencesMap(differences) {
32
48
  const map = /* @__PURE__ */ new Map();
@@ -70,13 +86,36 @@ function buildSimpleFont(fontDict, context) {
70
86
  const encodingObj = dictGet(fontDict, "Encoding");
71
87
  const encodingDict = context.resolver.resolveDict(encodingObj);
72
88
  const baseEncodingName = asName(encodingDict !== void 0 ? dictGet(encodingDict, "BaseEncoding") : encodingObj);
73
- if (baseEncodingName !== void 0 && baseEncodingName !== "WinAnsiEncoding") context.sink({
89
+ const namedBaseGlyphName = baseEncodingName !== void 0 ? namedEncodingGlyphName(baseEncodingName) : void 0;
90
+ if (baseEncodingName !== void 0 && namedBaseGlyphName === void 0) context.sink({
74
91
  code: "char/encoding-approximated",
75
92
  severity: "info",
76
93
  message: `base encoding "${baseEncodingName}" has no dedicated table here and is approximated as WinAnsiEncoding`
77
94
  });
78
95
  const differencesMap = readDifferencesMap(encodingDict !== void 0 ? asArray(dictGet(encodingDict, "Differences")) : void 0);
79
- const fallbackGlyphName = builtinGlyphName ?? (symbolic ? () => void 0 : winAnsiGlyphName);
96
+ const programEncoding = lazyFontProgram(descriptor, context);
97
+ const symbolEncoded = symbolic || builtinGlyphName !== void 0;
98
+ const byGlyphName = (source) => (code) => {
99
+ const name = source(code);
100
+ return name === void 0 ? void 0 : glyphNameToUnicode(name);
101
+ };
102
+ const fromProgram = (code) => programEncoding()?.codeToUnicode(code);
103
+ const namedBase = namedBaseGlyphName === void 0 ? void 0 : byGlyphName(namedBaseGlyphName);
104
+ const resolvers = [byGlyphName((code) => differencesMap.get(code)), ...symbolEncoded ? [
105
+ fromProgram,
106
+ builtinGlyphName === void 0 ? void 0 : byGlyphName(builtinGlyphName),
107
+ namedBase
108
+ ] : [
109
+ namedBase,
110
+ fromProgram,
111
+ byGlyphName(winAnsiGlyphName)
112
+ ]].filter((resolver) => resolver !== void 0);
113
+ const unicodeForCode = (code) => {
114
+ for (const resolve of resolvers) {
115
+ const unicode = resolve(code);
116
+ if (unicode !== void 0) return unicode;
117
+ }
118
+ };
80
119
  const decodeToUnicode = (codes) => {
81
120
  let out = "";
82
121
  let unmapped = 0;
@@ -86,10 +125,9 @@ function buildSimpleFont(fontDict, context) {
86
125
  out += viaToUnicode;
87
126
  continue;
88
127
  }
89
- const name = differencesMap.get(code) ?? fallbackGlyphName(code);
90
- const unicode = name !== void 0 ? glyphNameToUnicodeWithUniFallback(name) : void 0;
128
+ const unicode = unicodeForCode(code);
91
129
  if (unicode !== void 0) {
92
- out += String.fromCharCode(unicode);
130
+ out += String.fromCodePoint(unicode);
93
131
  continue;
94
132
  }
95
133
  unmapped++;
@@ -148,6 +186,8 @@ function buildCompositeFont(fontDict, context) {
148
186
  const widthMap = readCidWidths(descendantDict !== void 0 ? asArray(dictGet(descendantDict, "W")) : void 0);
149
187
  const widthOf = (cid) => widthMap.get(cid) ?? dw;
150
188
  const toUnicode = readToUnicodeCMap(fontDict, context);
189
+ const cidToGidMap = descendantDict !== void 0 ? dictGet(descendantDict, "CIDToGIDMap") : void 0;
190
+ const programEncoding = isName(dictGet(fontDict, "Encoding"), "Identity-H") && (cidToGidMap === void 0 || isName(cidToGidMap, "Identity")) ? lazyFontProgram(descriptor, context) : void 0;
151
191
  const decodeToUnicode = (codes) => {
152
192
  let out = "";
153
193
  let glyphCount = 0;
@@ -160,6 +200,11 @@ function buildCompositeFont(fontDict, context) {
160
200
  out += mapped;
161
201
  continue;
162
202
  }
203
+ const fromProgram = programEncoding?.()?.glyphIdToUnicode(cid);
204
+ if (fromProgram !== void 0) {
205
+ out += String.fromCodePoint(fromProgram);
206
+ continue;
207
+ }
163
208
  unmapped++;
164
209
  out += REPLACEMENT_CHARACTER;
165
210
  }