MCPcopy Create free account
hub / github.com/LibPDF-js/core / hexToString

Method hexToString

src/fontbox/afm/parser.ts:493–511  ·  view source on GitHub ↗
(hexString: string)

Source from the content-addressed store, hash-verified

491 // Low-level parsing methods
492
493 private hexToString(hexString: string): string {
494 if (hexString.length < 2) {
495 throw new Error(`Error: Expected hex string of length >= 2 not='${hexString}'`);
496 }
497
498 if (hexString[0] !== "<" || hexString[hexString.length - 1] !== ">") {
499 throw new Error(`String should be enclosed by angle brackets '${hexString}'`);
500 }
501
502 const hex = hexString.slice(1, -1);
503 const bytes = new Uint8Array(hex.length / 2);
504
505 for (let i = 0; i < hex.length; i += 2) {
506 bytes[i / 2] = Number.parseInt(hex.slice(i, i + 2), 16);
507 }
508
509 // ISO-8859-1 decoding
510 return String.fromCharCode(...bytes);
511 }
512
513 private tokenize(line: string): string[] {
514 // Split on whitespace and semicolons, keeping semicolons as tokens

Callers 1

parseKernPairMethod · 0.95

Calls 2

sliceMethod · 0.80
parseIntMethod · 0.80

Tested by

no test coverage detected