| 136 | export type ResolveBmFont = Omit<BmFont, "pages"> & Pick<RawFont, "pages">; |
| 137 | |
| 138 | export async function processBitmapFont(file: string, font: LoadedFont) { |
| 139 | const chars: Record<string, BmCharacter> = {}; |
| 140 | const kernings: Record<string, BmKerning> = {}; |
| 141 | |
| 142 | for (let i = 0; i < font.chars.length; i++) { |
| 143 | const char = font.chars[i]!; |
| 144 | chars[String.fromCharCode(char.id)] = char; |
| 145 | } |
| 146 | |
| 147 | for (let i = 0; i < font.kernings.length; i++) { |
| 148 | const firstString = String.fromCharCode(font.kernings[i]!.first); |
| 149 | |
| 150 | kernings[firstString] = kernings[firstString]! || {}; |
| 151 | kernings[firstString]![String.fromCharCode(font.kernings[i]!.second)] = |
| 152 | font.kernings[i]!.amount; |
| 153 | } |
| 154 | |
| 155 | return { |
| 156 | ...font, |
| 157 | chars, |
| 158 | kernings, |
| 159 | pages: await Promise.all( |
| 160 | font.pages.map(async (page) => |
| 161 | CharacterJimp.read(path.join(path.dirname(file), page)) |
| 162 | ) |
| 163 | ), |
| 164 | }; |
| 165 | } |