summary refs log tree commit diff
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-12-01 19:38:34 +0100
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-12-01 19:38:34 +0100
commite9aa597a46e04d74efb176076366ed2755e610cd (patch)
treea40edcc4d04229b253184456512333e3e551e48b
parent9b83579ad19e3f9e59e88c38c92552ba8370a20c (diff)
feat(anzeigetafel): use a PIL bitmap font pil-font
Experiment, probably to be abandoned since PIL ImageFonts don't seem to
support unicode _at all_.
-rw-r--r--default.nix11
-rw-r--r--nix/pilfont.nix30
-rwxr-xr-xthird_party/flipdots/scripts/scroll_text.py7
3 files changed, 46 insertions, 2 deletions
diff --git a/default.nix b/default.nix
index 6a3787d..d8d6bb1 100644
--- a/default.nix
+++ b/default.nix
@@ -89,7 +89,7 @@ rec {
 
             sed -i "s/version = '.*'/version = '${version}'/" setup.py
 
-            sed -i 's|FONT =.*$|FONT = "${unifont}/share/fonts/truetype/unifont.ttf"|' anzeigetafel.py
+            sed -i 's|FONT =.*$|FONT = "${unifont-pil}/share/fonts/unifont.pil"|' anzeigetafel.py
           '';
         };
     in python3.pkgs.callPackage drv { };
@@ -106,4 +106,13 @@ rec {
       };
     };
   };
+
+  pilfont = python3.pkgs.callPackage ./nix/pilfont.nix { };
+
+  unifont-pil = pkgs.runCommandLocal "unifont-pil" {} ''
+    mkdir -p $out/share/fonts/
+    ${pkgs.gzip}/bin/gunzip < ${pkgs.unifont}/share/fonts/unifont.pcf.gz > unifont.pcf
+    ${pilfont}/bin/pilfont unifont.pcf
+    cp unifont.* $out/share/fonts/
+  '';
 }
diff --git a/nix/pilfont.nix b/nix/pilfont.nix
new file mode 100644
index 0000000..af4ebc2
--- /dev/null
+++ b/nix/pilfont.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchurl, python }:
+
+let
+  pythonEnv = python.withPackages (p: [ p.pillow ]);
+in
+
+stdenv.mkDerivation rec {
+  pname = "pilfont";
+  version = "unstable-2019-03-07";
+
+  src = fetchurl {
+    url = "https://raw.githubusercontent.com/python-pillow/pillow-scripts/b24479cf88d2d9b2cb5518971f3949f318f5c40e/Scripts/pilfont.py";
+    sha256 = "15my6380scmni5r2bnrkjgqqf3r38r275h91ygmi7a0935987n13";
+  };
+
+  dontUnpack = true;
+
+  buildInputs = [ pythonEnv ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    install -Dm755 $src $out/bin/pilfont
+  '';
+
+  meta = {
+    description = "PIL raster font compiler";
+    inherit (python.pkgs.pillow.meta) license;
+    homepage = "https://github.com/python-pillow/pillow-scripts";
+  };
+}
diff --git a/third_party/flipdots/scripts/scroll_text.py b/third_party/flipdots/scripts/scroll_text.py
index 68a5cf8..ef17390 100755
--- a/third_party/flipdots/scripts/scroll_text.py
+++ b/third_party/flipdots/scripts/scroll_text.py
@@ -6,6 +6,7 @@ from PIL import Image, ImageFont, ImageDraw
 import sys
 import fileinput
 import threading
+from pathlib import PurePath
 
 UDPHOST="flipdot.lab"
 UDPPORT=2323
@@ -37,7 +38,11 @@ def array2packet(a):
     return bytearray([list2byte(a[i*8:i*8+8]) for i in range(int(len(a)/8))])
 
 def str2array(s,font):
-    font = ImageFont.truetype(font=font,size=FONT_SIZE)
+    # load a pillow font directly
+    if PurePath(font).suffix == '.pil':
+        font = ImageFont.load(font)
+    else:
+        font = ImageFont.truetype(font=font,size=FONT_SIZE)
 
     img_width = font.getsize(s)[0]
     image     = Image.new("RGBA", (img_width,DISPLAY_SIZE[1]), C_BLACK)