OLD | NEW |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1996--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 keyplacement by Mats Bengtsson | 6 keyplacement by Mats Bengtsson |
7 | 7 |
8 LilyPond is free software: you can redistribute it and/or modify | 8 LilyPond is free software: you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
10 the Free Software Foundation, either version 3 of the License, or | 10 the Free Software Foundation, either version 3 of the License, or |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 SCM c0s = me->get_property ("c0-position"); | 51 SCM c0s = me->get_property ("c0-position"); |
52 | 52 |
53 bool is_cancellation = me->internal_has_interface | 53 bool is_cancellation = me->internal_has_interface |
54 (ly_symbol2scm ("key-cancellation-interface")); | 54 (ly_symbol2scm ("key-cancellation-interface")); |
55 | 55 |
56 /* | 56 /* |
57 SCM lists are stacks, so we work from right to left, ending with | 57 SCM lists are stacks, so we work from right to left, ending with |
58 the cancellation signature. | 58 the cancellation signature. |
59 */ | 59 */ |
60 | 60 |
61 Slice pos, overlapping_pos; | 61 Slice ht_right, last_ht_left; /* ht intervals for natural glyph kerning */ |
62 SCM last_glyph_name = SCM_BOOL_F; | 62 SCM last_glyph_name = SCM_BOOL_F; |
63 SCM padding_pairs = me->get_property ("padding-pairs"); | 63 SCM padding_pairs = me->get_property ("padding-pairs"); |
64 | 64 |
65 Font_metric *fm = Font_interface::get_default_font (me); | 65 Font_metric *fm = Font_interface::get_default_font (me); |
66 SCM alist = me->get_property ("glyph-name-alist"); | 66 SCM alist = me->get_property ("glyph-name-alist"); |
67 | 67 |
68 for (SCM s = me->get_property ("alteration-alist"); scm_is_pair (s); s = scm_c
dr (s)) | 68 for (SCM s = me->get_property ("alteration-alist"); scm_is_pair (s); s = scm_c
dr (s)) |
69 { | 69 { |
70 SCM alt = is_cancellation | 70 SCM alt = is_cancellation |
71 ? scm_from_int (0) | 71 ? scm_from_int (0) |
72 : scm_cdar (s); | 72 : scm_cdar (s); |
73 | 73 |
74 SCM glyph_name_scm = ly_assoc_get (alt, alist, SCM_BOOL_F); | 74 SCM glyph_name_scm = ly_assoc_get (alt, alist, SCM_BOOL_F); |
75 if (!scm_is_string (glyph_name_scm)) | 75 if (!scm_is_string (glyph_name_scm)) |
76 { | 76 { |
77 me->warning (_f ("No glyph found for alteration: %s", | 77 me->warning (_f ("No glyph found for alteration: %s", |
78 ly_scm2rational (alt).to_string ().c_str ())); | 78 ly_scm2rational (alt).to_string ().c_str ())); |
79 continue; | 79 continue; |
80 } | 80 } |
81 | 81 |
82 string glyph_name = ly_scm2string (glyph_name_scm); | 82 string glyph_name = ly_scm2string (glyph_name_scm); |
83 | 83 |
84 Stencil acc (fm->find_by_name (glyph_name)); | 84 Stencil acc (fm->find_by_name (glyph_name)); |
85 | 85 |
86 if (acc.is_empty ()) | 86 if (acc.is_empty ()) |
87 me->warning (_ ("alteration not found")); | 87 me->warning (_ ("alteration not found")); |
88 else | 88 else |
89 { | 89 { |
90 pos.set_empty (); | 90 ht_right.set_empty (); |
91 Stencil column; | 91 Stencil column; |
92 for (SCM pos_list = Lily::key_signature_interface_alteration_positions | 92 for (SCM pos_list = Lily::key_signature_interface_alteration_positions |
93 (scm_car (s), c0s, smob); | 93 (scm_car (s), c0s, smob); |
94 scm_is_pair (pos_list); pos_list = scm_cdr (pos_list)) | 94 scm_is_pair (pos_list); pos_list = scm_cdr (pos_list)) |
95 { | 95 { |
96 int p = scm_to_int (scm_car (pos_list)); | 96 int p = scm_to_int (scm_car (pos_list)); |
97 pos.add_point (p); | 97 ht_right.add_point (2*p - 6); /* descender */ |
| 98 ht_right.add_point (2*p + 3); /* upper right corner */ |
98 column.add_stencil (acc.translated (Offset (0, p * inter))); | 99 column.add_stencil (acc.translated (Offset (0, p * inter))); |
99 } | 100 } |
100 /* | 101 /* |
101 The natural sign (unlike flat & sharp) | 102 The natural sign (unlike flat & sharp) |
102 has vertical edges on both sides. A little padding is | 103 has vertical edges on both sides. A little padding is |
103 needed to prevent collisions. | 104 needed to prevent collisions. |
104 */ | 105 */ |
105 Real padding = robust_scm2double (me->get_property ("padding"), | 106 Real padding = robust_scm2double (me->get_property ("padding"), |
106 0.0); | 107 0.0); |
107 SCM handle = scm_assoc (scm_cons (glyph_name_scm, last_glyph_name), | 108 SCM handle = scm_assoc (scm_cons (glyph_name_scm, last_glyph_name), |
108 padding_pairs); | 109 padding_pairs); |
109 if (scm_is_pair (handle)) | 110 if (scm_is_pair (handle)) |
110 padding = robust_scm2double (scm_cdr (handle), 0.0); | 111 padding = robust_scm2double (scm_cdr (handle), 0.0); |
111 else if (glyph_name == "accidentals.natural" | 112 else if (glyph_name == "accidentals.natural") |
112 && !intersection (overlapping_pos, pos).is_empty ()) | 113 if (!intersection (ht_right, last_ht_left).is_empty ()) |
113 padding += 0.3; | 114 padding += (intersection (ht_right, last_ht_left).length () |
| 115 ? 0.3 /* edges overlap */ |
| 116 : 0.15); /* just touching at the corners */ |
114 | 117 |
115 mol.add_at_edge (X_AXIS, LEFT, column, padding); | 118 mol.add_at_edge (X_AXIS, LEFT, column, padding); |
116 | 119 |
117 pos.widen (4); | 120 last_ht_left = ht_right + 3; /* shift up (change to left side) */ |
118 overlapping_pos = pos + 2; | |
119 last_glyph_name = glyph_name_scm; | 121 last_glyph_name = glyph_name_scm; |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 mol.align_to (X_AXIS, LEFT); | 125 mol.align_to (X_AXIS, LEFT); |
124 | 126 |
125 return mol.smobbed_copy (); | 127 return mol.smobbed_copy (); |
126 } | 128 } |
127 | 129 |
128 ADD_INTERFACE (Key_signature_interface, | 130 ADD_INTERFACE (Key_signature_interface, |
129 "A group of accidentals, to be printed as signature sign.", | 131 "A group of accidentals, to be printed as signature sign.", |
130 | 132 |
131 /* properties */ | 133 /* properties */ |
132 "alteration-alist " | 134 "alteration-alist " |
133 "c0-position " | 135 "c0-position " |
134 "glyph-name-alist " | 136 "glyph-name-alist " |
135 "flat-positions " | 137 "flat-positions " |
136 "sharp-positions " | 138 "sharp-positions " |
137 "padding " | 139 "padding " |
138 "padding-pairs " | 140 "padding-pairs " |
139 "non-default " | 141 "non-default " |
140 ); | 142 ); |
OLD | NEW |