| 22 | * Base class for CFF encodings. |
| 23 | */ |
| 24 | export class CFFEncodingBase implements CFFEncoding { |
| 25 | // code -> name mapping |
| 26 | protected readonly codeToName = new Map<number, string>(); |
| 27 | // name -> code mapping |
| 28 | protected readonly nameToCode = new Map<string, number>(); |
| 29 | |
| 30 | /** |
| 31 | * Add a code/name mapping. |
| 32 | */ |
| 33 | add(code: number, sid: number, name?: string): void { |
| 34 | const glyphName = name ?? getStandardString(sid) ?? `.sid${sid}`; |
| 35 | this.codeToName.set(code, glyphName); |
| 36 | |
| 37 | if (!this.nameToCode.has(glyphName)) { |
| 38 | this.nameToCode.set(glyphName, code); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | getName(code: number): string | undefined { |
| 43 | return this.codeToName.get(code); |
| 44 | } |
| 45 | |
| 46 | getCode(name: string): number | undefined { |
| 47 | return this.nameToCode.get(name); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Standard Encoding (encoding ID 0). |
nothing calls this directly
no outgoing calls
no test coverage detected