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.
2005-05-31 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * 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 <gperlist@shaw.ca>
};
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 */
--- /dev/null
+/*
+ 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 <hanwen@xs4all.nl>
+
+*/
+
+#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;
+}
+
--- /dev/null
+/*
+ stencil-interpret.cc -- implement Stencil expression interpreting
+
+ source file of the GNU LilyPond music typesetter
+
+ (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#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_;
+}
"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 ();
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 ();
+}
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_;
-}
--- /dev/null
+
+
+;; 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))
(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))
"define-grob-properties.scm"
"define-grobs.scm"
"define-grob-interfaces.scm"
+ "define-stencil-commands.scm"
"page-layout.scm"
"titling.scm"