From patchwork Tue Sep 27 09:55:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taiju HIGASHI X-Patchwork-Id: 43002 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id C4A5127BBEA; Tue, 27 Sep 2022 10:58:28 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4258C27BBE9 for ; Tue, 27 Sep 2022 10:58:28 +0100 (BST) Received: from localhost ([::1]:60038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1od7MB-0005I0-DF for patchwork@mira.cbaines.net; Tue, 27 Sep 2022 05:58:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od7Js-0001jg-96 for guix-patches@gnu.org; Tue, 27 Sep 2022 05:56:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:53816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1od7Jr-0007sZ-Op for guix-patches@gnu.org; Tue, 27 Sep 2022 05:56:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1od7Jq-0004tc-6w for guix-patches@gnu.org; Tue, 27 Sep 2022 05:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#57963] [PATCH v3] home: fontutils: Support user's fontconfig. References: <20220921002721.23511-1-higashi@taiju.info> In-Reply-To: <20220921002721.23511-1-higashi@taiju.info> Resent-From: Taiju HIGASHI Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 27 Sep 2022 09:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57963 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: ludo@gnu.org, liliana.prikler@gmail.com, andrew@trop.in Cc: 57963@debbugs.gnu.org, Taiju HIGASHI Received: via spool by 57963-submit@debbugs.gnu.org id=B57963.166427255618801 (code B ref 57963); Tue, 27 Sep 2022 09:56:02 +0000 Received: (at 57963) by debbugs.gnu.org; 27 Sep 2022 09:55:56 +0000 Received: from localhost ([127.0.0.1]:52894 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1od7Jj-0004tB-EY for submit@debbugs.gnu.org; Tue, 27 Sep 2022 05:55:55 -0400 Received: from mail-pg1-f181.google.com ([209.85.215.181]:45862) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1od7Je-0004st-0z for 57963@debbugs.gnu.org; Tue, 27 Sep 2022 05:55:53 -0400 Received: by mail-pg1-f181.google.com with SMTP id r62so5109880pgr.12 for <57963@debbugs.gnu.org>; Tue, 27 Sep 2022 02:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=taiju-info.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=cdWhS+Qz1yPjvOsmI4PrFoJjJb50CRiXBRa7uh833xM=; b=cboOiLfKV/b9ZiLbf/H9Wc8hnSYsb8so3anDivj5atFL4nK5nzbYHInS32ZMcSb5cZ Y2cowMVqikC/pEM4pX0qU/lyvN/XpHEpDk6z9tyJEdVBNoA9BflpnioB2zMuHaXUCweX ehzXq1MGokG5UpTGLtUSdj3ACkUpHdXy4nKrPR8/XBb/mmDtx0l3ay83tftUuhTTxWPs 9wKijQMGGIucpc0kK9ooy9FI819y2EsIk5V7owsfkOPcIF+H3KRgRgXp3YVohrQ0T/2a dPDjUjX6YW1BRzMACmQKahU58dmws6bS+WfJPfEPg1pAcZipY0/w20I8xtJXvnGy90qn ZGSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=cdWhS+Qz1yPjvOsmI4PrFoJjJb50CRiXBRa7uh833xM=; b=OoyjPciM+rcrcTKYmikzoefZ8SVy4lEsgf9CP9Q8Is0rlC0MFEQboe/Li2Twvkiu7Y hqwWs5gV9iOtAURp1fRMMxc1fKnnnhpc+QLrHMbBTrOcoYQTQECLd+gpKzuafjPA2zAk QZ018Q0Jo4Amtok5Pyvr1psvrLxzNxnV/PQu52Zn+nY/l53uHW6owJKJw2hsglKn138i omqCrPE84n1GzIIvOdEfD586iUNbVbDnJlIeqDgRhwpQ0aIvjLWywJr+e4Oh0S0Mk2/Z uEnMg3RkmClgN7IpNC5ooe8rpOd0DX+Dw++QoAXe+v30V8AtmOrUUbh88jNXcRlN+xQF xNIQ== X-Gm-Message-State: ACrzQf2aMorCO0c3vZftSG2eRdgP+3nm/HACBsUsvjKREWRrWqHrYNzF aj8UT1C8Eifdnkq+sVxRgz1Gdg== X-Google-Smtp-Source: AMsMyM5Y4nhjHtJW75fSPJzU++Zp8vXHE6UwdsbBd/HSZNnvPzEpqCCO0yMmDf4Y6H0eDubRaw0dFA== X-Received: by 2002:a62:e20f:0:b0:556:4265:5de2 with SMTP id a15-20020a62e20f000000b0055642655de2mr23896644pfi.57.1664272544140; Tue, 27 Sep 2022 02:55:44 -0700 (PDT) Received: from Taix.flets-west.jp ([240b:253:ec40:2400:b7d1:436e:2d61:e925]) by smtp.gmail.com with ESMTPSA id u16-20020a170902e5d000b00172f6726d8esm1067770plf.277.2022.09.27.02.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 02:55:43 -0700 (PDT) From: Taiju HIGASHI Date: Tue, 27 Sep 2022 18:55:25 +0900 Message-Id: <20220927095525.26431-1-higashi@taiju.info> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/home/services/fontutils.scm (add-fontconfig-config-file): Support user's fontconfig. --- gnu/home/services/fontutils.scm | 103 ++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 6 deletions(-) diff --git a/gnu/home/services/fontutils.scm b/gnu/home/services/fontutils.scm index 6062eaed6a..b02f43a4fc 100644 --- a/gnu/home/services/fontutils.scm +++ b/gnu/home/services/fontutils.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen +;;; Copyright © 2022 Taiju HIGASHI ;;; ;;; This file is part of GNU Guix. ;;; @@ -20,9 +21,16 @@ (define-module (gnu home services fontutils) #:use-module (gnu home services) #:use-module (gnu packages fontutils) + #:use-module (gnu services configuration) #:use-module (guix gexp) + #:use-module (guix records) + #:use-module (srfi srfi-1) + #:use-module (sxml simple) + #:use-module (ice-9 match) - #:export (home-fontconfig-service-type)) + #:export (home-fontconfig-service-type + home-fontconfig-configuration + default-font)) ;;; Commentary: ;;; @@ -33,15 +41,96 @@ (define-module (gnu home services fontutils) ;;; ;;; Code: -(define (add-fontconfig-config-file he-symlink-path) +(define-record-type* default-font + make-default-font + default-font? + (serif default-font-serif (default "")) + (sans-serif defalut-font-sans-serif (default "")) + (monospace default-font-monospace (default ""))) + +(define (sxml->xmlstring sxml) + (if (null? sxml) + "" + (call-with-output-string + (lambda (port) + (sxml->xml sxml port) + (newline port))))) + +(define font-directories? list?) + +(define (serialize-font-directories field-name value) + (sxml->xmlstring + (append + '((dir "~/.guix-home/profile/share/fonts")) + (map + (lambda (path) + `(dir ,path)) + value)))) + +(define extra-config-list? list?) + +(define (serialize-extra-config-list field-name value) + (sxml->xmlstring + (map (match-lambda + ((? pair? sxml) sxml) + ((? string? xml) (xml->sxml xml)) + (_ (error "extra-config value must be xml string or sxml list."))) + value))) + +(define (serialize-default-font field-name value) + (match value + (($ serif sans-serif monospace) + (sxml->xmlstring + (fold (lambda (pair sxml) + (if (string-null? (cdr pair)) + sxml + (append sxml + `((alias + (family ,(car pair)) + (prefer + (family ,(cdr pair)))))))) + '() + `((serif . ,serif) + (sans-serif . ,sans-serif) + (monospace . ,monospace))))))) + +(define-configuration home-fontconfig-configuration + (font-directories + (font-directories '()) + "The directory list that provides fonts.") + (preferred-default-font + (default-font (default-font)) + "The preffered default fonts for serif, sans-serif, and monospace.") + (extra-config + (extra-config-list '()) + "Extra configuration values to append to the fonts.conf.")) + +(define (home-fontconfig-extend original-config extend-configs) + (home-fontconfig-configuration + (inherit original-config) + (font-directories + (append + (home-fontconfig-configuration-font-directories original-config) + (append-map home-fontconfig-configuration-font-directories extend-configs))) + (preferred-default-font + (home-fontconfig-configuration-preferred-default-font + (if (null? extend-configs) + original-config + (last extend-configs)))) + (extra-config + (append + (home-fontconfig-configuration-extra-config original-config) + (append-map home-fontconfig-configuration-extra-config extend-configs))))) + +(define (add-fontconfig-config-file user-config) `(("fontconfig/fonts.conf" ,(mixed-text-file "fonts.conf" " - - ~/.guix-home/profile/share/fonts -")))) +\n" + (serialize-configuration user-config home-fontconfig-configuration-fields) + "\n")))) (define (regenerate-font-cache-gexp _) `(("profile/share/fonts" @@ -49,6 +138,8 @@ (define (regenerate-font-cache-gexp _) (define home-fontconfig-service-type (service-type (name 'home-fontconfig) + (compose identity) + (extend home-fontconfig-extend) (extensions (list (service-extension home-xdg-configuration-files-service-type @@ -59,7 +150,7 @@ (define home-fontconfig-service-type (service-extension home-profile-service-type (const (list fontconfig))))) - (default-value #f) + (default-value (home-fontconfig-configuration)) (description "Provides configuration file for fontconfig and make fc-* utilities aware of font packages installed in Guix Home's profile.")))