pdf-codec 1.5.0 → 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 (118) hide show
  1. package/README.md +36 -3
  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 +34 -14
  43. package/dist/content-write.d.cts +9 -2
  44. package/dist/content-write.d.ts +9 -2
  45. package/dist/content-write.js +34 -14
  46. package/dist/embedded-font-CLedn-mT.d.cts +42 -0
  47. package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
  48. package/dist/embedded-font-write.cjs +92 -0
  49. package/dist/embedded-font-write.d.cts +22 -0
  50. package/dist/embedded-font-write.d.ts +22 -0
  51. package/dist/embedded-font-write.js +90 -0
  52. package/dist/embedded-font.cjs +142 -0
  53. package/dist/embedded-font.d.cts +2 -0
  54. package/dist/embedded-font.d.ts +2 -0
  55. package/dist/embedded-font.js +138 -0
  56. package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
  57. package/dist/font-registry-yby02snZ.d.cts +38 -0
  58. package/dist/font-registry.cjs +152 -0
  59. package/dist/font-registry.d.cts +2 -0
  60. package/dist/font-registry.d.ts +2 -0
  61. package/dist/font-registry.js +150 -0
  62. package/dist/font-substitutes.cjs +13 -0
  63. package/dist/font-substitutes.d.cts +5 -0
  64. package/dist/font-substitutes.d.ts +5 -0
  65. package/dist/font-substitutes.js +12 -0
  66. package/dist/font-tables.cjs +127 -0
  67. package/dist/font-tables.d.cts +43 -0
  68. package/dist/font-tables.d.ts +43 -0
  69. package/dist/font-tables.js +122 -0
  70. package/dist/fonts.cjs +1 -0
  71. package/dist/fonts.d.cts +2 -1
  72. package/dist/fonts.d.ts +2 -1
  73. package/dist/fonts.js +1 -1
  74. package/dist/glyf.cjs +127 -0
  75. package/dist/glyf.d.cts +31 -0
  76. package/dist/glyf.d.ts +31 -0
  77. package/dist/glyf.js +125 -0
  78. package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
  79. package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
  80. package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
  81. package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
  82. package/dist/index.cjs +5 -0
  83. package/dist/index.d.cts +4 -2
  84. package/dist/index.d.ts +4 -2
  85. package/dist/index.js +3 -2
  86. package/dist/math-font-write.cjs +2 -31
  87. package/dist/math-font-write.js +1 -30
  88. package/dist/math-font.cjs +7 -5
  89. package/dist/math-font.js +5 -3
  90. package/dist/math-table.d.cts +1 -1
  91. package/dist/math-table.d.ts +1 -1
  92. package/dist/measure.cjs +65 -14
  93. package/dist/measure.d.cts +8 -1
  94. package/dist/measure.d.ts +8 -1
  95. package/dist/measure.js +64 -15
  96. package/dist/sfnt-V08bb5ut.d.cts +21 -0
  97. package/dist/sfnt-V08bb5ut.d.ts +21 -0
  98. package/dist/sfnt-subset.cjs +250 -0
  99. package/dist/sfnt-subset.d.cts +11 -0
  100. package/dist/sfnt-subset.d.ts +11 -0
  101. package/dist/sfnt-subset.js +249 -0
  102. package/dist/sfnt.cjs +50 -4
  103. package/dist/sfnt.d.cts +2 -17
  104. package/dist/sfnt.d.ts +2 -17
  105. package/dist/sfnt.js +47 -5
  106. package/dist/tounicode.cjs +34 -0
  107. package/dist/tounicode.d.cts +5 -0
  108. package/dist/tounicode.d.ts +5 -0
  109. package/dist/tounicode.js +33 -0
  110. package/dist/write.cjs +80 -10
  111. package/dist/write.d.cts +6 -0
  112. package/dist/write.d.ts +6 -0
  113. package/dist/write.js +81 -11
  114. package/package.json +1 -1
  115. package/dist/math-cmap.cjs +0 -81
  116. package/dist/math-cmap.d.cts +0 -6
  117. package/dist/math-cmap.d.ts +0 -6
  118. package/dist/math-cmap.js +0 -80
