Subject: [bug#69424] [PATCH 2/5] gnu: font-google-noto: Keep only variable fonts when available.

From: Hilton Chain <[email-masked]>
Date: Tue, 27 Feb 2024 20:54:23 +0800

* gnu/packages/fonts.scm (font-google-noto)[arguments]: When available, keep
only variable fonts.

Suggested-by: Jiwei YANG <[email-masked]>
Change-Id: Icac2927fb6c35d08504c379e273a5fc03b08ac46
---
 gnu/packages/fonts.scm | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/gnu/packages/fonts.scm b/gnu/packages/fonts.scm
index 72bf0124c4..1ed648f5a2 100644
--- a/gnu/packages/fonts.scm
+++ b/gnu/packages/fonts.scm
@@ -1092,6 +1092,48 @@ (define-public font-google-noto
        (sha256
         (base32 "087jg8ahpq35xwyrmvm9ivxl0wjic2j4r28bbrwqmgdva9brms40"))))
     (build-system font-build-system)
+    (arguments
+     (list
+      #:modules
+      '((guix build font-build-system)
+        (guix build utils)
+        (ice-9 ftw)
+        (srfi srfi-26))
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-before 'install 'delete-extra-fonts
+            (lambda _
+              (define (scan-directory name)
+                (scandir name (lambda (file)
+                                (not (member file '("." ".." "LICENSE"))))))
+              (define (delete-extra-font-formats variant)
+                "Keep one font format, variable or OTF or TTF."
+                (with-directory-excursion variant
+                  (let ((formats (scan-directory ".")))
+                    (for-each
+                     delete-file-recursively
+                     (cond
+                      ((member "variable-ttf" formats)
+                       (delete "variable-ttf" formats))
+                      ((member "otf" formats)
+                       (delete "otf" formats))
+                      ((member "ttf" formats)
+                       (delete "ttf" formats)))))))
+              (define (delete-extra-font-variants font)
+                "Keep one font variant, full or unhinted."
+                (with-directory-excursion font
+                  (let ((variants (scan-directory ".")))
+                    (for-each
+                     delete-file-recursively
+                     (cond
+                      ((member "full" variants)
+                       (delete-extra-font-formats "full")
+                       (delete "full" variants))
+                      ((member "unhinted" variants)
+                       (delete-extra-font-formats "unhinted")
+                       (delete "unhinted" variants)))))))
+              (with-directory-excursion "fonts"
+                (for-each delete-extra-font-variants (scan-directory "."))))))))
     (home-page "https://www.google.com/get/noto/")
     (synopsis "Fonts to cover all languages")
     (description "Google Noto Fonts is a family of fonts designed to support
--
2.41.0