pdf-codec 1.5.0 → 1.7.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 (214) hide show
  1. package/README.md +100 -9
  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-bounds.cjs +432 -0
  35. package/dist/cff-bounds.d.cts +9 -0
  36. package/dist/cff-bounds.d.ts +9 -0
  37. package/dist/cff-bounds.js +431 -0
  38. package/dist/cff-probe.cjs +35 -0
  39. package/dist/cff-probe.d.cts +10 -0
  40. package/dist/cff-probe.d.ts +10 -0
  41. package/dist/cff-probe.js +34 -0
  42. package/dist/cff.cjs +158 -0
  43. package/dist/cff.d.cts +17 -0
  44. package/dist/cff.d.ts +17 -0
  45. package/dist/cff.js +150 -0
  46. package/dist/cmap-table.cjs +108 -0
  47. package/dist/cmap-table.d.cts +6 -0
  48. package/dist/cmap-table.d.ts +6 -0
  49. package/dist/cmap-table.js +107 -0
  50. package/dist/content-write.cjs +34 -14
  51. package/dist/content-write.d.cts +9 -2
  52. package/dist/content-write.d.ts +9 -2
  53. package/dist/content-write.js +34 -14
  54. package/dist/embedded-font-CLedn-mT.d.cts +42 -0
  55. package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
  56. package/dist/embedded-font-write.cjs +92 -0
  57. package/dist/embedded-font-write.d.cts +22 -0
  58. package/dist/embedded-font-write.d.ts +22 -0
  59. package/dist/embedded-font-write.js +90 -0
  60. package/dist/embedded-font.cjs +142 -0
  61. package/dist/embedded-font.d.cts +2 -0
  62. package/dist/embedded-font.d.ts +2 -0
  63. package/dist/embedded-font.js +138 -0
  64. package/dist/filters.cjs +45 -2
  65. package/dist/filters.d.cts +4 -3
  66. package/dist/filters.d.ts +4 -3
  67. package/dist/filters.js +45 -2
  68. package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
  69. package/dist/font-registry-yby02snZ.d.cts +38 -0
  70. package/dist/font-registry.cjs +152 -0
  71. package/dist/font-registry.d.cts +2 -0
  72. package/dist/font-registry.d.ts +2 -0
  73. package/dist/font-registry.js +150 -0
  74. package/dist/font-substitutes.cjs +13 -0
  75. package/dist/font-substitutes.d.cts +5 -0
  76. package/dist/font-substitutes.d.ts +5 -0
  77. package/dist/font-substitutes.js +12 -0
  78. package/dist/font-tables.cjs +127 -0
  79. package/dist/font-tables.d.cts +43 -0
  80. package/dist/font-tables.d.ts +43 -0
  81. package/dist/font-tables.js +122 -0
  82. package/dist/fonts.cjs +1 -0
  83. package/dist/fonts.d.cts +2 -1
  84. package/dist/fonts.d.ts +2 -1
  85. package/dist/fonts.js +1 -1
  86. package/dist/formula.d.cts +1 -1
  87. package/dist/formula.d.ts +1 -1
  88. package/dist/glyf.cjs +183 -0
  89. package/dist/glyf.d.cts +33 -0
  90. package/dist/glyf.d.ts +33 -0
  91. package/dist/glyf.js +181 -0
  92. package/dist/glyph-bounds-BV_Z40KS.d.cts +10 -0
  93. package/dist/glyph-bounds-BV_Z40KS.d.ts +10 -0
  94. package/dist/glyph-bounds.cjs +12 -0
  95. package/dist/glyph-bounds.d.cts +2 -0
  96. package/dist/glyph-bounds.d.ts +2 -0
  97. package/dist/glyph-bounds.js +11 -0
  98. package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
  99. package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
  100. package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
  101. package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
  102. package/dist/image/jbig2-arith.cjs +432 -0
  103. package/dist/image/jbig2-arith.d.cts +23 -0
  104. package/dist/image/jbig2-arith.d.ts +23 -0
  105. package/dist/image/jbig2-arith.js +426 -0
  106. package/dist/image/jbig2-bitmap.cjs +80 -0
  107. package/dist/image/jbig2-bitmap.d.cts +20 -0
  108. package/dist/image/jbig2-bitmap.d.ts +20 -0
  109. package/dist/image/jbig2-bitmap.js +72 -0
  110. package/dist/image/jbig2-errors.cjs +17 -0
  111. package/dist/image/jbig2-errors.d.cts +2 -0
  112. package/dist/image/jbig2-errors.d.ts +2 -0
  113. package/dist/image/jbig2-errors.js +15 -0
  114. package/dist/image/jbig2-generic.cjs +242 -0
  115. package/dist/image/jbig2-generic.d.cts +27 -0
  116. package/dist/image/jbig2-generic.d.ts +27 -0
  117. package/dist/image/jbig2-generic.js +237 -0
  118. package/dist/image/jbig2-text.cjs +175 -0
  119. package/dist/image/jbig2-text.d.cts +58 -0
  120. package/dist/image/jbig2-text.d.ts +58 -0
  121. package/dist/image/jbig2-text.js +170 -0
  122. package/dist/image/jbig2.cjs +333 -0
  123. package/dist/image/jbig2.d.cts +15 -0
  124. package/dist/image/jbig2.d.ts +15 -0
  125. package/dist/image/jbig2.js +332 -0
  126. package/dist/image/jp2-boxes.cjs +148 -0
  127. package/dist/image/jp2-boxes.d.cts +26 -0
  128. package/dist/image/jp2-boxes.d.ts +26 -0
  129. package/dist/image/jp2-boxes.js +146 -0
  130. package/dist/image/jpeg2000-codestream.cjs +309 -0
  131. package/dist/image/jpeg2000-codestream.d.cts +78 -0
  132. package/dist/image/jpeg2000-codestream.d.ts +78 -0
  133. package/dist/image/jpeg2000-codestream.js +308 -0
  134. package/dist/image/jpeg2000-dwt.cjs +148 -0
  135. package/dist/image/jpeg2000-dwt.d.cts +34 -0
  136. package/dist/image/jpeg2000-dwt.d.ts +34 -0
  137. package/dist/image/jpeg2000-dwt.js +145 -0
  138. package/dist/image/jpeg2000-errors.cjs +17 -0
  139. package/dist/image/jpeg2000-errors.d.cts +9 -0
  140. package/dist/image/jpeg2000-errors.d.ts +9 -0
  141. package/dist/image/jpeg2000-errors.js +15 -0
  142. package/dist/image/jpeg2000-t1.cjs +254 -0
  143. package/dist/image/jpeg2000-t1.d.cts +18 -0
  144. package/dist/image/jpeg2000-t1.d.ts +18 -0
  145. package/dist/image/jpeg2000-t1.js +253 -0
  146. package/dist/image/jpeg2000-t2.cjs +316 -0
  147. package/dist/image/jpeg2000-t2.d.cts +79 -0
  148. package/dist/image/jpeg2000-t2.d.ts +79 -0
  149. package/dist/image/jpeg2000-t2.js +311 -0
  150. package/dist/image/jpeg2000-tagtree.cjs +105 -0
  151. package/dist/image/jpeg2000-tagtree.d.cts +29 -0
  152. package/dist/image/jpeg2000-tagtree.d.ts +29 -0
  153. package/dist/image/jpeg2000-tagtree.js +103 -0
  154. package/dist/image/jpeg2000.cjs +322 -0
  155. package/dist/image/jpeg2000.d.cts +54 -0
  156. package/dist/image/jpeg2000.d.ts +54 -0
  157. package/dist/image/jpeg2000.js +320 -0
  158. package/dist/images-read.cjs +78 -1
  159. package/dist/images-read.js +78 -1
  160. package/dist/index.cjs +22 -0
  161. package/dist/index.d.cts +14 -3
  162. package/dist/index.d.ts +14 -3
  163. package/dist/index.js +9 -2
  164. package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
  165. package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
  166. package/dist/math-font-write.cjs +2 -31
  167. package/dist/math-font-write.js +1 -30
  168. package/dist/math-font.cjs +50 -23
  169. package/dist/math-font.d.cts +8 -1
  170. package/dist/math-font.d.ts +8 -1
  171. package/dist/math-font.js +48 -21
  172. package/dist/math-stretch-Bwk_bxh1.d.ts +24 -0
  173. package/dist/math-stretch-DXWjs8gL.d.cts +24 -0
  174. package/dist/math-stretch.cjs +96 -0
  175. package/dist/math-stretch.d.cts +2 -0
  176. package/dist/math-stretch.d.ts +2 -0
  177. package/dist/math-stretch.js +94 -0
  178. package/dist/math-table-DhPrNoPa.d.ts +70 -0
  179. package/dist/math-table-gFNB8DmQ.d.cts +70 -0
  180. package/dist/math-table.cjs +69 -1
  181. package/dist/math-table.d.cts +2 -45
  182. package/dist/math-table.d.ts +2 -45
  183. package/dist/math-table.js +69 -1
  184. package/dist/{math-types-Ba8qAf1p.d.cts → math-types-YSQUTviw.d.cts} +2 -0
  185. package/dist/{math-types-Ba8qAf1p.d.ts → math-types-YSQUTviw.d.ts} +2 -0
  186. package/dist/math-types.d.cts +1 -1
  187. package/dist/math-types.d.ts +1 -1
  188. package/dist/measure.cjs +65 -14
  189. package/dist/measure.d.cts +8 -1
  190. package/dist/measure.d.ts +8 -1
  191. package/dist/measure.js +64 -15
  192. package/dist/sfnt-V08bb5ut.d.cts +21 -0
  193. package/dist/sfnt-V08bb5ut.d.ts +21 -0
  194. package/dist/sfnt-subset.cjs +250 -0
  195. package/dist/sfnt-subset.d.cts +11 -0
  196. package/dist/sfnt-subset.d.ts +11 -0
  197. package/dist/sfnt-subset.js +249 -0
  198. package/dist/sfnt.cjs +50 -4
  199. package/dist/sfnt.d.cts +2 -17
  200. package/dist/sfnt.d.ts +2 -17
  201. package/dist/sfnt.js +47 -5
  202. package/dist/tounicode.cjs +34 -0
  203. package/dist/tounicode.d.cts +5 -0
  204. package/dist/tounicode.d.ts +5 -0
  205. package/dist/tounicode.js +33 -0
  206. package/dist/write.cjs +80 -10
  207. package/dist/write.d.cts +6 -0
  208. package/dist/write.d.ts +6 -0
  209. package/dist/write.js +81 -11
  210. package/package.json +1 -1
  211. package/dist/math-cmap.cjs +0 -81
  212. package/dist/math-cmap.d.cts +0 -6
  213. package/dist/math-cmap.d.ts +0 -6
  214. package/dist/math-cmap.js +0 -80
