diff options
| author | kj_sh604 | 2026-03-01 19:07:42 -0500 |
|---|---|---|
| committer | kj_sh604 | 2026-03-01 19:07:42 -0500 |
| commit | 41fa7fe9ed84c4b8989f622fb532722b7f39ad72 (patch) | |
| tree | c0cff2582ae6bfa4f06a699dc13e4210d76c318f /src/fonts.php | |
| parent | a181069363b19274f65e36e69b172e7063647c1e (diff) | |
refactor: src/
Diffstat (limited to 'src/fonts.php')
| -rw-r--r-- | src/fonts.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/fonts.php b/src/fonts.php new file mode 100644 index 0000000..1959f51 --- /dev/null +++ b/src/fonts.php @@ -0,0 +1,49 @@ +<?php +// fonts.php — LIST server-side fonts via fontconfig + +header('Content-Type: application/json'); +header('Cache-Control: public, max-age=3600'); + +$output = shell_exec('fc-list --format="%{family}|%{file}\n" 2>/dev/null'); +if (!$output) { + echo json_encode([]); + exit; +} + +$lines = array_filter(explode("\n", trim($output))); +$fonts = []; +$seen = []; + +foreach ($lines as $line) { + $parts = explode('|', $line, 2); + if (count($parts) < 2) continue; + + /* take first family name (some entries are comma-separated) */ + $families = explode(',', $parts[0]); + $family = trim($families[0]); + + if (empty($family) || isset($seen[$family])) continue; + + $file = trim($parts[1]); + if (!file_exists($file)) continue; + + $seen[$family] = true; + + $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); + $format = match ($ext) { + 'ttf' => 'truetype', + 'otf' => 'opentype', + 'woff' => 'woff', + 'woff2' => 'woff2', + default => 'truetype', + }; + + $fonts[] = [ + 'family' => $family, + 'file' => base64_encode($file), + 'format' => $format, + ]; +} + +usort($fonts, fn($a, $b) => strcasecmp($a['family'], $b['family'])); +echo json_encode($fonts); |
