lilypond-1.5.48
authorfred <fred>
Wed, 27 Mar 2002 02:47:37 +0000 (02:47 +0000)
committerfred <fred>
Wed, 27 Mar 2002 02:47:37 +0000 (02:47 +0000)
lily/custos.cc
lily/include/lookup.hh
lily/include/note-head.hh
lily/lookup.cc
lily/porrectus.cc
scm/ascii-script.scm
scm/pdf.scm
scm/pdftex.scm
scm/ps.scm
scm/tex.scm

index 5fc7266b18023bc998dc3b8c04ac7d04fff8f454..608f0c03795b504be69f413b9c2902b7ac0ecaa7 100644 (file)
 #include "font-interface.hh"
 #include "math.h" // rint
 
-/*
-   This function is a patched and hopefully much more understandable
-   rewrite of Note_head::ledger_line ().  It still has some
-   bugs/limitations:
- *
- (1) The term thick/2 probably should be thick*2 (probably a bug,
-   see the code below).
- *
- (2) The minimal width of the resulting ledger line equals the width
-   of the noteheads-ledgerending symbol (a limitation):
- *
- (---- left ledger ending
-     ----) right ledger ending
- (---) resulting ledger line (just ok)
- *
-   If x_extent ("xwid" in Note_head) is less than the width of the
-   ledger ending, the width of the total ledger line is even *greater*
-   than the width of a ledger ending (I would call this a bug).  In
-   the below code, the condition "if (x_extent.length () >
-   slice_x_extent.length ())" avoids outputting the left ending in such
-   cases (rather a silly workaround, but better than nothing).
- *
- (---- left ledger ending
-     ----)   right ledger ending
- (-)   desired ledger line
-     ------- resulting ledger line (too long)
-     ----)   resulting ledger line with additional "if" (still too long)
- *
-   The algorithm works properly only for a desired ledger line width
-   greater than the width of the ledger ending:
- *
- (----    left ledger ending
-        ----) right ledger ending
- (------) desired ledger line
- (------) resulting ledger line (ok)
- *
- * (3) The thickness of the ledger line is fixed (limitation).
- */
-Molecule
-Custos::create_ledger_line (Interval x_extent, Grob *me) 
-{
-  Molecule line;
-  Molecule slice = Font_interface::get_default_font (me)->find_by_name ("noteheads-ledgerending");
-  Interval slice_x_extent = slice.extent (X_AXIS);
-  Interval slice_y_extent = slice.extent (Y_AXIS);
-
-  // Create left ending of ledger line.
-  Molecule left_ending = slice;
-  left_ending.translate_axis (x_extent[LEFT] - slice_x_extent[LEFT], X_AXIS);
-  if (x_extent.length () > slice_x_extent.length ())
-    line.add_molecule (left_ending);
-
-  // Create right ending of ledger line.
-  Molecule right_ending = slice;
-  right_ending.translate_axis (x_extent[RIGHT] - slice_x_extent[RIGHT],
-                              X_AXIS);
-  line.add_molecule (right_ending);
-
-  // Fill out space between left and right ending of ledger line by
-  // lining up a series of slices in a row between them.
-  Molecule fill_out_slice = left_ending;
-  Real thick = slice_y_extent.length ();
-  Real delta_x = slice_x_extent.length () - thick;
-  Real xpos = x_extent [LEFT] + 2*delta_x + thick/2; // TODO: check: thick*2?
-  while (xpos <= x_extent[RIGHT])
-    {
-      fill_out_slice.translate_axis (delta_x, X_AXIS);
-      line.add_molecule (fill_out_slice);
-      xpos += delta_x;
-    }
-
-  return line;
-}
-
-void
-Custos::add_streepjes (Grob* me,
-                  int pos,
-                  int interspaces,
-                  Molecule* custos_p_)
-{
-  // TODO: This is (almost) duplicated code (see
-  // Note_head::brew_molecule).  Junk me.
-  Real inter_f = Staff_symbol_referencer::staff_space (me)/2;
-  int streepjes_i = abs (pos) < interspaces
-    ? 0
-    : (abs (pos) - interspaces) /2;
-  if (streepjes_i) 
-    {
-      Direction dir = (Direction)sign (pos);
-      Molecule ledger_line (create_ledger_line (custos_p_->extent (X_AXIS),
-                                               me));
-      ledger_line.set_empty (true);
-      Real offs = (Staff_symbol_referencer::on_staffline (me))
-       ? 0.0
-       : -dir * inter_f;
-      for (int i = 0; i < streepjes_i; i++)
-       {
-         Molecule streep (ledger_line);
-         streep.translate_axis (-dir * inter_f * i * 2 + offs,
-                                Y_AXIS);
-         custos_p_->add_molecule (streep);
-       }
-    }
-}
-
 MAKE_SCHEME_CALLBACK (Custos,brew_molecule,1);
 SCM
 Custos::brew_molecule (SCM smob)
@@ -147,9 +42,9 @@ Custos::brew_molecule (SCM smob)
       String style = ly_scm2string (scm_symbol_to_string (scm_style));
 
       /*
-       DOCME:
-       
-       Why would we want it differently? What's the meaning of adjust ?
+       * Shall we use a common custos font character regardless if on
+       * staffline or not, or shall we use individual font characters
+       * for both cases?
        */
       bool adjust =
        to_boolean (me->get_grob_property ("adjust-if-on-staffline"));
@@ -199,8 +94,17 @@ Custos::brew_molecule (SCM smob)
        }
       else
         {
-         add_streepjes (me, (int)pos, sz, &molecule);
-         return  molecule.smobbed_copy ();
+         // add ledger lines
+         int pos = (int)rint (Staff_symbol_referencer::position_f (me));
+         int interspaces = Staff_symbol_referencer::line_count (me)-1;
+         if (abs (pos) - interspaces > 1)
+           {
+             Molecule ledger_lines =
+               Note_head::brew_ledger_lines (me, pos, interspaces,
+                                             molecule.extent (X_AXIS), true);
+             molecule.add_molecule (ledger_lines);
+           }
+         return molecule.smobbed_copy ();
        }
     }
   else
@@ -213,7 +117,6 @@ Custos::has_interface (Grob*m)
   return m && m->has_interface (ly_symbol2scm ("custos-interface"));
 }
 
-
 ADD_INTERFACE (Custos, "custos-interface",
   "A custos is a staff context symbol that appears at the end of a
   staff line with monophonic musical contents (i.e. with a single
index 447d0e4eca136637bee867dc583aedbdf8ba01de..fca7ccea693ff45fbe48d5ff38e89830b1436556 100644 (file)
@@ -21,14 +21,15 @@ struct Lookup
   static Molecule bracket (Axis a, Interval iv, Direction d, Real thick, Real protude);
   static Molecule accordion (SCM arg, Real interline_f, Font_metric*fm);
   static Molecule frame (Box b, Real thick);
-  static Molecule slur (Bezier controls, Real cthick, Real thick) ;
-  static Molecule bezier_sandwich (Bezier, Bezier);
-  static Molecule horizontal_slope (Real, Real, Real);
-  static Molecule beam (Real, Real, Real) ;
-  static Molecule dashed_slur (Bezier, Real thick, Real dash) ;
-  static Molecule blank (Box b) ;
-  static Molecule filledbox (Box b) ;
-  static Molecule repeat_slash( Real w, Real slope, Real th);
+  static Molecule slur (Bezier controls, Real cthick, Real thick);
+  static Molecule bezier_sandwich (Bezier top_curve, Bezier bottom_curve);
+  static Molecule horizontal_slope (Real width, Real slope, Real height);
+  static Molecule beam (Real slope, Real width, Real thick);
+  static Molecule dashed_slur (Bezier, Real thick, Real dash);
+  static Molecule blank (Box b);
+  static Molecule filledbox (Box b);
+  static Molecule roundfilledbox (Box b, Real blotdiameter);
+  static Molecule repeat_slash (Real w, Real slope, Real th);
 };
 
 #endif // LOOKUP_HH
index e60679d67b6ab7007b6a34bb1f3fb4bd98149489..55a9aa0b5aaef3e8ee9e2e19f9899001342ae79a 100644 (file)
@@ -21,9 +21,9 @@ class Note_head
 {
 public:
   DECLARE_SCHEME_CALLBACK (brew_molecule, (SCM ));
-  static Interval head_extent (Grob*,Axis);
-  static Molecule ledger_lines (Grob*, bool, int,Direction,Interval);
-  static Molecule ledger_line ( Grob*, Interval);
+  static Interval head_extent (Grob*, Axis);
+  static Molecule brew_ledger_lines (Grob *me, int pos, int interspaces,
+                                    Interval x_extent, bool take_space);
   DECLARE_SCHEME_CALLBACK (brew_ez_molecule, (SCM ));
   static bool has_interface (Grob*);
   static Real stem_attachment_coordinate (Grob *, Axis a);
index 1a2c793082c3276da9d0c99c2e05492a8e80230b..f25983e47ca7c4a4ea4dd56bcc5ab2f345c860af 100644 (file)
@@ -45,7 +45,6 @@ Lookup::beam (Real slope, Real width, Real thick)
   return Molecule (b, at);
 }
 
-
 Molecule
 Lookup::dashed_slur (Bezier b, Real thick, Real dash)
 {
@@ -72,7 +71,6 @@ Lookup::blank (Box b)
   return Molecule (b, SCM_EOL);
 }
 
-
 Molecule
 Lookup::filledbox (Box b) 
 {
@@ -86,6 +84,46 @@ Lookup::filledbox (Box b)
   return Molecule (b,at);
 }
 
+/*
+ * round filled box:
+ *
+ *   __________________________
+ *  /     \  ^           /     \
+ * |         |blot              |
+ * |   +   | |dia       |   +---|------
+ * |         |meter             |     ^
+ * |\ _ _ /  v           \ _ _ /|     |
+ * |                            |     |
+ * |                            |     | Box
+ * |                    <------>|     | extent
+ * |                      blot  |     | (Y_AXIS)
+ * |                    diameter|     |
+ * |                            |     |
+ * |  _ _                  _ _  |     |
+ * |/     \              /     \|     |
+ * | (0,0)                      |     v
+ * |   x   |            |   +---|------
+ * |   |                    |   |
+ *  \__|__/______________\__|__/
+ *     |                    |
+ *     |                    |
+ *     |                    |
+ *     |<------------------>|
+ *       Box extent(X_AXIS)
+ */
+Molecule
+Lookup::roundfilledbox (Box b, Real blotdiameter)
+{
+  SCM at = (scm_list_n (ly_symbol2scm ("roundfilledbox"),
+                       gh_double2scm (-b[X_AXIS][LEFT]),
+                       gh_double2scm (b[X_AXIS][RIGHT]),
+                       gh_double2scm (-b[Y_AXIS][DOWN]),
+                       gh_double2scm (b[Y_AXIS][UP]),
+                       gh_double2scm (blotdiameter),
+                       SCM_UNDEFINED));
+
+  return Molecule (b,at);
+}
 
 Molecule
 Lookup::frame (Box b, Real thick)
@@ -112,7 +150,6 @@ Lookup::frame (Box b, Real thick)
   
 }
 
-
 /*
   Make a smooth curve along the points 
  */
@@ -460,8 +497,6 @@ Lookup::repeat_slash (Real w, Real s, Real t)
   return Molecule (b, slashnodot); //  http://slashnodot.org
 }
 
-
-
 Molecule
 Lookup::bracket (Axis a, Interval iv, Direction d, Real thick, Real protude)
 {
index d811c380c3665b77eea00481e6deb12d8c905cc8..405a567d17f78dc87581bd0a0e9c0c7d6f765ee5 100644 (file)
@@ -20,6 +20,7 @@
 #include "bezier.hh"
 #include "font-interface.hh"
 #include "paper-def.hh"
+#include "note-head.hh"
 #include "math.h" // rint
 
 void
@@ -82,75 +83,6 @@ Porrectus::get_right_head (Grob *me)
     }
 }
 
-// Uugh.  The following two functions are almost duplicated code from
-// custos.cc, which itself is similar to code in note-head.cc.  Maybe
-// this should be moved to staff-symbol-referencer.cc?
-Molecule
-Porrectus::create_ledger_line (Interval x_extent, Grob *me) 
-{
-  Molecule line;
-  Molecule slice = Font_interface::get_default_font (me)->find_by_name ("noteheads-ledgerending");
-  Interval slice_x_extent = slice.extent (X_AXIS);
-  Interval slice_y_extent = slice.extent (Y_AXIS);
-
-  // Create left ending of ledger line.
-  Molecule left_ending = slice;
-  left_ending.translate_axis (x_extent[LEFT] - slice_x_extent[LEFT], X_AXIS);
-  if (x_extent.length () > slice_x_extent.length ())
-    line.add_molecule (left_ending);
-
-  // Create right ending of ledger line.
-  Molecule right_ending = slice;
-  right_ending.translate_axis (x_extent[RIGHT] - slice_x_extent[RIGHT],
-                              X_AXIS);
-  line.add_molecule (right_ending);
-
-  // Fill out space between left and right ending of ledger line by
-  // lining up a series of slices in a row between them.
-  Molecule fill_out_slice = left_ending;
-  Real thick = slice_y_extent.length ();
-  Real delta_x = slice_x_extent.length () - thick;
-  Real xpos = x_extent [LEFT] + 2*delta_x + thick/2; // TODO: check: thick*2?
-  while (xpos <= x_extent[RIGHT])
-    {
-      fill_out_slice.translate_axis (delta_x, X_AXIS);
-      line.add_molecule (fill_out_slice);
-      xpos += delta_x;
-    }
-
-  return line;
-}
-
-Molecule
-Porrectus::create_streepjes (Grob *me,
-                            int pos,
-                            int interspaces,
-                            Interval extent)
-{
-  Real inter_f = Staff_symbol_referencer::staff_space (me)/2;
-  int streepjes_i = abs (pos) < interspaces
-    ? 0
-    : (abs (pos) - interspaces) /2;
-  Molecule molecule = Molecule();
-  if (streepjes_i) 
-    {
-      Direction dir = (Direction)sign (pos);
-      Molecule ledger_line (create_ledger_line (extent, me));
-      ledger_line.set_empty (true);
-      Real offs = (Staff_symbol_referencer::on_staffline (me, pos))
-       ? 0.0
-       : -dir * inter_f;
-      for (int i = 0; i < streepjes_i; i++)
-       {
-         Molecule streep (ledger_line);
-         streep.translate_axis (-dir * inter_f * i * 2 + offs,
-                                Y_AXIS);
-         molecule.add_molecule (streep);
-       }
-    }
-  return molecule;
-}
-
 MAKE_SCHEME_CALLBACK (Porrectus,brew_molecule,1);
 SCM 
 Porrectus::brew_molecule (SCM smob)
@@ -179,11 +111,9 @@ Porrectus::brew_molecule (SCM smob)
   bool add_stem = to_boolean (me->get_grob_property ("add-stem"));
 
   /*
-
-  TODO:
-
-  ugr. why not  called direction?
-    
+   * This property is called stem-direction (rather than direction)
+   * since it only refers to this grob's stem (or, more precisely, its
+   * "cauda"), but not the grob as a whole.
    */
   SCM stem_direction_scm = me->get_grob_property ("direction");
   Direction stem_direction =
@@ -191,7 +121,6 @@ Porrectus::brew_molecule (SCM smob)
   if (!stem_direction)
     stem_direction = DOWN;
 
-
   /*
     TODO: revise name.
    */
@@ -285,15 +214,25 @@ Porrectus::brew_molecule (SCM smob)
 
   molecule.translate_axis (left_position_f * space/2, Y_AXIS);
 
-  Molecule left_head_streepjes =
-    create_streepjes (me, (int)rint (left_position_f), interspaces, extent);
-  left_head_streepjes.translate_axis (left_position_f * space/2, Y_AXIS);
-  molecule.add_molecule (left_head_streepjes);
+  int left_pos = (int)rint (left_position_f);
+  if (abs (left_pos) - interspaces > 1)
+    {
+      Molecule left_head_ledger_lines =
+       Note_head::brew_ledger_lines (me, left_pos, interspaces, extent, true);
+      left_head_ledger_lines.translate_axis (left_position_f * space/2,
+                                            Y_AXIS);
+      molecule.add_molecule (left_head_ledger_lines);
+    }
 
-  Molecule right_head_streepjes =
-    create_streepjes (me, (int)rint (right_position_f), interspaces, extent);
-  right_head_streepjes.translate_axis (right_position_f * space/2, Y_AXIS);
-  molecule.add_molecule (right_head_streepjes);
+  int right_pos = (int)rint (right_position_f);
+  if (abs (right_pos) - interspaces > 1)
+    {
+      Molecule right_head_ledger_lines =
+       Note_head::brew_ledger_lines (me, right_pos, interspaces, extent, true);
+      right_head_ledger_lines.translate_axis (right_position_f * space/2,
+                                             Y_AXIS);
+      molecule.add_molecule (right_head_ledger_lines);
+    }
 
   return molecule.smobbed_copy();
 }
@@ -496,4 +435,3 @@ Porrectus::brew_mensural_molecule (Item *me,
 ADD_INTERFACE (Porrectus,"porrectus-interface",
   "A porrectus ligature, joining two note heads into a single grob.",
   "left-head right-head width add-stem auto-properties solid direction");
-
index 25255e3f2886171b41417498a05da2e240822ed0..dc8f8f1d2075ad427b8d2c0a4879b971b414bc25 100644 (file)
                (if (<= dy 1) "-" "="))
          (func "h-line" dx))))))
 
+(define (roundfilledbox breapth width depth height)
+  (filledbox breapth width depth height))
+
 (define (font-load-command name-mag command)
   ;; (display "name-mag: ")
   ;; (write name-mag)
index 5f022652c79213d763753105bb091db1e327af27..a47e67f4f88d4a70ff21e93e9a0ba9a1f1446f93 100644 (file)
                   (ly-number->string (+ depth height))
                   " re f "))
 
+;; TODO:
+;;
+;;(define (dot x y diam)
+;;  (let (radius (/ diam 2))
+;;    (string-append (ly-number->string (x))
+;;                  (ly-number->string (y))
+;;                  (ly-number->string (radius))
+;;                  " ??? "))) ;; how to draw a circle in PDF?
+;;
+;;(define (roundfilledbox x width y height blotdiam)
+;;  (string-append " "
+;;    (dot x y blotdiam)
+;;    (dot (+ x width) y blotdiam)
+;;    (dot (+ x width) (+ y height) blotdiam)
+;;    (dot x (+ y height) blotdiam)
+;;    (filledbox (+ x (/ blotdiam 2)) (+ width (/ blotdiam 2)) y height)
+;;    (filledbox x width (+ y (/ blotdiam 2)) (+ height (/ blotdiam 2)))))
+;;
+;;
+;; WORKAROUND:
+;;
+  (define (roundfilledbox breadth width depth height) 
+    (filledbox breadth width depth height))
+;;
+
   (define (font-def i s) "")
 
   (define (font-switch i) "")
            (define end-output ,end-output)
            (define experimental-on ,experimental-on)
            (define filledbox ,filledbox)
+           (define roundfilledbox ,roundfilledbox)
            (define font-def ,font-def)
            (define font-switch ,font-switch)
            (define header-end ,header-end)
        ((eq? action-name 'experimental-on) experimental-on)
        ((eq? action-name 'ez-ball) ez-ball)    
        ((eq? action-name 'filledbox) filledbox)
+       ((eq? action-name 'roundfilledbox) roundfilledbox)
        ((eq? action-name 'repeat-slash) repeat-slash)
        ((eq? action-name 'select-font) select-font)
        ((eq? action-name 'volta) volta)
index 6fccc24420a24fd98a4083a19c5a9a6e5df3f7a1..a40e208669ece44734e8ae389dbe1eaa714ceb93 100644 (file)
      "depth " (number->dim depth)
      "height " (number->dim height) " "))
 
+  (define (roundfilledbox x width y height blotdiam)
+    (embedded-pdf ((pdf-scm 'roundfilledbox) x width y height blotdiam)))
+
   (define (text s)
     (string-append "\\hbox{" (output-tex-string s) "}"))
   
index dbc58a79c29611015a3c1bdb4fcb15f0a2448a35..75cf347d89fa1cd3e89c7098e761c72f619b1b39 100644 (file)
   (string-append (numbers->string (list breapth width depth height))
                 " draw_box" ))
 
+(define (dot x y radius)
+    (string-append " "
+     (numbers->string
+      (list x y radius)) " draw_dot"))
+
+(define (roundfilledbox x width y height blotdiam)
+   (string-append " "
+      (dot (- 0 x) (- 0 y) (/ blotdiam 2))
+      (dot width (- 0 y) (/ blotdiam 2))
+      (dot width height (/ blotdiam 2))
+      (dot (- 0 x) height (/ blotdiam 2))
+      (filledbox (+ x (/ blotdiam 2)) (+ width (/ blotdiam 2)) y height)
+      (filledbox x width (+ y (/ blotdiam 2)) (+ height (/ blotdiam 2)))))
+
 ;; obsolete?
 (define (font-def i s)
   (string-append
 
                                        ; TODO: use HEIGHT argument
 
-  
-(define (start-line height)
+  (define (start-line height)
   (string-append
    "\n"
    (ly-number->string height)
index 2769db1cd20a963e6129039d021e713b2c794c2f..9f0e65d857b11a3a8448d0005241dd4ca3c0bba1 100644 (file)
        "depth " (number->dim depth)
        "height " (number->dim height) " ")))
 
+(define (roundfilledbox x y width height blotdiam)
+  (embedded-ps (list 'roundfilledbox  x y width height blotdiam)))
+
 (define (text s)
   (string-append "\\hbox{" (output-tex-string s) "}"))