package/dist/cff.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ //#region src/cff.d.ts
2
+ interface CffIndex {
3
+ readonly count: number;
4
+ readonly endOffset: number;
5
+ entry(index: number): Uint8Array<ArrayBuffer> | undefined;
6
+ }
7
+ type CffDict = ReadonlyMap<number, readonly number[]>;
8
+ declare const CFF_ESCAPED_OPERATOR_BASE = 1200;
9
+ declare const CFF_DICT_OP_CHARSET = 15;
10
+ declare const CFF_DICT_OP_CHARSTRINGS = 17;
11
+ declare const CFF_DICT_OP_PRIVATE = 18;
12
+ declare const CFF_DICT_OP_SUBRS = 19;
13
+ declare const CFF_DICT_OP_ROS: number;
14
+ declare function readCffIndex(bytes: Uint8Array<ArrayBuffer>, offset: number): CffIndex | undefined;
15
+ declare function parseCffDict(data: Uint8Array<ArrayBuffer>): CffDict | undefined;
16
+ //#endregion
17
+ export { CFF_DICT_OP_CHARSET, CFF_DICT_OP_CHARSTRINGS, CFF_DICT_OP_PRIVATE, CFF_DICT_OP_ROS, CFF_DICT_OP_SUBRS, CFF_ESCAPED_OPERATOR_BASE, CffDict, CffIndex, parseCffDict, readCffIndex };
package/dist/cff.js ADDED
@@ -0,0 +1,150 @@
1
+ import { hasBytes, u16, u24, u32, u8 } from "./sfnt.js";
2
+ //#region src/cff.ts
3
+ const CFF_ESCAPED_OPERATOR_BASE = 1200;
4
+ const CFF_DICT_OP_CHARSET = 15;
5
+ const CFF_DICT_OP_CHARSTRINGS = 17;
6
+ const CFF_DICT_OP_PRIVATE = 18;
7
+ const CFF_DICT_OP_SUBRS = 19;
8
+ const CFF_DICT_OP_ROS = 1230;
9
+ const INDEX_COUNT_SIZE = 2;
10
+ const INDEX_OFF_SIZE_SIZE = 1;
11
+ const MIN_OFF_SIZE = 1;
12
+ const MAX_OFF_SIZE = 4;
13
+ const DICT_OPERATOR_MAX = 21;
14
+ const DICT_OPERATOR_ESCAPE = 12;
15
+ const DICT_OPERAND_INT16 = 28;
16
+ const DICT_OPERAND_INT32 = 29;
17
+ const DICT_OPERAND_REAL = 30;
18
+ const DICT_OPERAND_SMALL_FIRST = 32;
19
+ const DICT_OPERAND_SMALL_LAST = 246;
20
+ const DICT_OPERAND_MEDIUM_FIRST = 247;
21
+ const DICT_OPERAND_MEDIUM_LAST = 250;
22
+ const DICT_OPERAND_NEGATIVE_MEDIUM_FIRST = 251;
23
+ const DICT_OPERAND_NEGATIVE_MEDIUM_LAST = 254;
24
+ const DICT_OPERAND_SMALL_BIAS = 139;
25
+ const DICT_OPERAND_MEDIUM_BIAS = 108;
26
+ const DICT_OPERAND_MEDIUM_FIRST_BYTE_BIAS = 247;
27
+ const DICT_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS = 251;
28
+ const BYTE_RADIX = 256;
29
+ const REAL_NIBBLE_DECIMAL_POINT = 10;
30
+ const REAL_NIBBLE_EXPONENT = 11;
31
+ const REAL_NIBBLE_NEGATIVE_EXPONENT = 12;
32
+ const REAL_NIBBLE_RESERVED = 13;
33
+ const REAL_NIBBLE_MINUS = 14;
34
+ const REAL_NIBBLE_TERMINATOR = 15;
35
+ const NIBBLES_PER_BYTE = 2;
36
+ const HIGH_NIBBLE_SHIFT = 4;
37
+ const LOW_NIBBLE_MASK = 15;
38
+ function readOffsetAt(bytes, offset, offSize) {
39
+ if (offSize === 1) return u8(bytes, offset);
40
+ if (offSize === 2) return u16(bytes, offset);
41
+ if (offSize === 3) return u24(bytes, offset);
42
+ return u32(bytes, offset);
43
+ }
44
+ function readCffIndex(bytes, offset) {
45
+ if (!hasBytes(bytes, offset, INDEX_COUNT_SIZE)) return;
46
+ const count = u16(bytes, offset);
47
+ if (count === 0) return {
48
+ count: 0,
49
+ endOffset: offset + INDEX_COUNT_SIZE,
50
+ entry: () => void 0
51
+ };
52
+ if (!hasBytes(bytes, offset + INDEX_COUNT_SIZE, INDEX_OFF_SIZE_SIZE)) return;
53
+ const offSize = u8(bytes, offset + INDEX_COUNT_SIZE);
54
+ if (offSize < MIN_OFF_SIZE || offSize > MAX_OFF_SIZE) return;
55
+ const offsetArrayStart = offset + INDEX_COUNT_SIZE + INDEX_OFF_SIZE_SIZE;
56
+ const offsetArrayLength = (count + 1) * offSize;
57
+ if (!hasBytes(bytes, offsetArrayStart, offsetArrayLength)) return;
58
+ const offsets = [];
59
+ for (let i = 0; i <= count; i++) offsets.push(readOffsetAt(bytes, offsetArrayStart + i * offSize, offSize));
60
+ if (offsets[0] !== 1) return;
61
+ for (let i = 1; i <= count; i++) if (offsets[i] < offsets[i - 1]) return;
62
+ const dataOrigin = offsetArrayStart + offsetArrayLength - 1;
63
+ const dataLength = offsets[count] - 1;
64
+ if (!hasBytes(bytes, dataOrigin + 1, dataLength)) return;
65
+ return {
66
+ count,
67
+ endOffset: dataOrigin + 1 + dataLength,
68
+ entry: (index) => index < 0 || index >= count ? void 0 : bytes.subarray(dataOrigin + offsets[index], dataOrigin + offsets[index + 1])
69
+ };
70
+ }
71
+ function readRealOperand(data, start) {
72
+ let text = "";
73
+ for (let i = start; i < data.length; i++) {
74
+ const byte = data[i];
75
+ for (let n = 0; n < NIBBLES_PER_BYTE; n++) {
76
+ const nibble = n === 0 ? byte >> HIGH_NIBBLE_SHIFT : byte & LOW_NIBBLE_MASK;
77
+ if (nibble === REAL_NIBBLE_TERMINATOR) return {
78
+ value: Number(text),
79
+ endOffset: i + 1
80
+ };
81
+ if (nibble === REAL_NIBBLE_RESERVED) return;
82
+ if (nibble <= 9) text += String(nibble);
83
+ else if (nibble === REAL_NIBBLE_DECIMAL_POINT) text += ".";
84
+ else if (nibble === REAL_NIBBLE_EXPONENT) text += "E";
85
+ else if (nibble === REAL_NIBBLE_NEGATIVE_EXPONENT) text += "E-";
86
+ else if (nibble === REAL_NIBBLE_MINUS) text += "-";
87
+ }
88
+ }
89
+ }
90
+ function parseCffDict(data) {
91
+ const dict = /* @__PURE__ */ new Map();
92
+ let operands = [];
93
+ let i = 0;
94
+ while (i < data.length) {
95
+ const b0 = data[i];
96
+ if (b0 <= DICT_OPERATOR_MAX) {
97
+ let operator = b0;
98
+ i += 1;
99
+ if (b0 === DICT_OPERATOR_ESCAPE) {
100
+ if (i >= data.length) return;
101
+ operator = CFF_ESCAPED_OPERATOR_BASE + data[i];
102
+ i += 1;
103
+ }
104
+ dict.set(operator, operands);
105
+ operands = [];
106
+ continue;
107
+ }
108
+ if (b0 === DICT_OPERAND_INT16) {
109
+ if (!hasBytes(data, i + 1, 2)) return;
110
+ const raw = u16(data, i + 1);
111
+ operands.push(raw >= 32768 ? raw - 65536 : raw);
112
+ i += 3;
113
+ continue;
114
+ }
115
+ if (b0 === DICT_OPERAND_INT32) {
116
+ if (!hasBytes(data, i + 1, 4)) return;
117
+ operands.push(u32(data, i + 1) | 0);
118
+ i += 5;
119
+ continue;
120
+ }
121
+ if (b0 === DICT_OPERAND_REAL) {
122
+ const real = readRealOperand(data, i + 1);
123
+ if (real === void 0) return;
124
+ operands.push(real.value);
125
+ i = real.endOffset;
126
+ continue;
127
+ }
128
+ if (b0 >= DICT_OPERAND_SMALL_FIRST && b0 <= DICT_OPERAND_SMALL_LAST) {
129
+ operands.push(b0 - DICT_OPERAND_SMALL_BIAS);
130
+ i += 1;
131
+ continue;
132
+ }
133
+ if (b0 >= DICT_OPERAND_MEDIUM_FIRST && b0 <= DICT_OPERAND_MEDIUM_LAST) {
134
+ if (!hasBytes(data, i + 1, 1)) return;
135
+ operands.push((b0 - DICT_OPERAND_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX + u8(data, i + 1) + DICT_OPERAND_MEDIUM_BIAS);
136
+ i += 2;
137
+ continue;
138
+ }
139
+ if (b0 >= DICT_OPERAND_NEGATIVE_MEDIUM_FIRST && b0 <= DICT_OPERAND_NEGATIVE_MEDIUM_LAST) {
140
+ if (!hasBytes(data, i + 1, 1)) return;
141
+ operands.push(-(b0 - DICT_OPERAND_NEGATIVE_MEDIUM_FIRST_BYTE_BIAS) * BYTE_RADIX - u8(data, i + 1) - DICT_OPERAND_MEDIUM_BIAS);
142
+ i += 2;
143
+ continue;
144
+ }
145
+ return;
146
+ }
147
+ return dict;
148
+ }
149
+ //#endregion
150
+ export { CFF_DICT_OP_CHARSET, CFF_DICT_OP_CHARSTRINGS, CFF_DICT_OP_PRIVATE, CFF_DICT_OP_ROS, CFF_DICT_OP_SUBRS, CFF_ESCAPED_OPERATOR_BASE, parseCffDict, readCffIndex };
@@ -0,0 +1,108 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sfnt = require("./sfnt.cjs");
3
+ //#region src/cmap-table.ts
4
+ const CMAP_HEADER_SIZE = 4;
5
+ const SUBTABLE_RECORD_SIZE = 8;
6
+ const FORMAT_4_HEADER_SIZE = 14;
7
+ function parseFormat4(bytes, subtableOffset) {
8
+ if (!require_sfnt.hasBytes(bytes, subtableOffset, FORMAT_4_HEADER_SIZE)) return;
9
+ const segCountX2 = require_sfnt.u16(bytes, subtableOffset + 6);
10
+ if (segCountX2 === 0 || segCountX2 % 2 !== 0) return;
11
+ const segCount = segCountX2 / 2;
12
+ const endCodesOffset = subtableOffset + FORMAT_4_HEADER_SIZE;
13
+ const startCodesOffset = endCodesOffset + segCountX2 + 2;
14
+ const idDeltasOffset = startCodesOffset + segCountX2;
15
+ const idRangeOffsetsOffset = idDeltasOffset + segCountX2;
16
+ if (!require_sfnt.hasBytes(bytes, endCodesOffset, segCountX2 * 4 + 2)) return;
17
+ const segments = [];
18
+ for (let i = 0; i < segCount; i++) {
19
+ const idRangeOffsetPos = idRangeOffsetsOffset + i * 2;
20
+ const rawDelta = require_sfnt.u16(bytes, idDeltasOffset + i * 2);
21
+ segments.push({
22
+ endCode: require_sfnt.u16(bytes, endCodesOffset + i * 2),
23
+ startCode: require_sfnt.u16(bytes, startCodesOffset + i * 2),
24
+ idDelta: rawDelta >= 32768 ? rawDelta - 65536 : rawDelta,
25
+ idRangeOffsetPos,
26
+ idRangeOffset: require_sfnt.u16(bytes, idRangeOffsetPos)
27
+ });
28
+ }
29
+ return (codePoint) => {
30
+ if (codePoint > 65535) return;
31
+ for (const segment of segments) {
32
+ if (codePoint < segment.startCode || codePoint > segment.endCode) continue;
33
+ if (segment.idRangeOffset === 0) return codePoint + segment.idDelta & 65535;
34
+ const glyphIndexAddress = segment.idRangeOffsetPos + segment.idRangeOffset + (codePoint - segment.startCode) * 2;
35
+ if (!require_sfnt.hasBytes(bytes, glyphIndexAddress, 2)) return;
36
+ const glyphId = require_sfnt.u16(bytes, glyphIndexAddress);
37
+ return glyphId === 0 ? void 0 : glyphId + segment.idDelta & 65535;
38
+ }
39
+ };
40
+ }
41
+ const FORMAT_12_HEADER_SIZE = 16;
42
+ const FORMAT_12_GROUP_SIZE = 12;
43
+ function parseFormat12(bytes, subtableOffset) {
44
+ if (!require_sfnt.hasBytes(bytes, subtableOffset, FORMAT_12_HEADER_SIZE)) return;
45
+ const numGroups = require_sfnt.u32(bytes, subtableOffset + 12);
46
+ const groupsOffset = subtableOffset + FORMAT_12_HEADER_SIZE;
47
+ if (!require_sfnt.hasBytes(bytes, groupsOffset, numGroups * FORMAT_12_GROUP_SIZE)) return;
48
+ const groups = [];
49
+ for (let i = 0; i < numGroups; i++) {
50
+ const recordOffset = groupsOffset + i * FORMAT_12_GROUP_SIZE;
51
+ groups.push({
52
+ startCharCode: require_sfnt.u32(bytes, recordOffset),
53
+ endCharCode: require_sfnt.u32(bytes, recordOffset + 4),
54
+ startGlyphId: require_sfnt.u32(bytes, recordOffset + 8)
55
+ });
56
+ }
57
+ return (codePoint) => {
58
+ for (const group of groups) if (codePoint >= group.startCharCode && codePoint <= group.endCharCode) return group.startGlyphId + (codePoint - group.startCharCode);
59
+ };
60
+ }
61
+ const FORMAT_6_HEADER_SIZE = 10;
62
+ function parseFormat6(bytes, subtableOffset) {
63
+ if (!require_sfnt.hasBytes(bytes, subtableOffset, FORMAT_6_HEADER_SIZE)) return;
64
+ const firstCode = require_sfnt.u16(bytes, subtableOffset + 6);
65
+ const entryCount = require_sfnt.u16(bytes, subtableOffset + 8);
66
+ const glyphIdArrayOffset = subtableOffset + FORMAT_6_HEADER_SIZE;
67
+ if (!require_sfnt.hasBytes(bytes, glyphIdArrayOffset, entryCount * 2)) return;
68
+ return (codePoint) => {
69
+ const index = codePoint - firstCode;
70
+ if (index < 0 || index >= entryCount) return;
71
+ const glyphId = require_sfnt.u16(bytes, glyphIdArrayOffset + index * 2);
72
+ return glyphId === 0 ? void 0 : glyphId;
73
+ };
74
+ }
75
+ function preferenceRank(subtable) {
76
+ if (subtable.format === 12) {
77
+ if (subtable.platformId === 3 && subtable.encodingId === 10) return 0;
78
+ if (subtable.platformId === 0) return 1;
79
+ return 2;
80
+ }
81
+ if (subtable.format === 4) return subtable.platformId === 3 && subtable.encodingId === 1 ? 3 : 4;
82
+ return 5;
83
+ }
84
+ function buildCmapLookup(font) {
85
+ const cmapBytes = require_sfnt.sfntTableBytes(font, "cmap");
86
+ if (cmapBytes === void 0 || !require_sfnt.hasBytes(cmapBytes, 0, CMAP_HEADER_SIZE)) return;
87
+ const numTables = require_sfnt.u16(cmapBytes, 2);
88
+ if (!require_sfnt.hasBytes(cmapBytes, CMAP_HEADER_SIZE, numTables * SUBTABLE_RECORD_SIZE)) return;
89
+ const subtables = [];
90
+ for (let i = 0; i < numTables; i++) {
91
+ const recordOffset = CMAP_HEADER_SIZE + i * SUBTABLE_RECORD_SIZE;
92
+ const offset = require_sfnt.u32(cmapBytes, recordOffset + 4);
93
+ if (!require_sfnt.hasBytes(cmapBytes, offset, 2)) continue;
94
+ subtables.push({
95
+ platformId: require_sfnt.u16(cmapBytes, recordOffset),
96
+ encodingId: require_sfnt.u16(cmapBytes, recordOffset + 2),
97
+ offset,
98
+ format: require_sfnt.u16(cmapBytes, offset)
99
+ });
100
+ }
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
+ }
106
+ }
107
+ //#endregion
108
+ exports.buildCmapLookup = buildCmapLookup;
@@ -0,0 +1,6 @@
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
2
+ //#region src/cmap-table.d.ts
3
+ type CmapLookup = (codePoint: number) => number | undefined;
4
+ declare function buildCmapLookup(font: SfntFont): CmapLookup | undefined;
5
+ //#endregion
6
+ export { CmapLookup, buildCmapLookup };
@@ -0,0 +1,6 @@
1
+ import { t as SfntFont } from "./sfnt-V08bb5ut.js";
2
+ //#region src/cmap-table.d.ts
3
+ type CmapLookup = (codePoint: number) => number | undefined;
4
+ declare function buildCmapLookup(font: SfntFont): CmapLookup | undefined;
5
+ //#endregion
6
+ export { CmapLookup, buildCmapLookup };
@@ -0,0 +1,107 @@
1
+ import { hasBytes, sfntTableBytes, u16, u32 } from "./sfnt.js";
2
+ //#region src/cmap-table.ts
3
+ const CMAP_HEADER_SIZE = 4;
4
+ const SUBTABLE_RECORD_SIZE = 8;
5
+ const FORMAT_4_HEADER_SIZE = 14;
6
+ function parseFormat4(bytes, subtableOffset) {
7
+ if (!hasBytes(bytes, subtableOffset, FORMAT_4_HEADER_SIZE)) return;
8
+ const segCountX2 = u16(bytes, subtableOffset + 6);
9
+ if (segCountX2 === 0 || segCountX2 % 2 !== 0) return;
10
+ const segCount = segCountX2 / 2;
11
+ const endCodesOffset = subtableOffset + FORMAT_4_HEADER_SIZE;
12
+ const startCodesOffset = endCodesOffset + segCountX2 + 2;
13
+ const idDeltasOffset = startCodesOffset + segCountX2;
14
+ const idRangeOffsetsOffset = idDeltasOffset + segCountX2;
15
+ if (!hasBytes(bytes, endCodesOffset, segCountX2 * 4 + 2)) return;
16
+ const segments = [];
17
+ for (let i = 0; i < segCount; i++) {
18
+ const idRangeOffsetPos = idRangeOffsetsOffset + i * 2;
19
+ const rawDelta = u16(bytes, idDeltasOffset + i * 2);
20
+ segments.push({
21
+ endCode: u16(bytes, endCodesOffset + i * 2),
22
+ startCode: u16(bytes, startCodesOffset + i * 2),
23
+ idDelta: rawDelta >= 32768 ? rawDelta - 65536 : rawDelta,
24
+ idRangeOffsetPos,
25
+ idRangeOffset: u16(bytes, idRangeOffsetPos)
26
+ });
27
+ }
28
+ return (codePoint) => {
29
+ if (codePoint > 65535) return;
30
+ for (const segment of segments) {
31
+ if (codePoint < segment.startCode || codePoint > segment.endCode) continue;
32
+ if (segment.idRangeOffset === 0) return codePoint + segment.idDelta & 65535;
33
+ const glyphIndexAddress = segment.idRangeOffsetPos + segment.idRangeOffset + (codePoint - segment.startCode) * 2;
34
+ if (!hasBytes(bytes, glyphIndexAddress, 2)) return;
35
+ const glyphId = u16(bytes, glyphIndexAddress);
36
+ return glyphId === 0 ? void 0 : glyphId + segment.idDelta & 65535;
37
+ }
38
+ };
39
+ }
40
+ const FORMAT_12_HEADER_SIZE = 16;
41
+ const FORMAT_12_GROUP_SIZE = 12;
42
+ function parseFormat12(bytes, subtableOffset) {
43
+ if (!hasBytes(bytes, subtableOffset, FORMAT_12_HEADER_SIZE)) return;
44
+ const numGroups = u32(bytes, subtableOffset + 12);
45
+ const groupsOffset = subtableOffset + FORMAT_12_HEADER_SIZE;
46
+ if (!hasBytes(bytes, groupsOffset, numGroups * FORMAT_12_GROUP_SIZE)) return;
47
+ const groups = [];
48
+ for (let i = 0; i < numGroups; i++) {
49
+ const recordOffset = groupsOffset + i * FORMAT_12_GROUP_SIZE;
50
+ groups.push({
51
+ startCharCode: u32(bytes, recordOffset),
52
+ endCharCode: u32(bytes, recordOffset + 4),
53
+ startGlyphId: u32(bytes, recordOffset + 8)
54
+ });
55
+ }
56
+ return (codePoint) => {
57
+ for (const group of groups) if (codePoint >= group.startCharCode && codePoint <= group.endCharCode) return group.startGlyphId + (codePoint - group.startCharCode);
58
+ };
59
+ }
60
+ const FORMAT_6_HEADER_SIZE = 10;
61
+ function parseFormat6(bytes, subtableOffset) {
62
+ if (!hasBytes(bytes, subtableOffset, FORMAT_6_HEADER_SIZE)) return;
63
+ const firstCode = u16(bytes, subtableOffset + 6);
64
+ const entryCount = u16(bytes, subtableOffset + 8);
65
+ const glyphIdArrayOffset = subtableOffset + FORMAT_6_HEADER_SIZE;
66
+ if (!hasBytes(bytes, glyphIdArrayOffset, entryCount * 2)) return;
67
+ return (codePoint) => {
68
+ const index = codePoint - firstCode;
69
+ if (index < 0 || index >= entryCount) return;
70
+ const glyphId = u16(bytes, glyphIdArrayOffset + index * 2);
71
+ return glyphId === 0 ? void 0 : glyphId;
72
+ };
73
+ }
74
+ function preferenceRank(subtable) {
75
+ if (subtable.format === 12) {
76
+ if (subtable.platformId === 3 && subtable.encodingId === 10) return 0;
77
+ if (subtable.platformId === 0) return 1;
78
+ return 2;
79
+ }
80
+ if (subtable.format === 4) return subtable.platformId === 3 && subtable.encodingId === 1 ? 3 : 4;
81
+ return 5;
82
+ }
83
+ function buildCmapLookup(font) {
84
+ const cmapBytes = sfntTableBytes(font, "cmap");
85
+ if (cmapBytes === void 0 || !hasBytes(cmapBytes, 0, CMAP_HEADER_SIZE)) return;
86
+ const numTables = u16(cmapBytes, 2);
87
+ if (!hasBytes(cmapBytes, CMAP_HEADER_SIZE, numTables * SUBTABLE_RECORD_SIZE)) return;
88
+ const subtables = [];
89
+ for (let i = 0; i < numTables; i++) {
90
+ const recordOffset = CMAP_HEADER_SIZE + i * SUBTABLE_RECORD_SIZE;
91
+ const offset = u32(cmapBytes, recordOffset + 4);
92
+ if (!hasBytes(cmapBytes, offset, 2)) continue;
93
+ subtables.push({
94
+ platformId: u16(cmapBytes, recordOffset),
95
+ encodingId: u16(cmapBytes, recordOffset + 2),
96
+ offset,
97
+ format: u16(cmapBytes, offset)
98
+ });
99
+ }
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
+ }
105
+ }
106
+ //#endregion
107
+ export { buildCmapLookup };
@@ -3,8 +3,11 @@ const require_afm_widths = require("./afm-widths-BoeTOK2r.cjs");
3
3
  const require_bytes_writer = require("./bytes/writer.cjs");
