about summary refs log tree commit diff
path: root/pkgs/data/fonts/openmoji
diff options
context:
space:
mode:
authorFrancesco Gazzetta <fgaz@fgaz.me>2019-10-01 15:43:42 +0200
committerFrancesco Gazzetta <fgaz@fgaz.me>2021-08-11 11:28:46 +0200
commit4a377fd6179c998ae779a7eac8b567afb116acc6 (patch)
tree3e42293ae971000215a6a0280de168d996effe56 /pkgs/data/fonts/openmoji
parentb9a3c230bdf5729c95f99a5aae44bc5b71fe8dab (diff)
openmoji-black,openmoji-color: init at 12.0.0
Diffstat (limited to 'pkgs/data/fonts/openmoji')
-rw-r--r--pkgs/data/fonts/openmoji/default.nix79
1 files changed, 79 insertions, 0 deletions
diff --git a/pkgs/data/fonts/openmoji/default.nix b/pkgs/data/fonts/openmoji/default.nix
new file mode 100644
index 0000000000000..0e6843c074514
--- /dev/null
+++ b/pkgs/data/fonts/openmoji/default.nix
@@ -0,0 +1,79 @@
+{ stdenv
+, fetchFromGitHub
+, scfbuild
+, variant ? "color" # "color" or "black"
+}:
+
+let
+  filename = builtins.replaceStrings
+    [ "color"              "black"              ]
+    [ "OpenMoji-Color.ttf" "OpenMoji-Black.ttf" ]
+    variant;
+
+in stdenv.mkDerivation rec {
+  pname = "openmoji";
+  version = "12.0.0";
+
+  src = fetchFromGitHub {
+    owner = "hfg-gmuend";
+    repo = pname;
+    rev = version;
+    sha256 = "0h8sr74gbdmcm8vv8pxlig50mmbf9w9lh4p8ih2lqqi5iry1dvhj";
+  };
+
+  nativeBuildInputs = [
+    scfbuild
+  ];
+
+  # Some id and data-* attributes in the svg files contain unicode characters,
+  # which scfbuild (a python2 program) does not like
+  # (https://github.com/13rac1/scfbuild/issues/14).
+  # Fortunately, it's only metadata which we can remove:
+  postPatch = ''
+    sed -Ei 's/(id|data-[^=]*)="[^"]*"//g' black/svg/*.svg color/svg/*.svg
+  '';
+
+  buildPhase = ''
+    # Bash reimplementation of helpers/export-svg-font.js
+    # so we don't need to build all the node deps first
+    hexcodes=()
+    missingGlyphBlack='./black/svg/25A1.svg'
+    missingGlyphColor='./color/svg/25A1.svg'
+    for f in ./color/svg/*.svg; do
+      basename=$(basename "$f" .svg)
+      hexcodes+=(''${basename//-/ })
+      filename=$(basename "$f");
+      cp "./color/svg/$filename" "./font/tmp-color/$filename"
+      cp "./black/svg/$filename" "./font/tmp-black/$filename"
+    done
+
+    hexcodes=($(uniq<<<"$hexcodes"))
+
+    for h in $hexcodes; do
+      filename="$h.svg"
+      if [ ! -e "./color/svg/$filename" ]; then
+        echo "$h is missing -> substitute with \"Missing Glyph\": $filename"
+        cp $missingGlyphColor "./font/tmp-color/$filename"
+        cp $missingGlyphBlack "./font/tmp-black/$filename"
+      fi
+    done
+
+    # Actually build the font:
+    cd font
+    scfbuild -c scfbuild-${variant}.yml
+  '';
+
+  installPhase = ''
+    install -Dm644 ${filename} $out/share/fonts/truetype/${filename}
+  '';
+
+  meta = with stdenv.lib; {
+    license = licenses.cc-by-sa-40;
+    maintainers = with maintainers; [ fgaz ];
+    platforms = platforms.all;
+    homepage = "https://openmoji.org/";
+    downloadPage = "https://github.com/hfg-gmuend/openmoji/releases";
+    description = "Open-source emojis for designers, developers and everyone else";
+  };
+}
+