diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-11-24 21:23:56 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-25 17:37:12 +0100 |
commit | 83835ea22d7e169f80d8740ce8a542103257d173 (patch) | |
tree | 24744e958aca45e583563ed6db9c58194dcd0b5c /tools/fonts | |
parent | 1fd20db73895cf1ca8fab9cf2c7d288d3bcc1c92 (diff) | |
download | server-83835ea22d7e169f80d8740ce8a542103257d173.tar.gz |
Remove obsolete tools and update other tools.
Diffstat (limited to 'tools/fonts')
-rwxr-xr-x | tools/fonts/woff2css2 | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/fonts/woff2css2 b/tools/fonts/woff2css2 new file mode 100755 index 0000000..8105524 --- /dev/null +++ b/tools/fonts/woff2css2 @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +# Embed a woff2 font in a static CSS file. +# Usage: woff2css in.woff2 out.css +# +# Limitations: takes weight and style information from the file name of the font. +# This script will throw an unhelpful exception if weight and style cannot +# be determined. + +# @font-face { +# font-family: "Dinish"; +# font-weight: 700; +# font-style: bold; +# src: url(data:font/woff2;base64,d09GMgABAAAAACzcAA0AAAAAc/wAACyGAAIAxQAAAAAAAAAAAAAAAAAAAAAAAAAAGnYbnkIcg0IGYACDHAqBpT +# } + +import os +import re +import sys + +if not re.search(r"\.woff2$", sys.argv[1]): + print("Usage: woff2css *.woff2") + sys.exit(1) + +for src in sys.argv[1:]: + m = re.match(r"([\w-]+)-(\w+)\.", os.path.basename(src)) + if m: + family = m.group(1) + style = m.group(2) + else: + print("Font should be named Family-Style.woff2; could not determine font weight.") + sys.exit(1) + + s = ("@font-face{") + s += (f"font-family:'{family}';") + if style == "Bold" or style == "BoldItalic": + s += (f"font-weight:bold;") + if style == "Italic" or style == "BoldItalic": + s += (f"font-style:italic;") + s += (f"src:url('{src}')format('woff2')") + s += ("}") + print(s) |