'fa-solid-900.woff', 'far' => 'fa-regular-400.woff', 'fab' => 'fa-brands-400.woff', ]; /** * Extract one table's uncompressed bytes from a WOFF container. * * WOFF stores each table zlib-deflated when compLen differs from origLen. */ function fa5_woff_table(string $raw, string $tag): ?string { $num_tables = (int) (unpack('n', substr($raw, 12, 2))[1] ?? 0); if ($num_tables < 1 || strlen($raw) < 44 + $num_tables * 20) { return null; } for ($i = 0; $i < $num_tables; $i++) { $entry = substr($raw, 44 + $i * 20, 20); if (substr($entry, 0, 4) !== $tag) { continue; } $p = unpack('Noffset/NcompLen/NorigLen', substr($entry, 4, 12)); $data = substr($raw, $p['offset'], $p['compLen']); if ($p['compLen'] !== $p['origLen']) { $data = gzuncompress($data); if ($data === false) { return null; } } return $data; } return null; } /** * Codepoints mapped by a cmap table, keyed for O(1) membership tests. * * Only format-4 (Unicode BMP) subtables are decoded — the (3,1) record is * preferred, falling back to the first (3,x) then (0,x) record so a font that * ships a different platform order still resolves. */ function fa5_cmap_codepoints(string $cmap): array { $records = (int) (unpack('n', substr($cmap, 2, 2))[1] ?? 0); $best = null; $fallback = null; for ($i = 0; $i < $records; $i++) { $rec = unpack('nplatform/nencoding/Noffset', substr($cmap, 4 + $i * 8, 8)); if ($rec['platform'] === 3 && $rec['encoding'] === 1) { $best = $rec['offset']; break; } if ($fallback === null && ($rec['platform'] === 3 || $rec['platform'] === 0)) { $fallback = $rec['offset']; } } $offset = $best ?? $fallback; if ($offset === null || $offset + 14 > strlen($cmap)) { return []; } $table = substr($cmap, $offset); $format = (int) (unpack('n', substr($table, 0, 2))[1] ?? 0); if ($format !== 4) { fwrite(STDERR, "Unsupported cmap format {$format}; only format 4 is decoded\n"); exit(1); } $seg_x2 = (int) (unpack('n', substr($table, 6, 2))[1] ?? 0); $seg_count = intdiv($seg_x2, 2); if ($seg_count < 1) { return []; } $end_base = 14; $start_base = $end_base + $seg_x2 + 2; $codes = []; for ($i = 0; $i < $seg_count; $i++) { $start = (int) (unpack('n', substr($table, $start_base + $i * 2, 2))[1] ?? 0); $end = (int) (unpack('n', substr($table, $end_base + $i * 2, 2))[1] ?? 0); if ($start > $end || $end === 0xFFFF) { continue; } for ($code = $start; $code <= $end; $code++) { $codes[$code] = true; } } return $codes; } $css = (string) file_get_contents($css_path); // class name → codepoint (e.g. 'home' => 0xf015) if (!preg_match_all('/\.fa-([a-z0-9-]+):before\{content:"\\\\([0-9a-f]{4})"\}/i', $css, $m, PREG_SET_ORDER)) { fwrite(STDERR, "No glyph rules matched in all.min.css\n"); exit(1); } $name_to_code = []; foreach ($m as $hit) { $name_to_code[$hit[1]] = hexdec($hit[2]); } // style → set of codepoints, decoded from the shipped woff cmaps $code_to_style = []; foreach (FA5_FONTS as $style => $file) { $path = $fonts_path . '/' . $file; if (!is_readable($path)) { fwrite(STDERR, "Missing font: {$path}\n"); exit(1); } $cmap = fa5_woff_table((string) file_get_contents($path), 'cmap'); if ($cmap === null) { fwrite(STDERR, "No readable cmap table in {$path}\n"); exit(1); } $code_to_style[$style] = fa5_cmap_codepoints($cmap); } $groups = ['fas' => [], 'far' => [], 'fab' => []]; foreach ($name_to_code as $name => $code) { foreach ($groups as $style => $unused) { if (!empty($code_to_style[$style][$code])) { $groups[$style][] = $name; } } } foreach ($groups as $style => $names) { sort($groups[$style], SORT_NATURAL | SORT_FLAG_CASE); } $export = var_export($groups, true); $php = <<