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.
Files changed (170) hide show
  1. package/README.md +56 -15
  2. package/dist/assets/caladea-bold.cjs +5 -0
  3. package/dist/assets/caladea-bold.d.cts +4 -0
  4. package/dist/assets/caladea-bold.d.ts +4 -0
  5. package/dist/assets/caladea-bold.js +4 -0
  6. package/dist/assets/caladea-bolditalic.cjs +5 -0
  7. package/dist/assets/caladea-bolditalic.d.cts +4 -0
  8. package/dist/assets/caladea-bolditalic.d.ts +4 -0
  9. package/dist/assets/caladea-bolditalic.js +4 -0
  10. package/dist/assets/caladea-italic.cjs +5 -0
  11. package/dist/assets/caladea-italic.d.cts +4 -0
  12. package/dist/assets/caladea-italic.d.ts +4 -0
  13. package/dist/assets/caladea-italic.js +4 -0
  14. package/dist/assets/caladea-regular.cjs +5 -0
  15. package/dist/assets/caladea-regular.d.cts +4 -0
  16. package/dist/assets/caladea-regular.d.ts +4 -0
  17. package/dist/assets/caladea-regular.js +4 -0
  18. package/dist/assets/carlito-bold.cjs +5 -0
  19. package/dist/assets/carlito-bold.d.cts +4 -0
  20. package/dist/assets/carlito-bold.d.ts +4 -0
  21. package/dist/assets/carlito-bold.js +4 -0
  22. package/dist/assets/carlito-bolditalic.cjs +5 -0
  23. package/dist/assets/carlito-bolditalic.d.cts +4 -0
  24. package/dist/assets/carlito-bolditalic.d.ts +4 -0
  25. package/dist/assets/carlito-bolditalic.js +4 -0
  26. package/dist/assets/carlito-italic.cjs +5 -0
  27. package/dist/assets/carlito-italic.d.cts +4 -0
  28. package/dist/assets/carlito-italic.d.ts +4 -0
  29. package/dist/assets/carlito-italic.js +4 -0
  30. package/dist/assets/carlito-regular.cjs +5 -0
  31. package/dist/assets/carlito-regular.d.cts +4 -0
  32. package/dist/assets/carlito-regular.d.ts +4 -0
  33. package/dist/assets/carlito-regular.js +4 -0
  34. package/dist/cff-probe.cjs +133 -0
  35. package/dist/cff-probe.d.cts +10 -0
  36. package/dist/cff-probe.d.ts +10 -0
  37. package/dist/cff-probe.js +132 -0
  38. package/dist/cmap-table.cjs +108 -0
  39. package/dist/cmap-table.d.cts +6 -0
  40. package/dist/cmap-table.d.ts +6 -0
  41. package/dist/cmap-table.js +107 -0
  42. package/dist/content-write.cjs +36 -17
  43. package/dist/content-write.d.cts +9 -2
  44. package/dist/content-write.d.ts +9 -2
  45. package/dist/content-write.js +35 -16
  46. package/dist/crypto/aes.cjs +166 -0
  47. package/dist/crypto/aes.d.cts +6 -0
  48. package/dist/crypto/aes.d.ts +6 -0
  49. package/dist/crypto/aes.js +163 -0
  50. package/dist/crypto/md5.cjs +215 -0
  51. package/dist/crypto/md5.d.cts +4 -0
  52. package/dist/crypto/md5.d.ts +4 -0
  53. package/dist/crypto/md5.js +214 -0
  54. package/dist/crypto/rc4.cjs +29 -0
  55. package/dist/crypto/rc4.d.cts +4 -0
  56. package/dist/crypto/rc4.d.ts +4 -0
  57. package/dist/crypto/rc4.js +28 -0
  58. package/dist/crypto/sha2.cjs +261 -0
  59. package/dist/crypto/sha2.d.cts +6 -0
  60. package/dist/crypto/sha2.d.ts +6 -0
  61. package/dist/crypto/sha2.js +258 -0
  62. package/dist/diagnostics.cjs +7 -0
  63. package/dist/diagnostics.d.cts +4 -1
  64. package/dist/diagnostics.d.ts +4 -1
  65. package/dist/diagnostics.js +7 -1
  66. package/dist/document.cjs +38 -2
  67. package/dist/document.js +38 -2
  68. package/dist/embedded-font-CLedn-mT.d.cts +42 -0
  69. package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
  70. package/dist/embedded-font-write.cjs +92 -0
  71. package/dist/embedded-font-write.d.cts +22 -0
  72. package/dist/embedded-font-write.d.ts +22 -0
  73. package/dist/embedded-font-write.js +90 -0
  74. package/dist/embedded-font.cjs +142 -0
  75. package/dist/embedded-font.d.cts +2 -0
  76. package/dist/embedded-font.d.ts +2 -0
  77. package/dist/embedded-font.js +138 -0
  78. package/dist/encrypt.cjs +264 -0
  79. package/dist/encrypt.d.cts +11 -0
  80. package/dist/encrypt.d.ts +11 -0
  81. package/dist/encrypt.js +263 -0
  82. package/dist/filters.cjs +19 -1
  83. package/dist/filters.js +19 -1
  84. package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
  85. package/dist/font-registry-yby02snZ.d.cts +38 -0
  86. package/dist/font-registry.cjs +152 -0
  87. package/dist/font-registry.d.cts +2 -0
  88. package/dist/font-registry.d.ts +2 -0
  89. package/dist/font-registry.js +150 -0
  90. package/dist/font-substitutes.cjs +13 -0
  91. package/dist/font-substitutes.d.cts +5 -0
  92. package/dist/font-substitutes.d.ts +5 -0
  93. package/dist/font-substitutes.js +12 -0
  94. package/dist/font-tables.cjs +127 -0
  95. package/dist/font-tables.d.cts +43 -0
  96. package/dist/font-tables.d.ts +43 -0
  97. package/dist/font-tables.js +122 -0
  98. package/dist/fonts.cjs +1 -0
  99. package/dist/fonts.d.cts +2 -1
  100. package/dist/fonts.d.ts +2 -1
  101. package/dist/fonts.js +1 -1
  102. package/dist/glyf.cjs +127 -0
  103. package/dist/glyf.d.cts +31 -0
  104. package/dist/glyf.d.ts +31 -0
  105. package/dist/glyf.js +125 -0
  106. package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
  107. package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
  108. package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
  109. package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
  110. package/dist/image/ccitt.cjs +488 -0
  111. package/dist/image/ccitt.d.cts +17 -0
  112. package/dist/image/ccitt.d.ts +17 -0
  113. package/dist/image/ccitt.js +487 -0
  114. package/dist/images-read.cjs +1 -4
  115. package/dist/images-read.js +2 -5
  116. package/dist/index.cjs +8 -0
  117. package/dist/index.d.cts +7 -4
  118. package/dist/index.d.ts +7 -4
  119. package/dist/index.js +5 -3
  120. package/dist/interpret.cjs +173 -38
  121. package/dist/interpret.d.cts +27 -10
  122. package/dist/interpret.d.ts +27 -10
  123. package/dist/interpret.js +174 -39
  124. package/dist/math-font-write.cjs +3 -32
  125. package/dist/math-font-write.js +2 -31
  126. package/dist/math-font.cjs +7 -5
  127. package/dist/math-font.js +5 -3
  128. package/dist/math-table.d.cts +1 -1
  129. package/dist/math-table.d.ts +1 -1
  130. package/dist/{matrix-B3c2_a2f.d.cts → matrix-BHzJESll.d.cts} +2 -1
  131. package/dist/{matrix-B3c2_a2f.d.ts → matrix-BHzJESll.d.ts} +2 -1
  132. package/dist/matrix.cjs +2 -0
  133. package/dist/matrix.d.cts +2 -2
  134. package/dist/matrix.d.ts +2 -2
  135. package/dist/matrix.js +2 -1
  136. package/dist/measure.cjs +65 -14
  137. package/dist/measure.d.cts +8 -1
  138. package/dist/measure.d.ts +8 -1
  139. package/dist/measure.js +64 -15
  140. package/dist/objects.cjs +4 -0
  141. package/dist/objects.d.cts +2 -1
  142. package/dist/objects.d.ts +2 -1
  143. package/dist/objects.js +4 -1
  144. package/dist/read.cjs +43 -4
  145. package/dist/read.d.cts +1 -1
  146. package/dist/read.d.ts +1 -1
  147. package/dist/read.js +43 -4
  148. package/dist/sfnt-V08bb5ut.d.cts +21 -0
  149. package/dist/sfnt-V08bb5ut.d.ts +21 -0
  150. package/dist/sfnt-subset.cjs +250 -0
  151. package/dist/sfnt-subset.d.cts +11 -0
  152. package/dist/sfnt-subset.d.ts +11 -0
  153. package/dist/sfnt-subset.js +249 -0
  154. package/dist/sfnt.cjs +50 -4
  155. package/dist/sfnt.d.cts +2 -17
  156. package/dist/sfnt.d.ts +2 -17
  157. package/dist/sfnt.js +47 -5
  158. package/dist/tounicode.cjs +34 -0
  159. package/dist/tounicode.d.cts +5 -0
  160. package/dist/tounicode.d.ts +5 -0
  161. package/dist/tounicode.js +33 -0
  162. package/dist/write.cjs +81 -11
  163. package/dist/write.d.cts +6 -0
  164. package/dist/write.d.ts +6 -0
  165. package/dist/write.js +82 -12
  166. package/package.json +1 -1
  167. package/dist/math-cmap.cjs +0 -81
  168. package/dist/math-cmap.d.cts +0 -6
  169. package/dist/math-cmap.d.ts +0 -6
  170. package/dist/math-cmap.js +0 -80
