]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/define-stencil-commands.scm (Module): new file. Register all
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 30 May 2005 23:38:46 +0000 (23:38 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Mon, 30 May 2005 23:38:46 +0000 (23:38 +0000)
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.

ChangeLog
lily/include/stencil.hh
lily/stencil-expression.cc [new file with mode: 0644]
lily/stencil-interpret.cc [new file with mode: 0644]
lily/stencil-scheme.cc
lily/stencil.cc
scm/define-stencil-commands.scm [new file with mode: 0644]
scm/lily.scm

index 4f3c65fd7a6b57806a275ab5fb1d7a7752f7e553..12ff96a022d80f05ab773f32b6295d0d517e3eeb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 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>
index c8b6263e43ff4f63ef65561489e22c6bf8878668..2be9a3d7bbf61c9b7bcd214c99906c0d69da95af 100644 (file)
@@ -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 (file)
index 0000000..d4f5d96
--- /dev/null
@@ -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 <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;
+}
+  
diff --git a/lily/stencil-interpret.cc b/lily/stencil-interpret.cc
new file mode 100644 (file)
index 0000000..00441ee
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+  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_;
+}
index 95c4b07795787d53a562a6d3e9829d5cf582d95b..5dc0d9baab287f2cd5fbb7e0930b532709c9b34e 100644 (file)
@@ -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 ();
+}
index 221a92759fde088836f5d0233127fac975fdec9e..714d403638ae5d4bb8a8cfaaf32481bb9506f16b 100644 (file)
@@ -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 (file)
index 0000000..f7beaee
--- /dev/null
@@ -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))
index 6f6ce09b80cd530ee7462c52bbd52dd9fd9fd55a..9bc8504810e7dd9de4660fb4c5d5be5c591111f5 100644 (file)
@@ -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"