4
4
  const require_objects = require("./objects.cjs");
5
5
  const require_matrix = require("./matrix.cjs");
6
+ const require_embedded_font = require("./embedded-font.cjs");
6
7
  const require_serialize = require("./serialize.cjs");
7
8
  //#region src/content-write.ts
9
+ const GLYPH_SPACE_UNITS_PER_EM = 1e3;
10
+ const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
8
11
  function writeRgbOperator(writer, color, operator) {
9
12
  writer.writeAscii(`${require_serialize.formatNumber(color.r)} ${require_serialize.formatNumber(color.g)} ${require_serialize.formatNumber(color.b)} ${operator}\n`);
10
13
  }
@@ -22,8 +25,7 @@ function anchorMatrix(xPt, yPt, rotationDeg) {
22
25
  yPt
23
26
  ];
24
27
  }
25
- function writeUnderline(writer, item, widthPt, measurer) {
26
- const underline = measurer.underlineAtSize(item.font, item.sizePt);
28
+ function writeUnderline(writer, item, widthPt, underline) {
27
29
  writer.writeAscii("q\n");
28
30
  writeMatrixOperator(writer, anchorMatrix(item.xPt, item.yPt, item.rotationDeg), "cm");
29
31
  writeRgbOperator(writer, item.color, "rg");
@@ -31,23 +33,39 @@ function writeUnderline(writer, item, widthPt, measurer) {
31
33
  writer.writeAscii("f\n");
32
34
  writer.writeAscii("Q\n");
33
35
  }
34
- function writeText(writer, item, context, substitutions) {
35
- const font = context.resolveFont(item.font);
36
- const encoded = require_afm_widths.encodeForShow(item.text, font.standardName);
37
- substitutions.push(...encoded.substitutions);
38
- const scalePercent = context.measurer.horizontalScaleFor(item.font) * 100;
36
+ function writeShowTextBlock(writer, item, resourceName, scalePercent, codes) {
39
37
  writer.writeAscii("BT\n");
40
- writer.writeAscii(`/${font.resourceName} ${require_serialize.formatNumber(item.sizePt)} Tf\n`);
38
+ writer.writeAscii(`/${resourceName} ${require_serialize.formatNumber(item.sizePt)} Tf\n`);
41
39
  writer.writeAscii(`${require_serialize.formatNumber(scalePercent)} Tz\n`);
42
40
  writeRgbOperator(writer, item.color, "rg");
43
41
  writeMatrixOperator(writer, anchorMatrix(item.xPt, item.yPt, item.rotationDeg), "Tm");
44
- require_serialize.writeObject(writer, require_objects.pdfHexString(encoded.codes));
42
+ require_serialize.writeObject(writer, require_objects.pdfHexString(codes));
45
43
  writer.writeAscii(" Tj\n");
46
44
  writer.writeAscii("ET\n");
47
- if (item.underline === true) {
48
- const scale = context.measurer.horizontalScaleFor(item.font);
49
- writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / 1e3 * item.sizePt * scale, context.measurer);
45
+ }
46
+ function writeStandardText(writer, item, standardName, resourceName, measurer, substitutions) {
47
+ const encoded = require_afm_widths.encodeForShow(item.text, standardName);
48
+ substitutions.push(...encoded.substitutions);
49
+ const scale = measurer.horizontalScaleFor(item.font);
50
+ writeShowTextBlock(writer, item, resourceName, scale * 100, encoded.codes);
51
+ if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
52
+ }
53
+ function writeEmbeddedText(writer, item, face, resourceName, missingGlyphs) {
54
+ const encoded = require_embedded_font.encodeForShowEmbedded(item.text, face);
55
+ missingGlyphs.push(...encoded.substitutions);
56
+ writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, encoded.codes);
57
+ if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
58
+ offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
59
+ thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
60
+ });
61
+ }
62
+ function writeText(writer, item, context, substitutions, missingGlyphs) {
63
+ const font = context.resolveFont(item.font);
64
+ if (font.kind === "embedded") {
65
+ writeEmbeddedText(writer, item, font.face, font.resourceName, missingGlyphs);
66
+ return;
50
67
  }
68
+ writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer, substitutions);
51
69
  }
