From 946cbef95f3e68131f49bcf1801f310a476e6e0f Mon Sep 17 00:00:00 2001 From: John Ralls Date: Mon, 26 Oct 2020 14:05:31 -0700 Subject: [PATCH] HTML fonts: Parse additional values of font-weight from the pango font name. --- gnucash/report/html-fonts.scm | 18 ++++++++++++++++-- gnucash/report/test/test-html-fonts.scm | 8 ++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gnucash/report/html-fonts.scm b/gnucash/report/html-fonts.scm index ea5a3126fc..ee1598948a 100644 --- a/gnucash/report/html-fonts.scm +++ b/gnucash/report/html-fonts.scm @@ -26,6 +26,7 @@ (use-modules (gnucash core-utils)) +(use-modules (ice-9 regex)) (define (string-strip s1 s2) (let ((idx (string-contains-ci s1 s2))) @@ -40,11 +41,24 @@ (font-stretch "") (idx (string-index-right font-name #\space)) (font-size (substring font-name (1+ idx) (string-length font-name))) - (font-name (string-take font-name idx))) + (font-name (string-take font-name idx)) + (pat (make-regexp " weight=([0-9]+)" regexp/icase regexp/extended)) + (match (regexp-exec pat font-name))) - (when (string-contains-ci font-name " bold") + + (cond + ((string-contains-ci font-name " bold") (set! font-weight "font-weight: bold; ") (set! font-name (string-strip font-name " bold"))) + ((string-contains-ci font-name " regular") + (set! font-weight "font-weight: normal; ") + (set! font-name (string-strip font-name " regular"))) + ((string-contains-ci font-name " light") + (set! font-weight "font-weight: lighter; ") + (set! font-name (string-strip font-name " light"))) + ((regexp-match? match) + (set! font-weight (regexp-substitute #f match "font-weight: " 1 "; ")) + (set! font-name (regexp-substitute #f match 'pre 'post)))) (cond ((string-contains-ci font-name " italic") diff --git a/gnucash/report/test/test-html-fonts.scm b/gnucash/report/test/test-html-fonts.scm index 0a6df2ca77..d5abc1827d 100644 --- a/gnucash/report/test/test-html-fonts.scm +++ b/gnucash/report/test/test-html-fonts.scm @@ -14,11 +14,11 @@ (test-begin "font-name-to-style-info") (test-equal "basic" - "font-family: \"Courier Regular\", sans-serif; font-size: 20pt; " + "font-family: \"Courier\", sans-serif; font-size: 20pt; font-weight: normal; " (font-name-to-style-info "Courier Regular 20")) (test-equal "basic size 50" - "font-family: \"Courier Regular\", sans-serif; font-size: 50pt; " + "font-family: \"Courier\", sans-serif; font-size: 50pt; font-weight: normal; " (font-name-to-style-info "Courier Regular 50")) (test-equal "basic size 50 bold" @@ -33,4 +33,8 @@ "font-family: \"Courier\", sans-serif; font-size: 15pt; font-style: oblique; " (font-name-to-style-info "Courier oblique 15")) + (test-equal "basic size 15 numeric weight" + "font-family: \"Courier\", sans-serif; font-size: 15pt; font-weight: 550; " + (font-name-to-style-info "Courier weight=550 15")) + (test-end "font-name-to-style-info"))