HTML fonts: Parse additional values of font-weight from the pango font name.

This commit is contained in:
John Ralls 2020-10-26 14:05:31 -07:00
parent 4ddd28a5d9
commit 946cbef95f
2 changed files with 22 additions and 4 deletions

View File

@ -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")

View File

@ -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"))