Add font support to all stylesheets

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19172 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2010-05-15 14:50:33 +00:00
parent 01b550472a
commit 9833f70b32
8 changed files with 247 additions and 186 deletions

View File

@ -37,6 +37,7 @@ gncscm_DATA = \
html-acct-table.scm \
html-barchart.scm \
html-document.scm \
html-fonts.scm \
html-piechart.scm \
html-scatter.scm \
html-linechart.scm \

View File

@ -0,0 +1,148 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; html-fonts.scm
;; html stuff for fonts/css
;;
;; Copyright (c) 2001 Linux Developers Group, Inc.
;; Copyright (c) Phil Longstaff <plongstaff@rogers.com>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Converts a font name to css style information
(define (font-name-to-style-info font-name)
(let*
(
(font-family "Arial")
(font-size "20")
(font-style #f)
(font-style-idx 0)
(font-weight #f)
(font-weight-idx 0)
(result "")
(len (string-length font-name))
(idx 0)
)
(set! idx (string-index-right font-name #\space))
(set! font-size (substring font-name (+ idx 1) len))
(set! font-name (string-take font-name idx))
(set! font-weight-idx (string-contains-ci font-name " bold"))
(if font-weight-idx
(begin
(set! font-weight "bold")
(set! font-name (string-append (string-take font-name font-weight-idx)
(string-drop font-name (+ font-weight-idx 5))))
))
(set! font-style-idx (string-contains-ci font-name " italic"))
(if font-style-idx
(begin
(set! font-style "italic")
(set! font-name (string-append (string-take font-name font-style-idx)
(string-drop font-name (+ font-style-idx 7))))
)
(begin
(set! font-style-idx (string-contains-ci font-name " oblique"))
(if font-style-idx
(begin
(set! font-style "oblique")
(set! font-name (string-append (string-take font-name font-style-idx)
(string-drop font-name (+ font-style-idx 8))))
))))
(set! font-family font-name)
(set! result (string-append
"font-family: " font-family "; "
"font-size: " font-size "pt; "
(if font-style (string-append "font-style: " font-style "; ") "")
(if font-weight (string-append "font-weight: " font-weight "; ") "")))
result
))
;; Registers font options
(define (register-font-options options)
(let*
(
(opt-register
(lambda (opt) (gnc:register-option options opt)))
)
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Title") "a" (N_ "Font info for the report title")
"Arial Bold 15"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Account link") "b" (N_ "Font info for account name")
"Arial Italic 8"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Number cell") "c" (N_ "Font info for regular number cells")
"Arial 10"))
(opt-register
(gnc:make-simple-boolean-option
(N_ "Fonts")
(N_ "Negative Values in Red") "d" (N_ "Display negative values in red.")
#t))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Number header") "e" (N_ "Font info for number headers")
"Arial 10"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Text cell") "f" (N_ "Font info for regular text cells")
"Arial 10"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Total number cell") "g" (N_ "Font info for number cells containing a total")
"Arial Bold 12"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Total label cell") "h" (N_ "Font info for cells containing total labels")
"Arial Bold 12"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Centered label cell") "i" (N_ "Font info for centered label cells")
"Arial Bold 12"))
)
)
;; Adds CSS style information to an html document
(define (add-css-information-to-doc options ssdoc)
(let*
((opt-val
(lambda (section name)
(gnc:option-value (gnc:lookup-option options section name))))
(negative-red? (opt-val "Fonts" "Negative Values in Red"))
(title-font-info (font-name-to-style-info (opt-val "Fonts" "Title")))
(account-link-font-info (font-name-to-style-info (opt-val "Fonts" "Account link")))
(number-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Number cell")))
(number-header-font-info (font-name-to-style-info (opt-val "Fonts" "Number header")))
(text-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Text 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!
ssdoc
(string-append
"h3 { " title-font-info " }\n"
"a { " account-link-font-info " }\n"
"body, p, table, tr, td { text-align: left; " text-cell-font-info " }\n"
"th { text-align: right; " number-header-font-info " }\n"
"td.neg { " (if negative-red? "color: red; " "") " }\n"
"td.number-cell, td.total-number-cell { text-align: right; white-space: nowrap; }\n"
"td.date-cell { white-space: nowrap; }\n"
"td.anchor-cell { white-space: nowrap; " text-cell-font-info " }\n"
"td.number-cell { " number-cell-font-info " }\n"
"td.number-header { text-align: right; " number-header-font-info " }\n"
"td.text-cell { " text-cell-font-info " }\n"
"td.total-number-cell { " total-number-cell-font-info " }\n"
"td.total-label-cell { " total-label-cell-font-info " }\n"
"td.centered-label-cell { text-align: center; " centered-label-cell-font-info " }\n"
)
)
)
)

View File

@ -68,6 +68,11 @@
(export gnc:options-add-sort-method!)
(export gnc:options-add-subtotal-view!)
;; html-fonts.scm
(export register-font-options)
(export add-css-information-to-doc)
;; html-utilities.scm
(export gnc:html-make-empty-cell)
@ -693,6 +698,7 @@
(load-from-path "html-scatter.scm")
(load-from-path "html-linechart.scm")
(load-from-path "html-style-info.scm")
(load-from-path "html-fonts.scm")
(load-from-path "html-style-sheet.scm")
(load-from-path "html-table.scm")

View File

@ -1,17 +1,17 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; stylesheet-css : the css-based stylesheet
;; Copyright 2009 Phil Longstaff <plongstaff@rogers.com>
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, contact:
;;
@ -26,59 +26,21 @@
(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
(use-modules (gnucash gnc-module))
(use-modules (gnucash core-utils))
(use-modules (gnucash report report-system))
(use-modules (srfi srfi-13))
(use-modules (srfi srfi-14))
(gnc:module-load "gnucash/report/report-system" 0)
(define (font-name-to-style-info font-name)
(let*
(
(font-family "Arial")
(font-size "20")
(font-style #f)
(font-style-idx 0)
(font-weight #f)
(font-weight-idx 0)
(result "")
(len (string-length font-name))
(idx 0)
)
(set! idx (string-index-right font-name #\space))
(set! font-size (substring font-name (+ idx 1) len))
(set! font-name (string-take font-name idx))
(set! font-weight-idx (string-contains-ci font-name " bold"))
(if font-weight-idx
(begin
(set! font-weight "bold")
(set! font-name (string-append (string-take font-name font-weight-idx)
(string-drop font-name (+ font-weight-idx 5))))
))
(set! font-style-idx (string-contains-ci font-name " italic"))
(if font-style-idx
(begin
(set! font-style "italic")
(set! font-name (string-append (string-take font-name font-style-idx)
(string-drop font-name (+ font-style-idx 7))))
))
(set! font-family font-name)
(set! result (string-append
"font-family: " font-family "; "
"font-size: " font-size "pt; "
(if font-style (string-append "font-style: " font-style "; ") "")
(if font-weight (string-append "font-weight: " font-weight "; ") "")))
result
))
;; css style sheet
;; css style sheet
;; this should generally be the default style sheet for most reports.
;; it's supposed to be lightweight and unobtrusive.
(define (css-options)
(let* ((options (gnc:new-options))
(opt-register
(lambda (opt)
(gnc:register-option options opt))))
(opt-register
(opt-register
(lambda (opt)
(gnc:register-option options opt))))
(opt-register
(gnc:make-color-option
(N_ "General")
(N_ "Background Color") "a" (N_ "Background color for reports.")
@ -94,130 +56,79 @@
(N_ "General")
(N_ "Enable Links") "c" (N_ "Enable hyperlinks in reports.")
#t))
(opt-register
(gnc:make-number-range-option
(opt-register
(gnc:make-number-range-option
(N_ "Tables")
(N_ "Table cell spacing") "c" (N_ "Space between table cells")
4 0 20 0 1))
(opt-register
(gnc:make-number-range-option
(opt-register
(gnc:make-number-range-option
(N_ "Tables")
(N_ "Table cell padding") "d" (N_ "Space between table cells")
0 0 20 0 1))
(opt-register
(gnc:make-number-range-option
(opt-register
(gnc:make-number-range-option
(N_ "Tables")
(N_ "Table border width") "e" (N_ "Bevel depth on tables")
0 0 20 0 1))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Title") "a" (N_ "Font info for the report title")
"Arial Bold 15"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Account link") "b" (N_ "Font info for account name")
"Arial Italic 8"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Number cell") "c" (N_ "Font info for regular number cells")
"Arial 10"))
(opt-register
(gnc:make-simple-boolean-option
(N_ "Fonts")
(N_ "Negative Values in Red") "d" (N_ "Display negative values in red.")
#t))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Number header") "e" (N_ "Font info for number headers")
"Arial 10"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Text cell") "f" (N_ "Font info for regular text cells")
"Arial 10"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Total number cell") "g" (N_ "Font info for number cells containing a total")
"Arial Bold 12"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Total label cell") "h" (N_ "Font info for cells containing total labels")
"Arial Bold 12"))
(opt-register
(gnc:make-font-option
(N_ "Fonts")
(N_ "Centered label cell") "i" (N_ "Font info for centered label cells")
"Arial Bold 12"))
(register-font-options options)
options))
(define (css-renderer options doc)
(let*
((ssdoc (gnc:make-html-document))
(opt-val
(lambda (section name)
(gnc:option-value
(gnc:lookup-option options section name))))
(bgcolor
(gnc:color-option->html
(gnc:lookup-option options
"General"
"Background Color")))
(bgpixmap (opt-val "General" "Background Pixmap"))
(links? (opt-val "General" "Enable Links"))
(spacing (opt-val "Tables" "Table cell spacing"))
(padding (opt-val "Tables" "Table cell padding"))
(border (opt-val "Tables" "Table border width"))
(negative-red? (opt-val "Fonts" "Negative Values in Red"))
(title-font-info (font-name-to-style-info (opt-val "Fonts" "Title")))
(account-link-font-info (font-name-to-style-info (opt-val "Fonts" "Account link")))
(number-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Number cell")))
(number-header-font-info (font-name-to-style-info (opt-val "Fonts" "Number header")))
(text-cell-font-info (font-name-to-style-info (opt-val "Fonts" "Text 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")))
(opt-val
(lambda (section name)
(gnc:option-value
(gnc:lookup-option options section name))))
(bgcolor
(gnc:color-option->html
(gnc:lookup-option options
"General"
"Background Color")))
(bgpixmap (opt-val "General" "Background Pixmap"))
(links? (opt-val "General" "Enable Links"))
(spacing (opt-val "Tables" "Table cell spacing"))
(padding (opt-val "Tables" "Table cell padding"))
(border (opt-val "Tables" "Table border width"))
)
(gnc:html-document-set-style!
(gnc:html-document-set-style!
ssdoc "body"
'attribute (list "bgcolor" bgcolor))
(if (and bgpixmap
(not (string=? bgpixmap "")))
(gnc:html-document-set-style!
ssdoc "body"
'attribute (list "background" bgpixmap)))
(not (string=? bgpixmap "")))
(gnc:html-document-set-style!
ssdoc "body"
'attribute (list "background" bgpixmap)))
(gnc:html-document-set-style!
ssdoc "table"
ssdoc "table"
'attribute (list "border" border)
'attribute (list "cellspacing" spacing)
'attribute (list "cellpadding" padding))
(gnc:html-document-set-style!
ssdoc "date-cell"
'tag "td"
'attribute (list "class" "date-cell"))
(gnc:html-document-set-style!
ssdoc "anchor-cell"
'tag "td"
'attribute (list "class" "anchor-cell")
'attribute (list "nowrap"))
'attribute (list "class" "anchor-cell"))
(gnc:html-document-set-style!
ssdoc "number-cell"
'tag "td"
'attribute (list "class" "number-cell")
'attribute (list "nowrap"))
'attribute (list "class" "number-cell"))
(gnc:html-document-set-style!
ssdoc "number-cell-neg"
'tag "td"
'attribute (list "class" "number-cell-neg")
'attribute (list "nowrap"))
'attribute (list "class" "number-cell neg"))
(gnc:html-document-set-style!
ssdoc "number-header"
@ -232,89 +143,73 @@
(gnc:html-document-set-style!
ssdoc "total-number-cell"
'tag "td"
'attribute (list "class" "total-number-cell")
'attribute (list "nowrap"))
'attribute (list "class" "total-number-cell"))
(gnc:html-document-set-style!
ssdoc "total-number-cell-neg"
'tag "td"
'attribute (list "class" "total-number-cell-neg")
'attribute (list "nowrap"))
'attribute (list "class" "total-number-cell neg"))
(gnc:html-document-set-style!
ssdoc "total-label-cell"
'tag "td"
'attribute (list "class" "total-label-cell"))
(gnc:html-document-set-style!
ssdoc "centered-label-cell"
'tag "td"
'attribute (list "class" "centered-label-cell"))
(gnc:html-document-set-style!
ssdoc "normal-row"
'tag "tr")
(gnc:html-document-set-style!
ssdoc "alternate-row"
'attribute (list "bgcolor" bgcolor)
'tag "tr")
'tag "tr")
(gnc:html-document-set-style!
ssdoc "primary-subheading"
'attribute (list "bgcolor" bgcolor)
'tag "tr")
'attribute (list "bgcolor" bgcolor)
'tag "tr")
(gnc:html-document-set-style!
ssdoc "secondary-subheading"
'attribute (list "bgcolor" bgcolor)
'attribute (list "bgcolor" bgcolor)
'tag "tr")
(gnc:html-document-set-style!
ssdoc "grand-total"
'attribute (list "bgcolor" bgcolor)
'attribute (list "bgcolor" bgcolor)
'tag "tr")
;; don't surround marked-up links with <a> </a>
(if (not links?)
(gnc:html-document-set-style!
ssdoc "a"
'tag ""))
(gnc:html-document-set-style-text!
ssdoc
(string-append
"h3 { " title-font-info " }\n"
"a { " account-link-font-info " }\n"
"th { text-align: right; " number-header-font-info " }\n"
"td.number-cell { text-align: right; " number-cell-font-info " }\n"
"td.number-cell-neg { text-align: right; " (if negative-red? "color: red; " "") number-cell-font-info " }\n"
"td.number-header { text-align: right; " number-header-font-info " }\n"
"td.text-cell { text-align: left; " text-cell-font-info " }\n"
"td.total-number-cell { text-align:right; " total-number-cell-font-info " }\n"
"td.total-number-cell-neg { text-align:right; " (if negative-red? "color: red; " "") total-number-cell-font-info " }\n"
"td.total-label-cell { text-align: left; " total-label-cell-font-info " }\n"
"td.centered-label-cell { text-align: center; " centered-label-cell-font-info " }\n"
))
(gnc:html-document-set-style!
ssdoc "a"
'tag ""))
(add-css-information-to-doc options ssdoc)
(let* ((title (gnc:html-document-title doc))
(doc-headline (gnc:html-document-headline doc))
(headline (if (eq? doc-headline #f)
title doc-headline)))
(if headline
(gnc:html-document-add-object!
ssdoc
(gnc:make-html-text
(gnc:html-markup-p
(gnc:html-markup-h3 headline))))))
(gnc:html-document-add-object!
ssdoc
(gnc:make-html-text
(gnc:html-markup-p
(gnc:html-markup-h3 headline))))))
(gnc:html-document-append-objects! ssdoc
(gnc:html-document-objects doc))
(gnc:html-document-objects doc))
ssdoc))
(gnc:define-html-style-sheet
(gnc:define-html-style-sheet
'version 1
'name (N_ "CSS")
'renderer css-renderer
'options-generator css-options)
;; instantiate a default style sheet
;; instantiate a default style sheet
(gnc:make-html-style-sheet "CSS" (N_ "Default CSS"))

View File

@ -172,6 +172,8 @@
(N_ "Tables")
(N_ "Table border width") "c" (N_ "Bevel depth on tables")
1 0 20 0 1))
(register-font-options options)
options))
(define (easy-renderer options doc)
@ -326,6 +328,8 @@
(if (and logopixmap (> (string-length logopixmap) 0))
(set! headcolumn 1))
(add-css-information-to-doc options ssdoc)
(let* ((title (gnc:html-document-title doc))
(doc-headline (gnc:html-document-headline doc))
(headline (if (eq? doc-headline #f) title doc-headline)))

View File

@ -166,6 +166,8 @@
(N_ "Tables")
(N_ "Table border width") "c" (N_ "Bevel depth on tables")
1 0 20 0 1))
(register-font-options options)
options))
(define (fancy-renderer options doc)
@ -306,6 +308,8 @@
(gnc:html-document-set-style!
ssdoc "a" 'tag ""))
(add-css-information-to-doc options ssdoc)
(let ((t (gnc:make-html-table)))
;; we don't want a bevel for this table, but we don't want
;; that to propagate

View File

@ -185,6 +185,8 @@
(N_ "Tables")
(N_ "Table border width") "c" (N_ "Bevel depth on tables")
1 0 20 0 1))
(register-font-options options)
options))
(define (footer-renderer options doc)
@ -306,9 +308,10 @@
;; don't surround marked-up links with <a> </a>
(if (not links?)
(gnc:html-document-set-style!
ssdoc "a" 'tag ""))
(gnc:html-document-set-style! ssdoc "a" 'tag ""))
(add-css-information-to-doc options ssdoc)
(let ((t (gnc:make-html-table)))
;; we don't want a bevel for this table, but we don't want
;; that to propagate

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; stylesheets.scm
;; load the standard report definitions
;; load the standard stylesheet definitions
;;
;; Copyright (c) 2001 Linux Developers Group, Inc.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;