From aa0e7e36cd892be1a1dc4162a778f20c4403f48e Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 18 Feb 2005 12:56:21 +0000 Subject: [PATCH] *** empty log message *** --- ChangeLog | 18 ++++++++++++++++++ lily/stencil.cc | 13 +++++++++++++ lily/system.cc | 17 ++++++++++++----- scm/define-grob-properties.scm | 2 ++ scm/output-lib.scm | 24 ++++++++++++++++++++++++ scm/output-ps.scm | 12 ++++++++++++ 6 files changed, 81 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64a929c38b..bf4097206c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2005-02-18 Erlend Aasland + + * input/regression/color.ly: new file + + * lily/stencil.cc (interpret_stencil_expression): + when a color expression is encountered: save current color, + process the rest of the expression, and restore previous color. + + * lily/system.cc (get_line): check all grobs for color property and + prepare the stencil scheme expressions for further processing. + Fix layer-loop. + + * scm/define-grob-properties.scm: introduce the color property. + + * scm/output-lib.scm: color helper functions. + + * scm/output-ps.scm: introduce setcolor/resetcolor. + 2005-02-07 Erik Sandberg * ly/*.ly, input/regression/*.ly: Added missing \version diff --git a/lily/stencil.cc b/lily/stencil.cc index acdfd93bfa..0301cc1f53 100644 --- a/lily/stencil.cc +++ b/lily/stencil.cc @@ -226,6 +226,19 @@ interpret_stencil_expression (SCM expr, (*func) (func_arg, scm_list_1 (ly_symbol2scm ("no-origin"))); return; } + else if (head == ly_symbol2scm ("color")) + { + SCM color = scm_cadr (expr); + SCM r = scm_car (color); + SCM g = scm_cadr (color); + SCM b = scm_caddr (color); + + (*func) (func_arg, scm_list_4 (ly_symbol2scm ("setcolor"), r, g, b)); + interpret_stencil_expression (scm_caddr (expr), func, func_arg, o); + (*func) (func_arg, scm_list_1 (ly_symbol2scm ("resetcolor"))); + + return; + } else { (*func) (func_arg, diff --git a/lily/system.cc b/lily/system.cc index 68fcc8cdc4..7b8ff68349 100644 --- a/lily/system.cc +++ b/lily/system.cc @@ -368,12 +368,10 @@ System::get_line () SCM exprs = SCM_EOL; SCM *tail = &exprs; - /* Output stencils in three layers: 0, 1, 2. Default layer: 1. - - Start with layer 3, since scm_cons prepends to list. */ + /* Output stencils in three layers: 0, 1, 2. Default layer: 1. */ SCM all = get_property ("all-elements"); - for (int i = LAYER_COUNT; i--;) + for (int i = 0; i < LAYER_COUNT; i++) for (SCM s = all; scm_is_pair (s); s = scm_cdr (s)) { Grob *g = unsmob_grob (scm_car (s)); @@ -396,7 +394,16 @@ System::get_line () Stencil st = *stil; st.translate (o + extra); - *tail = scm_cons (st.expr (), SCM_EOL); + + /* color support... see interpret_stencil_expression() for more... */ + SCM color = g->get_property ("color"); + if (color != SCM_EOL) + { + SCM tmp = scm_list_3 (ly_symbol2scm ("color"), color, st.expr ()); + *tail = scm_cons (tmp, SCM_EOL); + } + else + *tail = scm_cons (st.expr (), SCM_EOL); tail = SCM_CDRLOC(*tail); } diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 311d40fb9e..23fb59f287 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -135,6 +135,8 @@ measure of the closeness of the inner stems. It is used for damping the slope of the beam.") (collapse-height ,ly:dimension? "Minimum height of system start delimiter. If equal or smaller, the bracket is removed.") + (color ,color? "The color of this grob.") + (context ,ly:context? "Originating context of the grob") ;;DOCME diff --git a/scm/output-lib.scm b/scm/output-lib.scm index db5a1fb3b1..a9249cc173 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -262,3 +262,27 @@ centered, X==1 is at the right, X == -1 is at the left." "Shift an item to the right, but only at the start of the line." (if (and (ly:item? g) (equal? (ly:item-break-dir g) RIGHT)) (ly:grob-translate-axis! g 3.5 X))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Color + +(define-public color? list?) + +; predefined colors +(define-public black '(0.0 0.0 0.0)) +(define-public white '(1.0 1.0 1.0)) +(define-public red '(1.0 0.0 0.0)) +(define-public green '(0.0 1.0 0.0)) +(define-public blue '(0.0 0.0 1.0)) +(define-public cyan '(1.0 1.0 0.0)) +(define-public magenta '(1.0 0.0 1.0)) +(define-public yellow '(0.0 1.0 1.0)) + +(define-public grey '(0.5 0.5 0.5)) +(define-public darkred '(0.5 0.0 0.0)) +(define-public darkgreen '(0.0 0.5 0.0)) +(define-public darkblue '(0.0 0.0 0.5)) +(define-public darkcyan '(0.5 0.5 0.0)) +(define-public darkmagenta '(0.5 0.0 0.5)) +(define-public darkyellow '(0.0 0.5 0.5)) diff --git a/scm/output-ps.scm b/scm/output-ps.scm index 67042e214e..f682173e3a 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -27,6 +27,8 @@ bracket dashed-slur char + setcolor + resetcolor named-glyph dashed-line zigzag-line @@ -115,6 +117,16 @@ (ps-font-command font) " setfont " "(\\" (ly:inexact->string i 8) ") show")) +;; save current color on stack and set new color +(define (setcolor r g b) + (string-append "currentrgbcolor " + (ly:numbers->string (list r g b)) + " setrgbcolor\n")) + +;; restore color from stack +(define (resetcolor) + (string-append "setrgbcolor\n")) + (define (dashed-line thick on off dx dy) (string-append (ly:number->string dx) " " -- 2.39.5