(text: string)
| 264 | * Encode string as UTF-16BE with BOM. |
| 265 | */ |
| 266 | export function encodeUtf16BE(text: string): Uint8Array { |
| 267 | const bytes: number[] = [0xfe, 0xff]; // BOM |
| 268 | |
| 269 | for (const char of text) { |
| 270 | // biome-ignore lint/style/noNonNullAssertion: char will exist since it's a string |
| 271 | const code = char.codePointAt(0)!; |
| 272 | |
| 273 | if (code > 0xffff) { |
| 274 | // Surrogate pair needed for characters outside BMP |
| 275 | const adjusted = code - 0x10000; |
| 276 | const high = 0xd800 + (adjusted >> 10); |
| 277 | const low = 0xdc00 + (adjusted & 0x3ff); |
| 278 | |
| 279 | bytes.push(high >> 8, high & 0xff); |
| 280 | bytes.push(low >> 8, low & 0xff); |
| 281 | } else { |
| 282 | bytes.push(code >> 8, code & 0xff); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | return new Uint8Array(bytes); |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Encode string for PDF text string. |
no test coverage detected