Font Library [main]

Added fontpack cmap

=> 9a84396eab9d47079ed02ecb38ff9bb7b0799093

diff --git a/build/font_cmap.py b/build/font_cmap.py
new file mode 100755
index 0000000..26ede8b
--- /dev/null
+++ b/build/font_cmap.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+import os
+import re
+import subprocess
+import sys
+import tempfile
+import zipfile
+
+def list_cmap_ranges(font_files):
+    code_pattern = re.compile(r'^\s* 0x20:
+                    cmap.add(code)
+
+    ranges = []
+    begin, end = None, None
+    for code in sorted(cmap):
+        if begin is None:
+            begin, end = code, code + 1
+        else:
+            if code > end:
+                ranges.append((begin, end))
+                begin, end = code, code + 1
+            elif code == end:
+                end = code + 1
+            else:
+                assert "WTF?"
+    if begin:
+        ranges.append((begin, end))
+
+    #print(ranges)
+    out = []
+    for r in ranges:
+        len = r[1] - r[0]
+        if len == 1:
+            out.append(str(r[0]))
+        else:
+            out.append(f'{r[0]}-{r[1] - 1}')
+    return ','.join(out)
+
+
+def make_fontpack_cmap(path):
+    pack = zipfile.ZipFile(path)
+    tmp_files = []
+    for file in pack.namelist():
+        if file.endswith('.ttf') or file.endswith('.ttc'):
+            tmp = tempfile.NamedTemporaryFile()
+            tmp_files.append(tmp)
+            data = pack.read(file)
+            tmp.write(data)
+    cmap = list_cmap_ranges([f.name for f in tmp_files])
+    if cmap: 
+        return path + ': ' + cmap
+    return None
+
+
+input_files = []
+for path in sys.argv[1:]:
+    if path.startswith('./'):
+        path = path[2:]
+    input_files.append((os.path.getsize(path), path))
+
+cmapfile = open('cmap.txt', 'wt')
+for _, path in sorted(input_files):
+    print('\nFONTPACK:', path)
+    line = make_fontpack_cmap(path)
+    if line:
+        print(line, file=cmapfile)
diff --git a/cmap.txt.gz b/cmap.txt.gz
new file mode 100644
index 0000000..54521fb
Binary files /dev/null and b/cmap.txt.gz differ
diff --git a/make_cmap.sh b/make_cmap.sh
new file mode 100755
index 0000000..5d0e6e9
--- /dev/null
+++ b/make_cmap.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+find . -name "*.fontpack" | xargs build/font_cmap.py
+gzip -f cmap.txt
Proxy Information
Original URL
gemini://git.skyjake.fi/fonts/main/cdiff/9a84396eab9d47079ed02ecb38ff9bb7b0799093
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
25.990698 milliseconds
Gemini-to-HTML Time
0.345265 milliseconds

This content has been proxied by September (ba2dc).