52
70
  function paintOperatorFor(fill, stroke, fillRule) {
53
71
  const evenOdd = fillRule === "evenodd";
@@ -122,7 +140,8 @@ function writeImage(writer, item, context) {
122
140
  function writeContentStream(items, context) {
123
141
  const writer = new require_bytes_writer.ByteWriter();
124
142
  const substitutions = [];
125
- for (const item of items) if (item.kind === "text") writeText(writer, item, context, substitutions);
143
+ const missingGlyphs = [];
144
+ for (const item of items) if (item.kind === "text") writeText(writer, item, context, substitutions, missingGlyphs);
126
145
  else if (item.kind === "image") writeImage(writer, item, context);
127
146
  else if (item.kind === "rect") writeRect(writer, item);
128
147
  else if (item.kind === "line") writeLine(writer, item);
@@ -130,7 +149,8 @@ function writeContentStream(items, context) {
130
149
  else if (item.kind === "path") writePath(writer, item);
131
150
  return {
132
151
  bytes: writer.toBytes(),
133
- substitutions
152
+ substitutions,
153
+ missingGlyphs
134
154
  };
135
155
  }
136
156
  //#endregion
@@ -1,12 +1,18 @@
1
1
  import { r as StandardFontName } from "./afm-widths-DyDq56Ph.cjs";
2
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CLedn-mT.cjs";
2
3
  import { TextMeasurer } from "./measure.cjs";
3
4
  import { WinAnsiSubstitution } from "./winansi.cjs";
4
5
  import { LayoutFont, LayoutItem } from "document-schema.js";
5
6
  //#region src/content-write.d.ts
6
- interface ResolvedFontResource {
7
+ type ResolvedFontResource = {
8
+ readonly kind: 'standard';
7
9
  readonly resourceName: string;
8
10
  readonly standardName: StandardFontName;
9
- }
11
+ } | {
12
+ readonly kind: 'embedded';
13
+ readonly resourceName: string;
14
+ readonly face: EmbeddedFace;
15
+ };
10
16
  interface ResolvedImageResource {
11
17
  readonly resourceName: string;
12
18
  }
@@ -18,6 +24,7 @@ interface ContentWriteContext {
18
24
  interface ContentStreamResult {
19
25
  readonly bytes: Uint8Array<ArrayBuffer>;
20
26
  readonly substitutions: readonly WinAnsiSubstitution[];
27
+ readonly missingGlyphs: readonly EmbeddedFaceSubstitution[];
21
28
  }
22
29
  declare function writeContentStream(items: readonly LayoutItem[], context: ContentWriteContext): ContentStreamResult;
23
30
  //#endregion
@@ -1,12 +1,18 @@
1
1
  import { r as StandardFontName } from "./afm-widths-DyDq56Ph.js";
2
+ import { r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CbqkKgBl.js";
2
3
  import { TextMeasurer } from "./measure.js";
3
4
  import { WinAnsiSubstitution } from "./winansi.js";
4
5
  import { LayoutFont, LayoutItem } from "document-schema.js";
5
6
  //#region src/content-write.d.ts
6
- interface ResolvedFontResource {
7
+ type ResolvedFontResource = {
8
+ readonly kind: 'standard';
7
9
  readonly resourceName: string;
8
10
  readonly standardName: StandardFontName;
9
- }
11
+ } | {
12
+ readonly kind: 'embedded';
13
+ readonly resourceName: string;
14
+ readonly face: EmbeddedFace;
15
+ };
10
16
  interface ResolvedImageResource {
11
17
  readonly resourceName: string;
12
18
  }
@@ -18,6 +24,7 @@ interface ContentWriteContext {
18
24
  interface ContentStreamResult {
19
25
  readonly bytes: Uint8Array<ArrayBuffer>;
20
26
  readonly substitutions: readonly WinAnsiSubstitution[];
27
+ readonly missingGlyphs: readonly EmbeddedFaceSubstitution[];
21
28
  }
22
29
  declare function writeContentStream(items: readonly LayoutItem[], context: ContentWriteContext): ContentStreamResult;
23
30
  //#endregion
@@ -2,8 +2,11 @@ import { o as encodeForShow } from "./afm-widths-Dxucrg7D.js";
2
2
  import { ByteWriter } from "./bytes/writer.js";
3
3
  import { pdfHexString } from "./objects.js";
4
4
  import { BEZIER_KAPPA, multiplyMatrices, rotationMatrix, scaleMatrix, translationMatrix } from "./matrix.js";
5
+ import { encodeForShowEmbedded } from "./embedded-font.js";
5
6
  import { formatNumber, writeObject } from "./serialize.js";
6
7
  //#region src/content-write.ts
8
+ const GLYPH_SPACE_UNITS_PER_EM = 1e3;
9
+ const EMBEDDED_HORIZONTAL_SCALE_PERCENT = 100;
7
10
  function writeRgbOperator(writer, color, operator) {
8
11
  writer.writeAscii(`${formatNumber(color.r)} ${formatNumber(color.g)} ${formatNumber(color.b)} ${operator}\n`);
9
12
  }
@@ -21,8 +24,7 @@ function anchorMatrix(xPt, yPt, rotationDeg) {
21
24
  yPt
22
25
  ];
23
26
  }
24
- function writeUnderline(writer, item, widthPt, measurer) {
25
- const underline = measurer.underlineAtSize(item.font, item.sizePt);
27
+ function writeUnderline(writer, item, widthPt, underline) {
26
28
  writer.writeAscii("q\n");
27
29
  writeMatrixOperator(writer, anchorMatrix(item.xPt, item.yPt, item.rotationDeg), "cm");
28
30
  writeRgbOperator(writer, item.color, "rg");
@@ -30,23 +32,39 @@ function writeUnderline(writer, item, widthPt, measurer) {
30
32
  writer.writeAscii("f\n");
31
33
  writer.writeAscii("Q\n");
32
34
  }
33
- function writeText(writer, item, context, substitutions) {
34
- const font = context.resolveFont(item.font);
35
- const encoded = encodeForShow(item.text, font.standardName);
36
- substitutions.push(...encoded.substitutions);
37
- const scalePercent = context.measurer.horizontalScaleFor(item.font) * 100;
35
+ function writeShowTextBlock(writer, item, resourceName, scalePercent, codes) {
38
36
  writer.writeAscii("BT\n");
39
- writer.writeAscii(`/${font.resourceName} ${formatNumber(item.sizePt)} Tf\n`);
37
+ writer.writeAscii(`/${resourceName} ${formatNumber(item.sizePt)} Tf\n`);
40
38
  writer.writeAscii(`${formatNumber(scalePercent)} Tz\n`);
41
39
  writeRgbOperator(writer, item.color, "rg");
42
40
  writeMatrixOperator(writer, anchorMatrix(item.xPt, item.yPt, item.rotationDeg), "Tm");
43
- writeObject(writer, pdfHexString(encoded.codes));
41
+ writeObject(writer, pdfHexString(codes));
44
42
  writer.writeAscii(" Tj\n");
45
43
  writer.writeAscii("ET\n");
46
- if (item.underline === true) {
47
- const scale = context.measurer.horizontalScaleFor(item.font);
48
- writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / 1e3 * item.sizePt * scale, context.measurer);
44
+ }
45
+ function writeStandardText(writer, item, standardName, resourceName, measurer, substitutions) {
46
+ const encoded = encodeForShow(item.text, standardName);
47
+ substitutions.push(...encoded.substitutions);
48
+ const scale = measurer.horizontalScaleFor(item.font);
49
+ writeShowTextBlock(writer, item, resourceName, scale * 100, encoded.codes);
50
+ if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt * scale, measurer.underlineAtSize(item.font, item.sizePt));
51
+ }
52
+ function writeEmbeddedText(writer, item, face, resourceName, missingGlyphs) {
53
+ const encoded = encodeForShowEmbedded(item.text, face);
54
+ missingGlyphs.push(...encoded.substitutions);
55
+ writeShowTextBlock(writer, item, resourceName, EMBEDDED_HORIZONTAL_SCALE_PERCENT, encoded.codes);
56
+ if (item.underline === true) writeUnderline(writer, item, item.widthPt ?? encoded.width1000 / GLYPH_SPACE_UNITS_PER_EM * item.sizePt, {
57
+ offsetPt: face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt,
58
+ thicknessPt: face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * item.sizePt
59
+ });
60
+ }
61
+ function writeText(writer, item, context, substitutions, missingGlyphs) {
62
+ const font = context.resolveFont(item.font);
63
+ if (font.kind === "embedded") {
64
+ writeEmbeddedText(writer, item, font.face, font.resourceName, missingGlyphs);
65
+ return;
49
66
  }
67
+ writeStandardText(writer, item, font.standardName, font.resourceName, context.measurer, substitutions);
50
68
  }
51
69
  function paintOperatorFor(fill, stroke, fillRule) {
52
70
  const evenOdd = fillRule === "evenodd";
@@ -121,7 +139,8 @@ function writeImage(writer, item, context) {
121
139
  function writeContentStream(items, context) {
122
140
  const writer = new ByteWriter();
123
141
  const substitutions = [];
124
- for (const item of items) if (item.kind === "text") writeText(writer, item, context, substitutions);
142
+ const missingGlyphs = [];
143
+ for (const item of items) if (item.kind === "text") writeText(writer, item, context, substitutions, missingGlyphs);
125
144
  else if (item.kind === "image") writeImage(writer, item, context);
126
145
  else if (item.kind === "rect") writeRect(writer, item);
127
146
  else if (item.kind === "line") writeLine(writer, item);
@@ -129,7 +148,8 @@ function writeContentStream(items, context) {
129
148
  else if (item.kind === "path") writePath(writer, item);
130
149
  return {
131
150
  bytes: writer.toBytes(),
132
- substitutions
151
+ substitutions,
152
+ missingGlyphs
133
153
  };
134
154
  }
135
155
  //#endregion