From cfbc56c96c900c2ae86a269e76fad1386c43809f Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 22 Feb 2022 14:06:59 -0800 Subject: [PATCH] infer font families from filename alone Allows a group of four RIBBI styles to be treated as a family, if they contain "bold" or "italic" in the filename --- quad/quadwriter/font.rkt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/quad/quadwriter/font.rkt b/quad/quadwriter/font.rkt index 66736d52..cd299d86 100644 --- a/quad/quadwriter/font.rkt +++ b/quad/quadwriter/font.rkt @@ -3,6 +3,7 @@ racket/string racket/path racket/match + racket/list fontland/font-path "attrs.rkt") (provide (all-defined-out)) @@ -49,10 +50,21 @@ (define key (cons (string-downcase family-name) (cond + ;; cases where fonts are in subdirectories named by style + ;; infer style from subdir name [(member "bold-italic" path-parts) 'bi] [(member "bold" path-parts) 'b] [(member "italic" path-parts) 'i] - [else 'r]))) + [else + ;; try to infer from filename alone + (define filename (string-downcase (last path-parts))) + (define filename-contains-bold? (string-contains? filename "bold")) + (define filename-contains-italic? (string-contains? filename "italic")) + (cond + [(and filename-contains-bold? filename-contains-italic?) 'bi] + [filename-contains-bold? 'b] + [filename-contains-italic? 'i] + [else 'r])]))) ;; only set value if there's not one there already. ;; this means that we only use the first eligible font we find. (hash-ref! font-paths key font-path)))