[html-fonts] compact and tidy functions

This commit is contained in:
Christopher Lam 2019-11-15 21:27:09 +08:00
parent 37a51475be
commit 78cd4eaa05

View File

@ -60,105 +60,95 @@
;; Registers font options ;; Registers font options
(define (register-font-options options) (define (register-font-options options)
(let* (define (opt-register opt)
( (gnc:register-option options opt))
(opt-register (let ((font-family (gnc-get-default-report-font-family)))
(lambda (opt) (gnc:register-option options opt))) (opt-register
(font-family (gnc-get-default-report-font-family)) (gnc:make-font-option
) (N_ "Fonts")
(opt-register (N_ "Title") "a" (N_ "Font info for the report title.")
(gnc:make-font-option (string-append font-family " Bold 15")))
(N_ "Fonts") (opt-register
(N_ "Title") "a" (N_ "Font info for the report title.") (gnc:make-font-option
(string-append font-family " Bold 15"))) (N_ "Fonts")
(opt-register (N_ "Account link") "b" (N_ "Font info for account name.")
(gnc:make-font-option (string-append font-family " Italic 10")))
(N_ "Fonts") (opt-register
(N_ "Account link") "b" (N_ "Font info for account name.") (gnc:make-font-option
(string-append font-family " Italic 10"))) (N_ "Fonts")
(opt-register (N_ "Number cell") "c" (N_ "Font info for regular number cells.")
(gnc:make-font-option (string-append font-family " 10")))
(N_ "Fonts") (opt-register
(N_ "Number cell") "c" (N_ "Font info for regular number cells.") (gnc:make-simple-boolean-option
(string-append font-family " 10"))) (N_ "Fonts")
(opt-register (N_ "Negative Values in Red") "d" (N_ "Display negative values in red.")
(gnc:make-simple-boolean-option #t))
(N_ "Fonts") (opt-register
(N_ "Negative Values in Red") "d" (N_ "Display negative values in red.") (gnc:make-font-option
#t)) (N_ "Fonts")
(opt-register (N_ "Number header") "e" (N_ "Font info for number headers.")
(gnc:make-font-option (string-append font-family " 10")))
(N_ "Fonts") (opt-register
(N_ "Number header") "e" (N_ "Font info for number headers.") (gnc:make-font-option
(string-append font-family " 10"))) (N_ "Fonts")
(opt-register (N_ "Text cell") "f" (N_ "Font info for regular text cells.")
(gnc:make-font-option (string-append font-family " 10")))
(N_ "Fonts") (opt-register
(N_ "Text cell") "f" (N_ "Font info for regular text cells.") (gnc:make-font-option
(string-append font-family " 10"))) (N_ "Fonts")
(opt-register (N_ "Total number cell") "g"
(gnc:make-font-option (N_ "Font info for number cells containing a total.")
(N_ "Fonts") (string-append font-family " Bold 12")))
(N_ "Total number cell") "g" (N_ "Font info for number cells containing a total.") (opt-register
(string-append font-family " Bold 12"))) (gnc:make-font-option
(opt-register (N_ "Fonts")
(gnc:make-font-option (N_ "Total label cell") "h"
(N_ "Fonts") (N_ "Font info for cells containing total labels.")
(N_ "Total label cell") "h" (N_ "Font info for cells containing total labels.") (string-append font-family " Bold 12")))
(string-append font-family " Bold 12"))) (opt-register
(opt-register (gnc:make-font-option
(gnc:make-font-option (N_ "Fonts")
(N_ "Fonts") (N_ "Centered label cell") "i" (N_ "Font info for centered label cells.")
(N_ "Centered label cell") "i" (N_ "Font info for centered label cells.") (string-append font-family " Bold 12")))))
(string-append font-family " Bold 12")))
)
)
;; Adds CSS style information to an html document ;; Adds CSS style information to an html document
(define (add-css-information-to-doc options ssdoc doc) (define (add-css-information-to-doc options ssdoc doc)
(let* (define (opt-font-val name)
((opt-val (gnc:option-value (gnc:lookup-option options "Fonts" name)))
(lambda (section name) (define (opt-style-info name) (font-name-to-style-info (opt-font-val name)))
(gnc:option-value (gnc:lookup-option options section name)))) (let* ((negative-red? (opt-font-val "Negative Values in Red"))
(negative-red? (opt-val "Fonts" "Negative Values in Red")) (alternate-row-color
(alternate-row-color (gnc:color-option->html
(gnc:color-option->html (gnc:lookup-option options "Colors" "Alternate Table Cell Color")))
(gnc:lookup-option options (title-info (opt-style-info "Title"))
"Colors" (account-link-info (opt-style-info "Account link"))
"Alternate Table Cell Color"))) (number-cell-info (opt-style-info "Number cell"))
(title-font-info (font-name-to-style-info (opt-val "Fonts" "Title"))) (number-header-info (opt-style-info "Number header"))
(account-link-font-info (font-name-to-style-info (opt-val "Fonts" "Account link"))) (text-cell-info (opt-style-info "Text cell"))
(number-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Number cell"))) (total-number-cell-info (opt-style-info "Total number cell"))
(number-header-font-info (font-name-to-style-info (opt-val "Fonts" "Number header"))) (total-label-cell-info (opt-style-info "Total label cell"))
(text-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Text cell"))) (centered-label-cell-info (opt-style-info "Centered label cell")))
(total-number-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Total number cell")))
(total-label-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Total label cell")))
(centered-label-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Centered label cell"))))
(gnc:html-document-set-style-text! (gnc:html-document-set-style-text!
ssdoc ssdoc
(string-append (string-append
"h3 { " title-font-info " }\n" "h3 { " title-info " }\n"
"a { " account-link-font-info " }\n" "a { " account-link-info " }\n"
"body, p, table, tr, td { vertical-align: top; " text-cell-font-info " }\n" "body, p, table, tr, td { vertical-align: top; " text-cell-info " }\n"
"tr.alternate-row { background: " alternate-row-color " }\n" "tr.alternate-row { background: " alternate-row-color " }\n"
"tr { page-break-inside: avoid !important;}\n" "tr { page-break-inside: avoid !important;}\n"
"td, th { border-color: grey }\n" "td, th { border-color: grey }\n"
"th.column-heading-left { text-align: left; " number-header-font-info " }\n" "th.column-heading-left { text-align: left; " number-header-info " }\n"
"th.column-heading-center { text-align: center; " number-header-font-info " }\n" "th.column-heading-center { text-align: center; " number-header-info " }\n"
"th.column-heading-right { text-align: right; " number-header-font-info " }\n" "th.column-heading-right { text-align: right; " number-header-info " }\n"
"td.neg { " (if negative-red? "color: red; " "") " }\n" "td.neg { " (if negative-red? "color: red; " "") " }\n"
"td.number-cell, td.total-number-cell { text-align: right; white-space: nowrap; }\n" "td.number-cell, td.total-number-cell { text-align: right; white-space: nowrap; }\n"
"td.date-cell { white-space: nowrap; }\n" "td.date-cell { white-space: nowrap; }\n"
"td.anchor-cell { white-space: nowrap; " text-cell-font-info " }\n" "td.anchor-cell { white-space: nowrap; " text-cell-info " }\n"
"td.number-cell { " number-cell-font-info " }\n" "td.number-cell { " number-cell-info " }\n"
"td.number-header { text-align: right; " number-header-font-info " }\n" "td.number-header { text-align: right; " number-header-info " }\n"
"td.text-cell { " text-cell-font-info " }\n" "td.text-cell { " text-cell-info " }\n"
"td.total-number-cell { " total-number-cell-font-info " }\n" "td.total-number-cell { " total-number-cell-info " }\n"
"td.total-label-cell { " total-label-cell-font-info " }\n" "td.total-label-cell { " total-label-cell-info " }\n"
"td.centered-label-cell { text-align: center; " centered-label-cell-font-info " }\n" "td.centered-label-cell { text-align: center; " centered-label-cell-info " }\n"
(or (gnc:html-document-style-text doc) "") (or (gnc:html-document-style-text doc) "")))))
)
)
)
)