| 35 | * Mutable encoding builder for constructing encodings. |
| 36 | */ |
| 37 | export class EncodingBuilder implements Encoding { |
| 38 | private readonly codeToName = new Map<number, string>(); |
| 39 | private readonly nameToCode = new Map<string, number>(); |
| 40 | |
| 41 | /** |
| 42 | * Add a character encoding mapping. |
| 43 | * @param code - Character code (0-255) |
| 44 | * @param name - Glyph name |
| 45 | */ |
| 46 | addCharacterEncoding(code: number, name: string): void { |
| 47 | this.codeToName.set(code, name); |
| 48 | this.nameToCode.set(name, code); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Get the glyph name for a character code. |
| 53 | * @param code - Character code (0-255) |
| 54 | * @returns The glyph name, or ".notdef" if not mapped |
| 55 | */ |
| 56 | getName(code: number): string { |
| 57 | return this.codeToName.get(code) ?? ".notdef"; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get the character code for a glyph name. |
| 62 | * @param name - The glyph name |
| 63 | * @returns The character code, or undefined if not mapped |
| 64 | */ |
| 65 | getCode(name: string): number | undefined { |
| 66 | return this.nameToCode.get(name); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get an unmodifiable view of the code to name mapping. |
| 71 | * @returns Map from character codes to glyph names |
| 72 | */ |
| 73 | getCodeToNameMap(): ReadonlyMap<number, string> { |
| 74 | return this.codeToName; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Create an encoding from a code-to-name map. |
nothing calls this directly
no outgoing calls
no test coverage detected