This code demonstrates how to use the hyphen glyph
of a fraktur font, but obviously it breaks lilypond for
general use. But as there seems to be no reasonable
solution, it might be valuable for other people as long as
no proper solution is implemented.

cu,
 Knut
>From cf54a3b00ed03070c3a4739b0c1d528d9cd7afca Mon Sep 17 00:00:00 2001
From: Knut Petersen <[email protected]>
Date: Mon, 27 Feb 2012 00:25:13 +0100
Subject: [PATCH] quick 'n very dirty hack to allow Fraktur hyphen
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Well, I don´t know C++ and scheme, but I do know ps,
and I really needed a quick solution for my problem.

This code changes lyric-hyphen.cc to call hyphen_box
instead of round_filled_box, definition of hyphen*box is
added to a few files, and draw_hyphen_box is added to
ps/music-drawing-routines.ps. If draw_hyphen_box would
be defined to be identical to draw_round_box, lilypond
behaviour would be unchanged. Here I added the ps code
todraw the Fraktur hyphen.

Don´t ever commit that to the master repository!

Signed-off-by: Knut Petersen <[email protected]>
---
 lily/include/lookup.hh       |    1 +
 lily/lookup.cc               |   19 +++++++++++++++++++
 lily/lyric-hyphen.cc         |    2 +-
 lily/stencil-scheme.cc       |   14 ++++++++++++++
 ps/music-drawing-routines.ps |    7 +++++++
 scm/output-ps.scm            |    9 +++++++++
 scm/output-socket.scm        |    4 ++++
 scm/output-svg.scm           |   18 ++++++++++++++++++
 8 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/lily/include/lookup.hh b/lily/include/lookup.hh
index f95a7e2..dd745a8 100644
--- a/lily/include/lookup.hh
+++ b/lily/include/lookup.hh
@@ -39,6 +39,7 @@ struct Lookup
   static Stencil blank (Box b);
   static Stencil filled_box (Box b);
   static Stencil round_filled_box (Box b, Real blotdiameter);
+  static Stencil hyphen_box (Box b, Real blotdiameter);
   static Stencil repeat_slash (Real w, Real slope, Real th);
   static Stencil horizontal_line (Interval w, Real th);
   static Stencil triangle (Interval iv, Real thick, Real protrude);
diff --git a/lily/lookup.cc b/lily/lookup.cc
index f55e2f2..676a256 100644
--- a/lily/lookup.cc
+++ b/lily/lookup.cc
@@ -185,6 +185,25 @@ Lookup::round_filled_box (Box b, Real blotdiameter)
   return Stencil (b, at);
 }
 