@@ -0,0 +1,150 @@
1
+ import { parseSfnt } from "./sfnt.js";
2
+ import { base64ToBytes } from "./util/base64.js";
3
+ import { normalizeFamilyName, resolveStandardFont } from "./fonts.js";
4
+ import { loadEmbeddedFace } from "./embedded-font.js";
5
+ import { CALADEA_BOLD_FONT_DEFLATED_BASE64 } from "./assets/caladea-bold.js";
6
+ import { CALADEA_BOLDITALIC_FONT_DEFLATED_BASE64 } from "./assets/caladea-bolditalic.js";
7
+ import { CALADEA_ITALIC_FONT_DEFLATED_BASE64 } from "./assets/caladea-italic.js";
8
+ import { CALADEA_REGULAR_FONT_DEFLATED_BASE64 } from "./assets/caladea-regular.js";
9
+ import { CARLITO_BOLD_FONT_DEFLATED_BASE64 } from "./assets/carlito-bold.js";
10
+ import { CARLITO_BOLDITALIC_FONT_DEFLATED_BASE64 } from "./assets/carlito-bolditalic.js";
11
+ import { CARLITO_ITALIC_FONT_DEFLATED_BASE64 } from "./assets/carlito-italic.js";
12
+ import { CARLITO_REGULAR_FONT_DEFLATED_BASE64 } from "./assets/carlito-regular.js";
13
+ import { resolveVendoredSubstituteFamily } from "./font-substitutes.js";
14
+ import { inflateSync } from "fflate";
15
+ //#region src/font-registry.ts
16
+ function faceCacheKey(family, bold, italic) {
17
+ return `${normalizeFamilyName(family)}|${bold ? 1 : 0}|${italic ? 1 : 0}`;
18
+ }
19
+ function embedFace(bytes) {
20
+ const sfnt = parseSfnt(bytes);
21
+ if (sfnt === void 0) return;
22
+ return loadEmbeddedFace(sfnt);
23
+ }
24
+ function findExactFace(list, family, bold, italic) {
25
+ const normalized = normalizeFamilyName(family);
26
+ return list.find((candidate) => normalizeFamilyName(candidate.family) === normalized && candidate.bold === bold && candidate.italic === italic);
27
+ }
28
+ function findFamilyRegular(list, family) {
29
+ const normalized = normalizeFamilyName(family);
30
+ const familyFaces = list.filter((candidate) => normalizeFamilyName(candidate.family) === normalized);
31
+ if (familyFaces.length === 0) return;
32
+ return familyFaces.find((candidate) => !candidate.bold && !candidate.italic) ?? familyFaces[0];
33
+ }
34
+ const vendoredFaceBytesCache = /* @__PURE__ */ new Map();
35
+ const VENDORED_FACE_BASE64 = {
36
+ carlito: {
37
+ regular: CARLITO_REGULAR_FONT_DEFLATED_BASE64,
38
+ bold: CARLITO_BOLD_FONT_DEFLATED_BASE64,
39
+ italic: CARLITO_ITALIC_FONT_DEFLATED_BASE64,
40
+ boldItalic: CARLITO_BOLDITALIC_FONT_DEFLATED_BASE64
41
+ },
42
+ caladea: {
43
+ regular: CALADEA_REGULAR_FONT_DEFLATED_BASE64,
44
+ bold: CALADEA_BOLD_FONT_DEFLATED_BASE64,
45
+ italic: CALADEA_ITALIC_FONT_DEFLATED_BASE64,
46
+ boldItalic: CALADEA_BOLDITALIC_FONT_DEFLATED_BASE64
47
+ }
48
+ };
49
+ function loadVendoredFaceBytes(family, bold, italic) {
50
+ const faceKey = bold && italic ? "boldItalic" : bold ? "bold" : italic ? "italic" : "regular";
51
+ const cacheKey = `${family}-${faceKey}`;
52
+ const cached = vendoredFaceBytesCache.get(cacheKey);
53
+ if (cached !== void 0) return cached;
54
+ const deflatedBase64 = VENDORED_FACE_BASE64[family][faceKey];
55
+ const inflated = inflateSync(base64ToBytes(deflatedBase64));
56
+ const bytes = new Uint8Array(inflated.length);
57
+ bytes.set(inflated);
58
+ vendoredFaceBytesCache.set(cacheKey, bytes);
59
+ return bytes;
60
+ }
61
+ function createFontRegistry(options = {}) {
62
+ const sourceFonts = options.sourceFonts ?? [];
63
+ const fonts = options.fonts ?? [];
64
+ const substitutesEnabled = (options.substitutes ?? "vendored") === "vendored";
65
+ const onSubstitution = options.onSubstitution;
66
+ const cache = /* @__PURE__ */ new Map();
67
+ function resolveUncached(family, bold, italic) {
68
+ const sourceExact = findExactFace(sourceFonts, family, bold, italic);
69
+ if (sourceExact !== void 0) {
70
+ const face = embedFace(sourceExact.bytes);
71
+ if (face !== void 0) return {
72
+ kind: "embedded",
73
+ face
74
+ };
75
+ }
76
+ const callerExact = findExactFace(fonts, family, bold, italic);
77
+ if (callerExact !== void 0) {
78
+ const face = embedFace(callerExact.bytes);
79
+ if (face !== void 0) return {
80
+ kind: "embedded",
81
+ face
82
+ };
83
+ }
84
+ const sourceFamilyRegular = findFamilyRegular(sourceFonts, family);
85
+ const callerFamilyRegular = sourceFamilyRegular === void 0 ? findFamilyRegular(fonts, family) : void 0;
86
+ const familyRegular = sourceFamilyRegular ?? callerFamilyRegular;
87
+ if (familyRegular !== void 0) {
88
+ const face = embedFace(familyRegular.bytes);
89
+ if (face !== void 0) {
90
+ onSubstitution?.({
91
+ requestedFamily: family,
92
+ requestedBold: bold,
93
+ requestedItalic: italic,
94
+ reason: "missing-face",
95
+ resolvedFamily: family
96
+ });
97
+ return {
98
+ kind: "embedded",
99
+ face
100
+ };
101
+ }
102
+ }
103
+ if (substitutesEnabled) {
104
+ const vendoredFamily = resolveVendoredSubstituteFamily(family);
105
+ if (vendoredFamily !== void 0) {
106
+ const face = embedFace(loadVendoredFaceBytes(vendoredFamily, bold, italic));
107
+ if (face !== void 0) {
108
+ onSubstitution?.({
109
+ requestedFamily: family,
110
+ requestedBold: bold,
111
+ requestedItalic: italic,
112
+ reason: "vendored-substitute",
113
+ resolvedFamily: vendoredFamily
114
+ });
115
+ return {
116
+ kind: "embedded",
117
+ face
118
+ };
119
+ }
120
+ }
121
+ }
122
+ const standard = resolveStandardFont(family, bold, italic);
123
+ return {
124
+ kind: "standard",
125
+ standardName: standard.standardName,
126
+ matched: standard.matched
127
+ };
128
+ }
129
+ return { resolve(font) {
130
+ const bold = font.weight === "bold";
131
+ const italic = font.style === "italic";
132
+ const key = faceCacheKey(font.family, bold, italic);
133
+ const cached = cache.get(key);
134
+ if (cached !== void 0) return cached;
135
+ const resolved = resolveUncached(font.family, bold, italic);
136
+ cache.set(key, resolved);
137
+ return resolved;
138
+ } };
139
+ }
140
+ function resolveFaceWithRegistry(registry, font) {
141
+ if (registry !== void 0) return registry.resolve(font);
142
+ const standard = resolveStandardFont(font.family, font.weight === "bold", font.style === "italic");
143
+ return {
144
+ kind: "standard",
145
+ standardName: standard.standardName,
146
+ matched: standard.matched
147
+ };
148
+ }
149
+ //#endregion
150
+ export { createFontRegistry, resolveFaceWithRegistry };
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_fonts = require("./fonts.cjs");
3
+ //#region src/font-substitutes.ts
4
+ const SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME = /* @__PURE__ */ new Map([
5
+ ["calibri", "carlito"],
6
+ ["calibrilight", "carlito"],
7
+ ["cambria", "caladea"]
8
+ ]);
9
+ function resolveVendoredSubstituteFamily(rawFamily) {
10
+ return SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME.get(require_fonts.normalizeFamilyName(rawFamily));
11
+ }
12
+ //#endregion
13
+ exports.resolveVendoredSubstituteFamily = resolveVendoredSubstituteFamily;
@@ -0,0 +1,5 @@
1
+ //#region src/font-substitutes.d.ts
2
+ type VendoredFamily = 'carlito' | 'caladea';
3
+ declare function resolveVendoredSubstituteFamily(rawFamily: string): VendoredFamily | undefined;
4
+ //#endregion
5
+ export { VendoredFamily, resolveVendoredSubstituteFamily };
@@ -0,0 +1,5 @@
1
+ //#region src/font-substitutes.d.ts
2
+ type VendoredFamily = 'carlito' | 'caladea';
3
+ declare function resolveVendoredSubstituteFamily(rawFamily: string): VendoredFamily | undefined;
4
+ //#endregion
5
+ export { VendoredFamily, resolveVendoredSubstituteFamily };
@@ -0,0 +1,12 @@
1
+ import { normalizeFamilyName } from "./fonts.js";
2
+ //#region src/font-substitutes.ts
3
+ const SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME = /* @__PURE__ */ new Map([
4
+ ["calibri", "carlito"],
5
+ ["calibrilight", "carlito"],
6
+ ["cambria", "caladea"]
7
+ ]);
8
+ function resolveVendoredSubstituteFamily(rawFamily) {
9
+ return SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME.get(normalizeFamilyName(rawFamily));
10
+ }
11
+ //#endregion
12
+ export { resolveVendoredSubstituteFamily };
@@ -0,0 +1,127 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sfnt = require("./sfnt.cjs");
3
+ //#region src/font-tables.ts
4
+ const HEAD_TABLE_SIZE = 54;
5
+ const HEAD_MAGIC_NUMBER = 1594834165;
6
+ const MIN_UNITS_PER_EM = 16;
7
+ const MAX_UNITS_PER_EM = 16384;
8
+ function parseHead(font) {
9
+ const bytes = require_sfnt.sfntTableBytes(font, "head");
10
+ if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, HEAD_TABLE_SIZE)) return;
11
+ if (require_sfnt.u32(bytes, 12) !== HEAD_MAGIC_NUMBER) return;
12
+ const unitsPerEm = require_sfnt.u16(bytes, 18);
13
+ if (unitsPerEm < MIN_UNITS_PER_EM || unitsPerEm > MAX_UNITS_PER_EM) return;
14
+ const indexToLocFormat = require_sfnt.i16(bytes, 50);
15
+ if (indexToLocFormat !== 0 && indexToLocFormat !== 1) return;
16
+ return {
17
+ unitsPerEm,
18
+ checkSumAdjustment: require_sfnt.u32(bytes, 8),
19
+ xMin: require_sfnt.i16(bytes, 36),
20
+ yMin: require_sfnt.i16(bytes, 38),
21
+ xMax: require_sfnt.i16(bytes, 40),
22
+ yMax: require_sfnt.i16(bytes, 42),
23
+ indexToLocFormat
24
+ };
25
+ }
26
+ const MAXP_HEADER_SIZE = 6;
27
+ function parseMaxp(font) {
28
+ const bytes = require_sfnt.sfntTableBytes(font, "maxp");
29
+ if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, MAXP_HEADER_SIZE)) return;
30
+ return { numGlyphs: require_sfnt.u16(bytes, 4) };
31
+ }
32
+ const OS2_VERSION_0_SIZE = 78;
33
+ const OS2_VERSION_2_SIZE = 96;
34
+ const OS2_VERSION_WITH_HEIGHTS = 2;
35
+ const OS2_PANOSE_OFFSET = 32;
36
+ function parseOs2(font) {
37
+ const bytes = require_sfnt.sfntTableBytes(font, "OS/2");
38
+ if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, OS2_VERSION_0_SIZE)) return;
39
+ const version = require_sfnt.u16(bytes, 0);
40
+ const hasHeights = version >= OS2_VERSION_WITH_HEIGHTS && require_sfnt.hasBytes(bytes, 0, OS2_VERSION_2_SIZE);
41
+ return {
42
+ version,
43
+ fsSelection: require_sfnt.u16(bytes, 62),
44
+ panose: [...bytes.subarray(OS2_PANOSE_OFFSET, 42)],
45
+ sTypoAscender: require_sfnt.i16(bytes, 68),
46
+ sTypoDescender: require_sfnt.i16(bytes, 70),
47
+ sTypoLineGap: require_sfnt.i16(bytes, 72),
48
+ usWinAscent: require_sfnt.u16(bytes, 74),
49
+ usWinDescent: require_sfnt.u16(bytes, 76),
50
+ sxHeight: hasHeights ? require_sfnt.i16(bytes, 86) : void 0,
51
+ sCapHeight: hasHeights ? require_sfnt.i16(bytes, 88) : void 0
52
+ };
53
+ }
54
+ const POST_HEADER_SIZE = 32;
55
+ const FIXED_16_16_SCALE = 65536;
56
+ function parsePost(font) {
57
+ const bytes = require_sfnt.sfntTableBytes(font, "post");
58
+ if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
59
+ return {
60
+ version: require_sfnt.u32(bytes, 0),
61
+ italicAngle: require_sfnt.i32(bytes, 4) / FIXED_16_16_SCALE,
62
+ underlinePosition: require_sfnt.i16(bytes, 8),
63
+ underlineThickness: require_sfnt.i16(bytes, 10)
64
+ };
65
+ }
66
+ const NAME_HEADER_SIZE = 6;
67
+ const NAME_RECORD_SIZE = 12;
68
+ const NAME_ID_FAMILY = 1;
69
+ const NAME_ID_POSTSCRIPT = 6;
70
+ const NAME_ID_TYPOGRAPHIC_FAMILY = 16;
71
+ const PLATFORM_UNICODE = 0;
72
+ const PLATFORM_MACINTOSH = 1;
73
+ const PLATFORM_WINDOWS = 3;
74
+ const WINDOWS_ENCODING_UNICODE_BMP = 1;
75
+ const MACINTOSH_ENCODING_ROMAN = 0;
76
+ function decodeUtf16Be(bytes, offset, length) {
77
+ let text = "";
78
+ for (let i = 0; i + 1 < length; i += 2) text += String.fromCharCode(bytes[offset + i] << 8 | bytes[offset + i + 1]);
79
+ return text;
80
+ }
81
+ function decodeMacRoman(bytes, offset, length) {
82
+ let text = "";
83
+ for (let i = 0; i < length; i++) text += String.fromCharCode(bytes[offset + i]);
84
+ return text;
85
+ }
86
+ function platformRank(record) {
87
+ if (record.platformId === PLATFORM_WINDOWS && record.encodingId === WINDOWS_ENCODING_UNICODE_BMP) return 0;
88
+ if (record.platformId === PLATFORM_UNICODE) return 1;
89
+ if (record.platformId === PLATFORM_MACINTOSH && record.encodingId === MACINTOSH_ENCODING_ROMAN) return 2;
90
+ return 3;
91
+ }
92
+ function readName(bytes, records, nameId) {
93
+ const matches = records.filter((record) => record.nameId === nameId && platformRank(record) < 3).sort((a, b) => platformRank(a) - platformRank(b));
94
+ for (const record of matches) {
95
+ if (!require_sfnt.hasBytes(bytes, record.stringOffset, record.length)) continue;
96
+ const text = record.platformId === PLATFORM_MACINTOSH ? decodeMacRoman(bytes, record.stringOffset, record.length) : decodeUtf16Be(bytes, record.stringOffset, record.length);
97
+ if (text.length > 0) return text;
98
+ }
99
+ }
100
+ function parseName(font) {
101
+ const bytes = require_sfnt.sfntTableBytes(font, "name");
102
+ if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, NAME_HEADER_SIZE)) return;
103
+ const count = require_sfnt.u16(bytes, 2);
104
+ const storageOffset = require_sfnt.u16(bytes, 4);
105
+ if (!require_sfnt.hasBytes(bytes, NAME_HEADER_SIZE, count * NAME_RECORD_SIZE)) return;
106
+ const records = [];
107
+ for (let i = 0; i < count; i++) {
108
+ const recordOffset = NAME_HEADER_SIZE + i * NAME_RECORD_SIZE;
109
+ records.push({
110
+ platformId: require_sfnt.u16(bytes, recordOffset),
111
+ encodingId: require_sfnt.u16(bytes, recordOffset + 2),
112
+ nameId: require_sfnt.u16(bytes, recordOffset + 6),
113
+ length: require_sfnt.u16(bytes, recordOffset + 8),
114
+ stringOffset: storageOffset + require_sfnt.u16(bytes, recordOffset + 10)
115
+ });
116
+ }
117
+ return {
118
+ postScriptName: readName(bytes, records, NAME_ID_POSTSCRIPT),
119
+ familyName: readName(bytes, records, NAME_ID_TYPOGRAPHIC_FAMILY) ?? readName(bytes, records, NAME_ID_FAMILY)
120
+ };
121
+ }
122
+ //#endregion
123
+ exports.parseHead = parseHead;
124
+ exports.parseMaxp = parseMaxp;
125
+ exports.parseName = parseName;
126
+ exports.parseOs2 = parseOs2;
127
+ exports.parsePost = parsePost;
@@ -0,0 +1,43 @@
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
+ //#region src/font-tables.d.ts
3
+ interface HeadTable {
4
+ readonly unitsPerEm: number;
5
+ readonly checkSumAdjustment: number;
6
+ readonly xMin: number;
7
+ readonly yMin: number;
8
+ readonly xMax: number;
9
+ readonly yMax: number;
10
+ readonly indexToLocFormat: 0 | 1;
11
+ }
12
+ declare function parseHead(font: SfntFont): HeadTable | undefined;
13
+ interface MaxpTable {
14
+ readonly numGlyphs: number;
15
+ }
16
+ declare function parseMaxp(font: SfntFont): MaxpTable | undefined;
17
+ interface Os2Table {
18
+ readonly version: number;
19
+ readonly fsSelection: number;
20
+ readonly panose: readonly number[];
21
+ readonly sTypoAscender: number;
22
+ readonly sTypoDescender: number;
23
+ readonly sTypoLineGap: number;
24
+ readonly usWinAscent: number;
25
+ readonly usWinDescent: number;
26
+ readonly sxHeight: number | undefined;
27
+ readonly sCapHeight: number | undefined;
28
+ }
29
+ declare function parseOs2(font: SfntFont): Os2Table | undefined;
30
+ interface PostTable {
31
+ readonly version: number;
32
+ readonly italicAngle: number;
33
+ readonly underlinePosition: number;
34
+ readonly underlineThickness: number;
35
+ }
36
+ declare function parsePost(font: SfntFont): PostTable | undefined;
37
+ interface NameTable {
38
+ readonly postScriptName: string | undefined;
39
+ readonly familyName: string | undefined;
40
+ }
41
+ declare function parseName(font: SfntFont): NameTable | undefined;
42
+ //#endregion
43
+ export { HeadTable, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost };
@@ -0,0 +1,43 @@
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
+ //#region src/font-tables.d.ts
3
+ interface HeadTable {
4
+ readonly unitsPerEm: number;
5
+ readonly checkSumAdjustment: number;
6
+ readonly xMin: number;
7
+ readonly yMin: number;
8
+ readonly xMax: number;
9
+ readonly yMax: number;
10
+ readonly indexToLocFormat: 0 | 1;
11
+ }
12
+ declare function parseHead(font: SfntFont): HeadTable | undefined;
13
+ interface MaxpTable {
14
+ readonly numGlyphs: number;
15
+ }
16
+ declare function parseMaxp(font: SfntFont): MaxpTable | undefined;
17
+ interface Os2Table {
18
+ readonly version: number;
19
+ readonly fsSelection: number;
20
+ readonly panose: readonly number[];
21
+ readonly sTypoAscender: number;
22
+ readonly sTypoDescender: number;
23
+ readonly sTypoLineGap: number;
24
+ readonly usWinAscent: number;
25
+ readonly usWinDescent: number;
26
+ readonly sxHeight: number | undefined;
27
+ readonly sCapHeight: number | undefined;
28
+ }
29
+ declare function parseOs2(font: SfntFont): Os2Table | undefined;
30
+ interface PostTable {
31
+ readonly version: number;
32
+ readonly italicAngle: number;
33
+ readonly underlinePosition: number;
34
+ readonly underlineThickness: number;
35
+ }
36
+ declare function parsePost(font: SfntFont): PostTable | undefined;
37
+ interface NameTable {
38
+ readonly postScriptName: string | undefined;
39
+ readonly familyName: string | undefined;
40
+ }
41
+ declare function parseName(font: SfntFont): NameTable | undefined;
42
+ //#endregion
43
+ export { HeadTable, MaxpTable, NameTable, Os2Table, PostTable, parseHead, parseMaxp, parseName, parseOs2, parsePost };
@@ -0,0 +1,122 @@
1
+ import { hasBytes, i16, i32, sfntTableBytes, u16, u32 } from "./sfnt.js";
2
+ //#region src/font-tables.ts
3
+ const HEAD_TABLE_SIZE = 54;
4
+ const HEAD_MAGIC_NUMBER = 1594834165;
5
+ const MIN_UNITS_PER_EM = 16;
6
+ const MAX_UNITS_PER_EM = 16384;
7
+ function parseHead(font) {
8
+ const bytes = sfntTableBytes(font, "head");
9
+ if (bytes === void 0 || !hasBytes(bytes, 0, HEAD_TABLE_SIZE)) return;
10
+ if (u32(bytes, 12) !== HEAD_MAGIC_NUMBER) return;
11
+ const unitsPerEm = u16(bytes, 18);
12
+ if (unitsPerEm < MIN_UNITS_PER_EM || unitsPerEm > MAX_UNITS_PER_EM) return;
13
+ const indexToLocFormat = i16(bytes, 50);
14
+ if (indexToLocFormat !== 0 && indexToLocFormat !== 1) return;
15
+ return {
16
+ unitsPerEm,
17
+ checkSumAdjustment: u32(bytes, 8),
18
+ xMin: i16(bytes, 36),
19
+ yMin: i16(bytes, 38),
20
+ xMax: i16(bytes, 40),
21
+ yMax: i16(bytes, 42),
22
+ indexToLocFormat
23
+ };
24
+ }
25
+ const MAXP_HEADER_SIZE = 6;
26
+ function parseMaxp(font) {
27
+ const bytes = sfntTableBytes(font, "maxp");
28
+ if (bytes === void 0 || !hasBytes(bytes, 0, MAXP_HEADER_SIZE)) return;
29
+ return { numGlyphs: u16(bytes, 4) };
30
+ }
31
+ const OS2_VERSION_0_SIZE = 78;
32
+ const OS2_VERSION_2_SIZE = 96;
33
+ const OS2_VERSION_WITH_HEIGHTS = 2;
34
+ const OS2_PANOSE_OFFSET = 32;
35
+ function parseOs2(font) {
36
+ const bytes = sfntTableBytes(font, "OS/2");
37
+ if (bytes === void 0 || !hasBytes(bytes, 0, OS2_VERSION_0_SIZE)) return;
38
+ const version = u16(bytes, 0);
39
+ const hasHeights = version >= OS2_VERSION_WITH_HEIGHTS && hasBytes(bytes, 0, OS2_VERSION_2_SIZE);
40
+ return {
41
+ version,
42
+ fsSelection: u16(bytes, 62),
43
+ panose: [...bytes.subarray(OS2_PANOSE_OFFSET, 42)],
44
+ sTypoAscender: i16(bytes, 68),
45
+ sTypoDescender: i16(bytes, 70),
46
+ sTypoLineGap: i16(bytes, 72),
47
+ usWinAscent: u16(bytes, 74),
48
+ usWinDescent: u16(bytes, 76),
49
+ sxHeight: hasHeights ? i16(bytes, 86) : void 0,
50
+ sCapHeight: hasHeights ? i16(bytes, 88) : void 0
51
+ };
52
+ }
53
+ const POST_HEADER_SIZE = 32;
54
+ const FIXED_16_16_SCALE = 65536;
55
+ function parsePost(font) {
56
+ const bytes = sfntTableBytes(font, "post");
57
+ if (bytes === void 0 || !hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
58
+ return {
59
+ version: u32(bytes, 0),
60
+ italicAngle: i32(bytes, 4) / FIXED_16_16_SCALE,
61
+ underlinePosition: i16(bytes, 8),
62
+ underlineThickness: i16(bytes, 10)
63
+ };
64
+ }
65
+ const NAME_HEADER_SIZE = 6;
66
+ const NAME_RECORD_SIZE = 12;
67
+ const NAME_ID_FAMILY = 1;
68
+ const NAME_ID_POSTSCRIPT = 6;
69
+ const NAME_ID_TYPOGRAPHIC_FAMILY = 16;
70
+ const PLATFORM_UNICODE = 0;
71
+ const PLATFORM_MACINTOSH = 1;
72
+ const PLATFORM_WINDOWS = 3;
73
+ const WINDOWS_ENCODING_UNICODE_BMP = 1;
74
+ const MACINTOSH_ENCODING_ROMAN = 0;
75
+ function decodeUtf16Be(bytes, offset, length) {
76
+ let text = "";
77
+ for (let i = 0; i + 1 < length; i += 2) text += String.fromCharCode(bytes[offset + i] << 8 | bytes[offset + i + 1]);
78
+ return text;
79
+ }
80
+ function decodeMacRoman(bytes, offset, length) {
81
+ let text = "";
82
+ for (let i = 0; i < length; i++) text += String.fromCharCode(bytes[offset + i]);
83
+ return text;
84
+ }
85
+ function platformRank(record) {
86
+ if (record.platformId === PLATFORM_WINDOWS && record.encodingId === WINDOWS_ENCODING_UNICODE_BMP) return 0;
87
+ if (record.platformId === PLATFORM_UNICODE) return 1;
88
+ if (record.platformId === PLATFORM_MACINTOSH && record.encodingId === MACINTOSH_ENCODING_ROMAN) return 2;
89
+ return 3;
90
+ }
91
+ function readName(bytes, records, nameId) {
92
+ const matches = records.filter((record) => record.nameId === nameId && platformRank(record) < 3).sort((a, b) => platformRank(a) - platformRank(b));
93
+ for (const record of matches) {
94
+ if (!hasBytes(bytes, record.stringOffset, record.length)) continue;
95
+ const text = record.platformId === PLATFORM_MACINTOSH ? decodeMacRoman(bytes, record.stringOffset, record.length) : decodeUtf16Be(bytes, record.stringOffset, record.length);
96
+ if (text.length > 0) return text;
97
+ }
98
+ }
99
+ function parseName(font) {
100
+ const bytes = sfntTableBytes(font, "name");
101
+ if (bytes === void 0 || !hasBytes(bytes, 0, NAME_HEADER_SIZE)) return;
102
+ const count = u16(bytes, 2);
103
+ const storageOffset = u16(bytes, 4);
104
+ if (!hasBytes(bytes, NAME_HEADER_SIZE, count * NAME_RECORD_SIZE)) return;
105
+ const records = [];
106
+ for (let i = 0; i < count; i++) {
107
+ const recordOffset = NAME_HEADER_SIZE + i * NAME_RECORD_SIZE;
108
+ records.push({
109
+ platformId: u16(bytes, recordOffset),
110
+ encodingId: u16(bytes, recordOffset + 2),
111
+ nameId: u16(bytes, recordOffset + 6),
112
+ length: u16(bytes, recordOffset + 8),
113
+ stringOffset: storageOffset + u16(bytes, recordOffset + 10)
114
+ });
115
+ }
116
+ return {
117
+ postScriptName: readName(bytes, records, NAME_ID_POSTSCRIPT),
118
+ familyName: readName(bytes, records, NAME_ID_TYPOGRAPHIC_FAMILY) ?? readName(bytes, records, NAME_ID_FAMILY)
119
+ };
120
+ }
121
+ //#endregion
122
+ export { parseHead, parseMaxp, parseName, parseOs2, parsePost };
package/dist/fonts.cjs CHANGED
@@ -120,5 +120,6 @@ function resolveStandardFont(family, bold, italic) {
120
120
  };
121
121
  }
