( config: FontBuildConfig, )
| 62 | * Generates the complete subset data map from raw file contents provided in the config. |
| 63 | */ |
| 64 | export const generateSubsetData = ( |
| 65 | config: FontBuildConfig, |
| 66 | ): Map<string, SubsetDefinition> => { |
| 67 | const subsetData = new Map<string, SubsetDefinition>(); |
| 68 | |
| 69 | for (const name of config.subsets) { |
| 70 | const fileContent = config.subsetSources?.[name]; |
| 71 | if (!fileContent) { |
| 72 | // Missing subset sources make the build nondeterministic. |
| 73 | throw new Error(`Missing subset source content for "${name}"`); |
| 74 | } |
| 75 | |
| 76 | // A slicing strategy file will contain "subsets {" blocks. |
| 77 | // Google-generated files don't have SlicingStrategy wrapper, just raw subset blocks |
| 78 | if (fileContent.includes('subsets {')) { |
| 79 | const slices = parseSlicingStrategy(fileContent); |
| 80 | subsetData.set(name, { |
| 81 | name, |
| 82 | type: 'sliced', |
| 83 | slices: slices.map((codepoints, i) => ({ index: i + 1, codepoints })), |
| 84 | }); |
| 85 | } else { |
| 86 | const codepoints = parseNamFile(fileContent); |
| 87 | const unicodeRange = codepointsToRangeString(codepoints); |
| 88 | subsetData.set(name, { name, type: 'range', unicodeRange, codepoints }); |
| 89 | } |
| 90 | } |
| 91 | return subsetData; |
| 92 | }; |
no test coverage detected