From: Han-Wen Nienhuys Date: Mon, 30 May 2005 23:38:46 +0000 (+0000) Subject: * scm/define-stencil-commands.scm (Module): new file. Register all X-Git-Tag: release/2.5.27~15 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9362fc6e2a7604cbe2dd977009e687137b5ef05a;p=lilypond.git * scm/define-stencil-commands.scm (Module): new file. Register all allowed stencil expression heads in a central place. * lily/stencil-scheme.cc (LY_DEFINE): check is_stencil_head in ly:make-stencil * lily/stencil-expression.cc (all_stencil_heads): registering stencil expressions. * lily/stencil-interpret.cc: new file. Stencil expression interpreting. --- diff --git a/ChangeLog b/ChangeLog index 4f3c65fd7a..12ff96a022 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2005-05-31 Han-Wen Nienhuys + * scm/define-stencil-commands.scm (Module): new file. Register all + allowed stencil expression heads in a central place. + + * lily/stencil-scheme.cc (LY_DEFINE): check is_stencil_head in + ly:make-stencil + + * lily/stencil-expression.cc (all_stencil_heads): registering + stencil expressions. + + * lily/stencil-interpret.cc: new file. Stencil expression + interpreting. + * input/xiao-haizi-guai-guai.ly: move file back. 2005-05-30 Graham Percival diff --git a/lily/include/stencil.hh b/lily/include/stencil.hh index c8b6263e43..2be9a3d7bb 100644 --- a/lily/include/stencil.hh +++ b/lily/include/stencil.hh @@ -88,15 +88,15 @@ public: }; DECLARE_UNSMOB (Stencil, stencil); -SCM fontify_atom (Font_metric const *, SCM atom); void interpret_stencil_expression (SCM expr, void (*func) (void *, SCM), void *func_arg, Offset o); - -Stencil create_stencil (SCM print); SCM find_expression_fonts (SCM expr); +void register_stencil_head (SCM symbol); +bool is_stencil_head (SCM symbol); +SCM all_stencil_heads (); #endif /* STENCIL_HH */ diff --git a/lily/stencil-expression.cc b/lily/stencil-expression.cc new file mode 100644 index 0000000000..d4f5d96011 --- /dev/null +++ b/lily/stencil-expression.cc @@ -0,0 +1,35 @@ +/* + stencil-expression.cc -- keep track of which expressions are valid + stencil exps. + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "stencil.hh" + +#include "protected-scm.hh" + +static Protected_scm heads; + +void register_stencil_head (SCM symbol) +{ + scm_set_object_property_x (symbol, ly_symbol2scm ("stencil-head?"), SCM_BOOL_T); + heads = scm_cons (symbol, heads); + +} +bool +is_stencil_head (SCM symbol) +{ + return scm_object_property (symbol, ly_symbol2scm ("stencil-head?")) + == SCM_BOOL_T; +} + +SCM +all_stencil_heads () +{ + return heads; +} + diff --git a/lily/stencil-interpret.cc b/lily/stencil-interpret.cc new file mode 100644 index 0000000000..00441eeebc --- /dev/null +++ b/lily/stencil-interpret.cc @@ -0,0 +1,108 @@ +/* + stencil-interpret.cc -- implement Stencil expression interpreting + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "stencil.hh" + +void +interpret_stencil_expression (SCM expr, + void (*func) (void *, SCM), + void *func_arg, + Offset o) +{ + while (1) + { + if (!scm_is_pair (expr)) + return; + + SCM head = scm_car (expr); + + if (head == ly_symbol2scm ("translate-stencil")) + { + o += ly_scm2offset (scm_cadr (expr)); + expr = scm_caddr (expr); + } + else if (head == ly_symbol2scm ("combine-stencil")) + { + for (SCM x = scm_cdr (expr); scm_is_pair (x); x = scm_cdr (x)) + interpret_stencil_expression (scm_car (x), func, func_arg, o); + return; + } + else if (head == ly_symbol2scm ("grob-cause")) + { + SCM grob = scm_cadr (expr); + + (*func) (func_arg, scm_list_3 (head, + ly_quote_scm (ly_offset2scm (o)), grob)); + interpret_stencil_expression (scm_caddr (expr), func, func_arg, o); + (*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, + scm_list_4 (ly_symbol2scm ("placebox"), + scm_make_real (o[X_AXIS]), + scm_make_real (o[Y_AXIS]), + expr)); + return; + } + } +} + +struct Font_list +{ + SCM fonts_; +}; + +static void +find_font_function (void *fs, SCM x) +{ + Font_list *me = (Font_list *) fs; + + if (scm_car (x) == ly_symbol2scm ("placebox")) + { + SCM args = scm_cdr (x); + SCM what = scm_caddr (args); + + if (scm_is_pair (what)) + { + SCM head = scm_car (what); + if (ly_symbol2scm ("text") == head) + me->fonts_ = scm_cons (scm_cadr (what), me->fonts_); + else if (head == ly_symbol2scm ("char")) + me->fonts_ = scm_cons (scm_cadr (what), me->fonts_); + } + } +} + +SCM +find_expression_fonts (SCM expr) +{ + Font_list fl; + + fl.fonts_ = SCM_EOL; + + interpret_stencil_expression (expr, &find_font_function, + (void *) & fl, Offset (0, 0)); + + return fl.fonts_; +} diff --git a/lily/stencil-scheme.cc b/lily/stencil-scheme.cc index 95c4b07795..5dc0d9baab 100644 --- a/lily/stencil-scheme.cc +++ b/lily/stencil-scheme.cc @@ -221,12 +221,17 @@ LY_DEFINE (ly_make_stencil, "ly:make-stencil", "They carry two pieces of information: \n\n" "1: a specification of how to print this object. " "This specification is processed by the output backends, " - " for example @file{scm/output-tex.scm}.\n\n" + " for example @file{scm/output-ps.scm}.\n\n" "2: the vertical and horizontal extents of the object.\n\n") { + SCM_ASSERT_TYPE (!scm_is_pair (expr) + || is_stencil_head (scm_car (expr)), + expr, SCM_ARG1, __FUNCTION__, "registered stencil expression"); + SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG2, __FUNCTION__, "number pair"); SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG3, __FUNCTION__, "number pair"); - + + Box b (ly_scm2interval (xext), ly_scm2interval (yext)); Stencil s (b, expr); return s.smobbed_copy (); @@ -334,3 +339,23 @@ LY_DEFINE (ly_filled_box, "ly:round-filled-box", scm_to_double (blot)).smobbed_copy (); } + + +LY_DEFINE (ly_register_stencil_expression, "ly:register-stencil-expression", + 1, 0, 0, + (SCM symbol), + "Add @var{symbol} as head of a stencil expression") +{ + SCM_ASSERT_TYPE (scm_is_symbol (symbol), symbol, + SCM_ARG1, __FUNCTION__, "Symbol"); + register_stencil_head (symbol); + return SCM_UNSPECIFIED; +} + +LY_DEFINE (ly_all_stencil_expressions, "ly:all-stencil-expressions", + 0, 0, 0, + (), + "Return all symbols recognized as stencil expressions.") +{ + return all_stencil_heads (); +} diff --git a/lily/stencil.cc b/lily/stencil.cc index 221a92759f..714d403638 100644 --- a/lily/stencil.cc +++ b/lily/stencil.cc @@ -203,103 +203,3 @@ Stencil::in_color (Real r, Real g, Real b) const expr ())); return new_stencil; } - -/****************************************************************/ - -void -interpret_stencil_expression (SCM expr, - void (*func) (void *, SCM), - void *func_arg, - Offset o) -{ - while (1) - { - if (!scm_is_pair (expr)) - return; - - SCM head = scm_car (expr); - - if (head == ly_symbol2scm ("translate-stencil")) - { - o += ly_scm2offset (scm_cadr (expr)); - expr = scm_caddr (expr); - } - else if (head == ly_symbol2scm ("combine-stencil")) - { - for (SCM x = scm_cdr (expr); scm_is_pair (x); x = scm_cdr (x)) - interpret_stencil_expression (scm_car (x), func, func_arg, o); - return; - } - else if (head == ly_symbol2scm ("grob-cause")) - { - SCM grob = scm_cadr (expr); - - (*func) (func_arg, scm_list_3 (head, - ly_quote_scm (ly_offset2scm (o)), grob)); - interpret_stencil_expression (scm_caddr (expr), func, func_arg, o); - (*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, - scm_list_4 (ly_symbol2scm ("placebox"), - scm_make_real (o[X_AXIS]), - scm_make_real (o[Y_AXIS]), - expr)); - return; - } - } -} - -struct Font_list -{ - SCM fonts_; -}; - -static void -find_font_function (void *fs, SCM x) -{ - Font_list *me = (Font_list *) fs; - - if (scm_car (x) == ly_symbol2scm ("placebox")) - { - SCM args = scm_cdr (x); - SCM what = scm_caddr (args); - - if (scm_is_pair (what)) - { - SCM head = scm_car (what); - if (ly_symbol2scm ("text") == head) - me->fonts_ = scm_cons (scm_cadr (what), me->fonts_); - else if (head == ly_symbol2scm ("char")) - me->fonts_ = scm_cons (scm_cadr (what), me->fonts_); - } - } -} - -SCM -find_expression_fonts (SCM expr) -{ - Font_list fl; - - fl.fonts_ = SCM_EOL; - - interpret_stencil_expression (expr, &find_font_function, - (void *) & fl, Offset (0, 0)); - - return fl.fonts_; -} diff --git a/scm/define-stencil-commands.scm b/scm/define-stencil-commands.scm new file mode 100644 index 0000000000..f7beaee3a9 --- /dev/null +++ b/scm/define-stencil-commands.scm @@ -0,0 +1,41 @@ + + +;; TODO: generate this list by registering the stencil expressions +;; stencil expressions should have docstrings. +(map ly:register-stencil-expression + '(beam + bezier-sandwich + blank + bracket + char + circle + dashed-line + dashed-slur + dot + draw-line + filledbox + glyph-string + named-glyph + polygon + repeat-slash + round-filled-box + text + url-link + utf8-string + white-dot + white-text + embedded-ps + zigzag-line)) + +;; TODO: +;; - generate this list by registering the output-backend-commands +;; output-backend-commands should have docstrings. +;; - remove hard copies in output-ps output-tex + +(define-public (ly:all-output-backend-commands) + "Return list of output backend commands." + '( + grob-cause + no-origin + placebox + unknown)) diff --git a/scm/lily.scm b/scm/lily.scm index 6f6ce09b80..9bc8504810 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -151,46 +151,6 @@ predicates. Print a message at LOCATION if any predicate failed." (define-public (ps-output-expression expr port) (display (eval expr output-ps-module) port)) -;; TODO: generate this list by registering the stencil expressions -;; stencil expressions should have docstrings. -(define-public (ly:all-stencil-expressions) - "Return list of stencil expressions." - '(beam - bezier-sandwich - blank - bracket - char - circle - dashed-line - dashed-slur - dot - draw-line - filledbox - glyph-string - named-glyph - polygon - repeat-slash - round-filled-box - text - url-link - utf8-string - white-dot - white-text - embedded-ps - zigzag-line)) - -;; TODO: -;; - generate this list by registering the output-backend-commands -;; output-backend-commands should have docstrings. -;; - remove hard copies in output-ps output-tex -(define-public (ly:all-output-backend-commands) - "Return list of output backend commands." - '( - grob-cause - no-origin - placebox - unknown)) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Safe definitions utility (define safe-objects (list)) @@ -250,6 +210,7 @@ The syntax is the same as `define*-public'." "define-grob-properties.scm" "define-grobs.scm" "define-grob-interfaces.scm" + "define-stencil-commands.scm" "page-layout.scm" "titling.scm"