@@ -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 };
package/dist/glyf.cjs ADDED
@@ -0,0 +1,127 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sfnt = require("./sfnt.cjs");
3
+ //#region src/glyf.ts
4
+ const LOCA_SHORT_ENTRY_SIZE = 2;
5
+ const LOCA_LONG_ENTRY_SIZE = 4;
6
+ const LOCA_SHORT_OFFSET_SCALE = 2;
7
+ function parseLoca(font, options) {
8
+ const bytes = require_sfnt.sfntTableBytes(font, "loca");
9
+ if (bytes === void 0) return;
10
+ const entryCount = options.numGlyphs + 1;
11
+ const entrySize = options.indexToLocFormat === 0 ? LOCA_SHORT_ENTRY_SIZE : LOCA_LONG_ENTRY_SIZE;
12
+ if (!require_sfnt.hasBytes(bytes, 0, entryCount * entrySize)) return;
13
+ const offsets = [];
14
+ for (let i = 0; i < entryCount; i++) offsets.push(options.indexToLocFormat === 0 ? require_sfnt.u16(bytes, i * LOCA_SHORT_ENTRY_SIZE) * LOCA_SHORT_OFFSET_SCALE : require_sfnt.u32(bytes, i * LOCA_LONG_ENTRY_SIZE));
15
+ return offsets;
16
+ }
17
+ const GLYPH_HEADER_SIZE = 10;
18
+ const ARG_1_AND_2_ARE_WORDS = 1;
19
+ const ARGS_ARE_XY_VALUES = 2;
20
+ const WE_HAVE_A_SCALE = 8;
21
+ const MORE_COMPONENTS = 32;
22
+ const WE_HAVE_AN_X_AND_Y_SCALE = 64;
23
+ const WE_HAVE_A_TWO_BY_TWO = 128;
24
+ const COMPONENT_RECORD_HEADER_SIZE = 4;
25
+ function signedByte(value) {
26
+ return value >= 128 ? value - 256 : value;
27
+ }
28
+ function readComponents(glyph) {
29
+ const components = [];
30
+ let offset = GLYPH_HEADER_SIZE;
31
+ for (;;) {
32
+ if (!require_sfnt.hasBytes(glyph, offset, COMPONENT_RECORD_HEADER_SIZE)) return;
33
+ const flags = require_sfnt.u16(glyph, offset);
34
+ const glyphIndex = require_sfnt.u16(glyph, offset + 2);
35
+ offset += COMPONENT_RECORD_HEADER_SIZE;
36
+ const argsAreWords = (flags & ARG_1_AND_2_ARE_WORDS) !== 0;
37
+ const argsAreXyValues = (flags & ARGS_ARE_XY_VALUES) !== 0;
38
+ const argsSize = argsAreWords ? 4 : 2;
39
+ if (!require_sfnt.hasBytes(glyph, offset, argsSize)) return;
40
+ let argument1;
41
+ let argument2;
42
+ if (argsAreWords) {
43
+ argument1 = argsAreXyValues ? require_sfnt.i16(glyph, offset) : require_sfnt.u16(glyph, offset);
44
+ argument2 = argsAreXyValues ? require_sfnt.i16(glyph, offset + 2) : require_sfnt.u16(glyph, offset + 2);
45
+ } else {
46
+ argument1 = argsAreXyValues ? signedByte(require_sfnt.u8(glyph, offset)) : require_sfnt.u8(glyph, offset);
47
+ argument2 = argsAreXyValues ? signedByte(require_sfnt.u8(glyph, offset + 1)) : require_sfnt.u8(glyph, offset + 1);
48
+ }
49
+ offset += argsSize;
50
+ let transform;
51
+ if ((flags & WE_HAVE_A_SCALE) !== 0) {
52
+ if (!require_sfnt.hasBytes(glyph, offset, 2)) return;
53
+ const scale = require_sfnt.f2dot14(glyph, offset);
54
+ transform = [
55
+ scale,
56
+ 0,
57
+ 0,
58
+ scale
59
+ ];
60
+ offset += 2;
61
+ } else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) !== 0) {
62
+ if (!require_sfnt.hasBytes(glyph, offset, 4)) return;
63
+ transform = [
64
+ require_sfnt.f2dot14(glyph, offset),
65
+ 0,
66
+ 0,
67
+ require_sfnt.f2dot14(glyph, offset + 2)
68
+ ];
69
+ offset += 4;
70
+ } else if ((flags & WE_HAVE_A_TWO_BY_TWO) !== 0) {
71
+ if (!require_sfnt.hasBytes(glyph, offset, 8)) return;
72
+ transform = [
73
+ require_sfnt.f2dot14(glyph, offset),
74
+ require_sfnt.f2dot14(glyph, offset + 2),
75
+ require_sfnt.f2dot14(glyph, offset + 4),
76
+ require_sfnt.f2dot14(glyph, offset + 6)
77
+ ];
78
+ offset += 8;
79
+ }
80
+ components.push({
81
+ flags,
82
+ glyphIndex,
83
+ argument1,
84
+ argument2,
85
+ argsAreXyValues,
86
+ transform
87
+ });
88
+ if ((flags & MORE_COMPONENTS) === 0) return components;
89
+ }
90
+ }
91
+ function parseGlyf(font, options) {
92
+ const glyfBytes = require_sfnt.sfntTableBytes(font, "glyf");
93
+ const loca = parseLoca(font, options);
94
+ if (glyfBytes === void 0 || loca === void 0) return;
95
+ const glyphBytes = (glyphId) => {
96
+ if (!Number.isInteger(glyphId) || glyphId < 0 || glyphId >= options.numGlyphs) return;
97
+ const start = loca[glyphId];
98
+ const end = loca[glyphId + 1];
99
+ if (end < start || !require_sfnt.hasBytes(glyfBytes, start, end - start)) return;
100
+ return glyfBytes.subarray(start, end);
101
+ };
102
+ const glyphHeader = (glyphId) => {
103
+ const glyph = glyphBytes(glyphId);
104
+ if (glyph === void 0 || !require_sfnt.hasBytes(glyph, 0, GLYPH_HEADER_SIZE)) return;
105
+ return {
106
+ numberOfContours: require_sfnt.i16(glyph, 0),
107
+ xMin: require_sfnt.i16(glyph, 2),
108
+ yMin: require_sfnt.i16(glyph, 4),
109
+ xMax: require_sfnt.i16(glyph, 6),
110
+ yMax: require_sfnt.i16(glyph, 8)
111
+ };
112
+ };
113
+ return {
114
+ numGlyphs: options.numGlyphs,
115
+ glyphBytes,
116
+ glyphHeader,
117
+ compositeComponents(glyphId) {
118
+ const header = glyphHeader(glyphId);
119
+ if (header === void 0 || header.numberOfContours >= 0) return;
120
+ const glyph = glyphBytes(glyphId);
121
+ return glyph === void 0 ? void 0 : readComponents(glyph);
122
+ }
123
+ };
124
+ }
125
+ //#endregion
126
+ exports.parseGlyf = parseGlyf;
127
+ exports.parseLoca = parseLoca;
@@ -0,0 +1,31 @@
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
+ //#region src/glyf.d.ts
3
+ interface GlyphHeader {
4
+ readonly numberOfContours: number;
5
+ readonly xMin: number;
6
+ readonly yMin: number;
7
+ readonly xMax: number;
8
+ readonly yMax: number;
9
+ }
10
+ interface CompositeComponent {
11
+ readonly flags: number;
12
+ readonly glyphIndex: number;
13
+ readonly argument1: number;
14
+ readonly argument2: number;
15
+ readonly argsAreXyValues: boolean;
16
+ readonly transform: readonly [number, number, number, number] | undefined;
17
+ }
18
+ interface GlyfTable {
19
+ readonly numGlyphs: number;
20
+ glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
21
+ glyphHeader(glyphId: number): GlyphHeader | undefined;
22
+ compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
23
+ }
24
+ interface GlyfOptions {
25
+ readonly numGlyphs: number;
26
+ readonly indexToLocFormat: 0 | 1;
27
+ }
28
+ declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
29
+ declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
30
+ //#endregion
31
+ export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };
package/dist/glyf.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
+ //#region src/glyf.d.ts
3
+ interface GlyphHeader {
4
+ readonly numberOfContours: number;
5
+ readonly xMin: number;
6
+ readonly yMin: number;
7
+ readonly xMax: number;
8
+ readonly yMax: number;
9
+ }
10
+ interface CompositeComponent {
11
+ readonly flags: number;
12
+ readonly glyphIndex: number;
13
+ readonly argument1: number;
14
+ readonly argument2: number;
15
+ readonly argsAreXyValues: boolean;
16
+ readonly transform: readonly [number, number, number, number] | undefined;
17
+ }
18
+ interface GlyfTable {
19
+ readonly numGlyphs: number;
20
+ glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
21
+ glyphHeader(glyphId: number): GlyphHeader | undefined;
22
+ compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
23
+ }
24
+ interface GlyfOptions {
25
+ readonly numGlyphs: number;
26
+ readonly indexToLocFormat: 0 | 1;
27
+ }
28
+ declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
29
+ declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
30
+ //#endregion
31
+ export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };