Phil Longstaff wrote:
> On July 12, 2009 07:02:18 am Chris Dennis wrote:
>> Phil Longstaff wrote:
>>> You're right that any styling can be used. What I will probably do is
>>> have 2 options pages, one for styling and one for fonts, and then
>>> combine the results. For fonts, there is a font option type which uses
>>> the font selector.
>> I avoided using the font selector in my eguile reports because of the
>> need to translate something like "URW Bookman L Bold Italic 12" into CSS
>> syntax. But I suppose that's not really too hard.
>
> Yes, this is what I do. The digits at the end of the string become
the font
> size, if "bold" is in the name, then font-weight becomes "bold", if
"italic"
> is in the name, then font-style becomes "italic". Whatever is left
becomes
> font-name.
>
> In typography, that isn't really correct (bold and italic fonts are
not really
> just modifications of the base font), but it's good enough for now.
>
> My routine is in stylesheet-css.scm, if you want to move it to some more
> central place (report-utils?) so you can use it too.
>
> Phil
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel@gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
Hello Phil
I've changed your font name routine to deal with awkward fonts such as
AR PL UMing TW MBE Light 11
Nimbus Sans L Bold Italic Condensed 11
URW Gothic L Semi-Bold 11
by using regular expressions.
The new routine is below if you want to use it. I'm planning to create
one or more modules full of useful routines for eguile reports and/or
CSS related stuff, so the font name thing could go in there eventually.
I'll try to get on to that in the next few days.
cheers
Chris
====================================================
(use-modules (ice-9 regex)) ; for regular expressions
(define (font-name-to-style-info font-name)
;;; Convert a font name as return by a font option to CSS format.
;;; e.g. 'URW Bookman L Bold Italic 12' becomes
;;; 'font: bold italic 12pt "URW Bookman L";'
(let* ((font-family "sans") ; defaults
(font-weight "normal")
(font-style "normal")
(font-size "medium")
(match "")
; (thanks to Peter Brett for this regexp and the use of
match:prefix)
(fontre (make-regexp
"([[:space:]]+(bold|semi-bold|book|regular|medium|light))?([[:space:]]+(normal|roman|italic|oblique))?([[:space:]]+(condensed))?[[:space:]]+([[:digit:]]+)"
regexp/icase))
(match (regexp-exec fontre font-name)))
(if match
(begin
; font name parsed OK -- assemble the bits for CSS
(set! font-family (match:prefix match))
(if (match:substring match 2)
; weight given -- some need translating
(let ((weight (match:substring match 2)))
(cond
((string-ci=? weight "bold") (set! font-weight "bold"))
((string-ci=? weight "semi-bold") (set! font-weight "600"))
((string-ci=? weight "light") (set! font-weight
"200")))))
(if (match:substring match 4)
; style
(let ((style (match:substring match 4)))
(cond
((string-ci=? style "italic") (set! font-style "italic"))
((string-ci=? style "oblique") (set! font-style
"oblique")))))
; ('condensed' is ignored)
(if (match:substring match 7)
; size is in points
(set! font-size (string-append (match:substring match 7)
"pt")))))
; construct the result (the order of these is important)
(string-append "font: " font-weight " " font-style " " font-size "
\"" font-family "\";")))
====================================================
--
Chris Dennis cgden...@btinternet.com
Fordingbridge, Hampshire, UK
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel