From e0f8a3a7b104580a401dd792357669b351c6587a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 5 Feb 2009 22:16:07 -0600 Subject: [PATCH] derive-font: output base font if font given is f --- basis/fonts/fonts.factor | 32 +++++++++++++++++------------ basis/ui/gadgets/panes/panes.factor | 13 ++++++------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/basis/fonts/fonts.factor b/basis/fonts/fonts.factor index fa139a35f2..3e6541283d 100644 --- a/basis/fonts/fonts.factor +++ b/basis/fonts/fonts.factor @@ -1,14 +1,18 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel colors accessors combinators ; +USING: kernel colors colors.constants accessors combinators ; IN: fonts -TUPLE: font name size bold? italic? foreground background ; +TUPLE: font +name +size +bold? +italic? +{ foreground initial: COLOR: black } +{ background initial: COLOR: white } ; : ( -- font ) - font new - black >>foreground - white >>background ; inline + font new ; inline : font-with-foreground ( font color -- font' ) [ clone ] dip >>foreground ; inline @@ -25,14 +29,16 @@ TUPLE: font name size bold? italic? foreground background ; [ >>background ] [ >>foreground ] bi* ; : derive-font ( base font -- font' ) - [ clone ] dip over { - [ [ name>> ] either? >>name ] - [ [ size>> ] either? >>size ] - [ [ bold?>> ] either? >>bold? ] - [ [ italic?>> ] either? >>italic? ] - [ [ foreground>> ] either? >>foreground ] - [ [ background>> ] either? >>background ] - } 2cleave ; + [ + [ clone ] dip over { + [ [ name>> ] either? >>name ] + [ [ size>> ] either? >>size ] + [ [ bold?>> ] either? >>bold? ] + [ [ italic?>> ] either? >>italic? ] + [ [ foreground>> ] either? >>foreground ] + [ [ background>> ] either? >>background ] + } 2cleave + ] when* ; : serif-font ( -- font ) diff --git a/basis/ui/gadgets/panes/panes.factor b/basis/ui/gadgets/panes/panes.factor index 0f0a102b93..cc2db3ff3b 100644 --- a/basis/ui/gadgets/panes/panes.factor +++ b/basis/ui/gadgets/panes/panes.factor @@ -179,9 +179,9 @@ M: pane-stream make-span-stream MEMO: specified-font ( assoc -- font ) #! We memoize here to avoid creating lots of duplicate font objects. - [ ] dip + [ monospace-font ] dip { - [ font-name swap at "monospace" or >>name ] + [ font-name swap at >>name ] [ font-style swap at { { f [ ] } @@ -191,10 +191,11 @@ MEMO: specified-font ( assoc -- font ) { bold-italic [ t >>bold? t >>italic? ] } } case ] - [ font-size swap at 12 or >>size ] - [ foreground swap at black or >>foreground ] - [ background swap at white or >>background ] - } cleave ; + [ font-size swap at >>size ] + [ foreground swap at >>foreground ] + [ background swap at >>background ] + } cleave + derive-font ; : apply-font-style ( style gadget -- style gadget ) { font-name font-style font-size foreground background }