summaryrefslogtreecommitdiff
path: root/lily/percent-repeat-item.cc
blob: 5688ce5fa5841c14c7d5ea14744bf7a278b7c7e9 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*   
  percent-repeat-item.cc --  implement Percent_repeat_item_interface
  
  source file of the GNU LilyPond music typesetter
  
  (c) 2001--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
  
 */
#include <math.h>

#include "grob.hh"
#include "lookup.hh"
#include "molecule.hh"
#include "font-interface.hh"
#include "font-metric.hh" 
#include "percent-repeat-item.hh"


Molecule
Percent_repeat_item_interface::brew_slash ( Grob *me)
{
  Real slope = robust_scm2double (me->get_grob_property ("slope"), 1);
  Real wid = 2.0 / slope;

  /*
    todo: check out if in staff-rule thickness normally.
   */
  Real thick = robust_scm2double (me->get_grob_property ("thickness"), 1);
  Molecule m = Lookup::repeat_slash (wid, slope, thick);
  m.translate_axis (-m.extent (Y_AXIS).center (), Y_AXIS);
  return m;
}

/*
  todo: use grob props for dot_neg_kern, slash_neg_kern?
 */
Molecule
Percent_repeat_item_interface::x_percent (Grob *me, int count,
					  Real dot_neg_kern,
					  Real slash_neg_kern)
{
  Molecule m ;
  Molecule s = brew_slash (me);

  for (int i  = count; i--;)
    {
      m.add_at_edge (X_AXIS, RIGHT, s, -slash_neg_kern,0);
    }
  Molecule d1 = Font_interface::get_default_font (me)->find_by_name ("dots-dot");
  Molecule d2  =  d1;
  d1.translate_axis (0.5, Y_AXIS );
  d2.translate_axis (-0.5, Y_AXIS);
  
  m.add_at_edge (X_AXIS, LEFT, d1, -dot_neg_kern,0);
  m.add_at_edge (X_AXIS, RIGHT, d2, -dot_neg_kern,0);

  return m;
}

MAKE_SCHEME_CALLBACK(Percent_repeat_item_interface,double_percent,1);
SCM
Percent_repeat_item_interface::double_percent (SCM grob)
{
  Grob *me = unsmob_grob (grob);
  Molecule m = x_percent (me, 2, 0.75, 1.6);
  m.translate_axis (- m.extent (X_AXIS).center (), X_AXIS);
  return m.smobbed_copy ();
}

MAKE_SCHEME_CALLBACK(Percent_repeat_item_interface,beat_slash,1);
SCM
Percent_repeat_item_interface::beat_slash (SCM grob)
{
  Grob *me = unsmob_grob (grob);
  Molecule m = brew_slash (me);

  return m.smobbed_copy ();
}

ADD_INTERFACE (Percent_repeat_item_interface,"percent-repeat-interface",
  "Repeats that look like percent signs",
  "slope thickness");