+Stencil
+Lookup::hyphen_box (Box b, Real blotdiameter)
+{
+  if (b.x ().length () < blotdiameter)
+    blotdiameter = b.x ().length ();
+  if (b.y ().length () < blotdiameter)
+    blotdiameter = b.y ().length ();
+
+  SCM at = (scm_list_n (ly_symbol2scm ("hyphen-box"),
+                        scm_from_double (-b[X_AXIS][LEFT]),
+                        scm_from_double (b[X_AXIS][RIGHT]),
+                        scm_from_double (-b[Y_AXIS][DOWN]),
+                        scm_from_double (b[Y_AXIS][UP]),
+                        scm_from_double (blotdiameter),
+                        SCM_UNDEFINED));
+
+  return Stencil (b, at);
+}
+
 /*
  * Create Stencil that represents a filled polygon with round edges.
  *
diff --git a/lily/lyric-hyphen.cc b/lily/lyric-hyphen.cc
index 4ce2fdd..ceb6111 100644
--- a/lily/lyric-hyphen.cc
+++ b/lily/lyric-hyphen.cc
@@ -101,7 +101,7 @@ Lyric_hyphen::print (SCM smob)
   space_left = max (space_left, 0.0);
 
   Box b (Interval (0, dash_length), Interval (h, h + th));
-  Stencil dash_mol (Lookup::round_filled_box (b, 0.8 * lt));
+  Stencil dash_mol (Lookup::hyphen_box (b, 0.8 * lt));
 
   Stencil total;
   for (int i = 0; i < n; i++)
diff --git a/lily/stencil-scheme.cc b/lily/stencil-scheme.cc
index d73221f..861b170 100644
--- a/lily/stencil-scheme.cc
+++ b/lily/stencil-scheme.cc
@@ -340,6 +340,20 @@ LY_DEFINE (ly_round_filled_box, "ly:round-filled-box",
                                    scm_to_double (blot)).smobbed_copy ();
 }
 
+LY_DEFINE (ly_hyphen_box, "ly:hyphen-box",
+           3, 0, 0,
+           (SCM xext, SCM yext, SCM blot),
+           "Make a @code{Stencil} object that prints a black box of"
+           " dimensions @var{xext}, @var{yext} and roundness @var{blot}.")
+{
+  LY_ASSERT_TYPE (is_number_pair, xext, 1);
+  LY_ASSERT_TYPE (is_number_pair, yext, 2);
+  LY_ASSERT_TYPE (scm_is_number, blot, 3);
+
+  return Lookup::hyphen_box (Box (ly_scm2interval (xext), ly_scm2interval (yext)),
+                                   scm_to_double (blot)).smobbed_copy ();
+}
+
 LY_DEFINE (ly_round_filled_polygon, "ly:round-filled-polygon",
            2, 0, 0,
            (SCM points, SCM blot),
diff --git a/ps/music-drawing-routines.ps b/ps/music-drawing-routines.ps
index d7450e45..5a04573 100644
--- a/ps/music-drawing-routines.ps
+++ b/ps/music-drawing-routines.ps
@@ -116,6 +116,13 @@ bind def
 	} ifelse
 } bind def
 
+/draw_hyphen_box % width height x y blot
+{
+	/MarsFrakturOT-Normal 3.22070312 output-scale div selectfont
+	0.6146 0.0000 0.0000 /hyphen
+	1 print_glyphs
+} bind def
+
 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
 {
 	setlinewidth %set to blot
diff --git a/scm/output-ps.scm b/scm/output-ps.scm
index 7c8a6ed..204bb76 100644
--- a/scm/output-ps.scm
+++ b/scm/output-ps.scm
@@ -210,6 +210,15 @@
     (ly:format  "~4l draw_round_box"
 		(list width height x y blotdiam))))
 
+(define (hyphen-box left right bottom top blotdiam)
+  (let* ((halfblot (/ blotdiam 2))
+	 (x (- halfblot left))
+	 (width (- right (+ halfblot x)))
+	 (y (- halfblot bottom))
+	 (height (- top (+ halfblot y))))
+    (ly:format  "~4l draw_hyphen_box"
+		(list width height x y blotdiam))))
+
 ;; save current color on stack and set new color
 (define (setcolor r g b)
   (ly:format "gsave ~4l setrgbcolor\n"
diff --git a/scm/output-socket.scm b/scm/output-socket.scm
index 352ff29..0d91e96 100644
--- a/scm/output-socket.scm
+++ b/scm/output-socket.scm
@@ -89,6 +89,10 @@
   (format #f "draw_round_box ~a ~a ~a ~a ~a"
 	  breapth width depth height blot-diameter))
 
+(define (hyphen-box breapth width depth height blot-diameter)
+  (format #f "draw_round_box ~a ~a ~a ~a ~a"
+	  breapth width depth height blot-diameter))
+
 (define (utf-8-string descr string)
   (format #f "utf-8 \"~a\" \"~a\""
 	  (escape-string descr)
diff --git a/scm/output-svg.scm b/scm/output-svg.scm
index 9f10629..3ed98d6 100644
--- a/scm/output-svg.scm
+++ b/scm/output-svg.scm
@@ -599,6 +599,24 @@
     `(ry . ,(/ blot-diameter 2))
     '(fill . "currentColor")))
 
+(define (hyphen-box breapth width depth height blot-diameter)
+  (entity
+    'rect ""
+    ;; The stroke will stick out.  To use stroke,
+    ;; the stroke-width must be subtracted from all other dimensions.
+    ;;'(stroke-linejoin . "round")
+    ;;'(stroke-linecap . "round")
+    ;;`(stroke-width . ,blot)
+    ;;'(stroke . "red")
+    ;;'(fill . "orange")
+
+    `(x . ,(- breapth))
+    `(y . ,(- height))
+    `(width . ,(+ breapth width))
+    `(height . ,(+ depth height))
+    `(ry . ,(/ blot-diameter 2))
+    '(fill . "currentColor")))
+
 (define (setcolor r g b)
   (format #f "<g color=\"rgb(~a%, ~a%, ~a%)\">\n"
 	  (* 100 r) (* 100 g) (* 100 b)))
-- 
1.7.9

_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to