122
122
  //#endregion
123
+ exports.normalizeFamilyName = normalizeFamilyName;
123
124
  exports.resolveFontFamily = resolveFontFamily;
124
125
  exports.resolveStandardFont = resolveStandardFont;
package/dist/fonts.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { r as StandardFontName } from "./afm-widths-DyDq56Ph.cjs";
2
2
  //#region src/fonts.d.ts
3
3
  type StandardFamily = 'helvetica' | 'times' | 'courier';
4
+ declare function normalizeFamilyName(raw: string): string;
4
5
  interface FontFamilyResolution {
5
6
  readonly family: StandardFamily;
6
7
  readonly matched: boolean;
@@ -12,4 +13,4 @@ interface ResolvedFont {
12
13
  }
13
14
  declare function resolveStandardFont(family: string, bold: boolean, italic: boolean): ResolvedFont;
14
15
  //#endregion
15
- export { FontFamilyResolution, ResolvedFont, resolveFontFamily, resolveStandardFont };
16
+ export { FontFamilyResolution, ResolvedFont, normalizeFamilyName, resolveFontFamily, resolveStandardFont };
package/dist/fonts.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { r as StandardFontName } from "./afm-widths-DyDq56Ph.js";
2
2
  //#region src/fonts.d.ts
3
3
  type StandardFamily = 'helvetica' | 'times' | 'courier';
4
+ declare function normalizeFamilyName(raw: string): string;
4
5
  interface FontFamilyResolution {
5
6
  readonly family: StandardFamily;
6
7
  readonly matched: boolean;
@@ -12,4 +13,4 @@ interface ResolvedFont {
12
13
  }
13
14
  declare function resolveStandardFont(family: string, bold: boolean, italic: boolean): ResolvedFont;
14
15
  //#endregion
15
- export { FontFamilyResolution, ResolvedFont, resolveFontFamily, resolveStandardFont };
16
+ export { FontFamilyResolution, ResolvedFont, normalizeFamilyName, resolveFontFamily, resolveStandardFont };
package/dist/fonts.js CHANGED
@@ -119,4 +119,4 @@ function resolveStandardFont(family, bold, italic) {
119
119
  };
120
120
  }
121
121
  //#endregion
122
- export { resolveFontFamily, resolveStandardFont };
122
+ export { normalizeFamilyName, resolveFontFamily, resolveStandardFont };