| 1 |
# This is a companion to squarize.py |
| 2 |
# coding=utf-8 |
| 3 |
|
| 4 |
""" |
| 5 |
Companion to squarize.py, building the stem length config |
| 6 |
according to various schemas. |
| 7 |
|
| 8 |
Copyright (C) 2016-2025 The Gregorio Project (see CONTRIBUTORS.md) |
| 9 |
|
| 10 |
This file is part of Gregorio. |
| 11 |
|
| 12 |
Gregorio is free software: you can redistribute it and/or modify |
| 13 |
it under the terms of the GNU General Public License as published |
| 14 |
by the Free Software Foundation, either version 3 of the License, |
| 15 |
or (at your option) any later version. |
| 16 |
|
| 17 |
Gregorio is distributed in the hope that it will be useful, but |
| 18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 |
General Public License for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License |
| 23 |
along with Gregorio. If not, see <http://www.gnu.org/licenses/>. |
| 24 |
|
| 25 |
This script takes a very simple .sfd file with a few symbols and |
| 26 |
builds a complete square notation font. See gregorio-base.sfd for |
| 27 |
naming conventions of these symbols. |
| 28 |
|
| 29 |
To build your own font, look at gregorio-base.sfd, and build your |
| 30 |
own glyphs from it. |
| 31 |
|
| 32 |
The idea here is to return a "stem schema" describing the lengths |
| 33 |
of all possible stems. |
| 34 |
|
| 35 |
Common names of variables: |
| 36 |
- font_config(dict): the font configuration (ex: content of |
| 37 |
greciliae.json) |
| 38 |
- add_suppl(boolean): if we must make queues slightly longer |
| 39 |
than their reference height. The height difference is |
| 40 |
font_config[font_config['bottom-add']] |
| 41 |
- bmu(str): "bottom" or "middle" or "top" |
| 42 |
- base (int): font_config['base height'] |
| 43 |
""" |
| 44 |
|
| 45 |
def get_default_porrectus(font_config, add_suppl, one_bottom): |
| 46 |
""" Common subfunction, gets porrectus length. |
| 47 |
""" |
| 48 |
suppl = font_config['bottom-add'] if add_suppl else 0 |
| 49 |
return { |
| 50 |
"Nothing": { |
| 51 |
"1": { |
| 52 |
"short": font_config['bottom-porrectus-1'] + suppl, |
| 53 |
"long": one_bottom |
| 54 |
}, |
| 55 |
"2": { |
| 56 |
"short": font_config['bottom-porrectus-2'] + suppl, |
| 57 |
"long": font_config['bottom-porrectus-2'] + suppl |
| 58 |
}, |
| 59 |
"3": { |
| 60 |
"short": font_config['bottom-porrectus-3'] + suppl, |
| 61 |
"long": font_config['bottom-porrectus-3'] + suppl |
| 62 |
}, |
| 63 |
"4": { |
| 64 |
"short": font_config['bottom-porrectus-4'] + suppl, |
| 65 |
"long": font_config['bottom-porrectus-4'] + suppl |
| 66 |
}, |
| 67 |
"5": { |
| 68 |
"short": font_config['bottom-porrectus-5'] + suppl, |
| 69 |
"long": font_config['bottom-porrectus-5'] + suppl |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
def get_conf(font_config, bmu, suffix, add_suppl, second_suffix=''): |
| 75 |
""" Gets a value from font_config, with fallbacks if not present. |
| 76 |
- suffix can be 'deminutus', 'oriscus', etc. |
| 77 |
- second_suffix can be 'lower' or 'upper', currently handling |
| 78 |
quilisma only. |
| 79 |
""" |
| 80 |
suffixed = bmu+'-'+suffix |
| 81 |
second_suffixed = bmu+'-'+suffix+'-'+second_suffix |
| 82 |
base = font_config[bmu] |
| 83 |
if second_suffixed in font_config: |
| 84 |
base = font_config[second_suffixed] |
| 85 |
elif suffixed in font_config: |
| 86 |
base = font_config[suffixed] |
| 87 |
if add_suppl and bmu == 'bottom': |
| 88 |
base += font_config['bottom-add'] |
| 89 |
return base |
| 90 |
|
| 91 |
def get_stem_schema_default(font_config): |
| 92 |
""" This returns Gregorio's default schema. This is adapted from |
| 93 |
1934 Antiphonale Monasticum (AM), with a few changes: |
| 94 |
- values for ancus and salicus (not present in AM) |
| 95 |
- more consistent short virga stems. AM has a short and |
| 96 |
longer form. See line 6 page 400 for both figures side |
| 97 |
to side. The longer form is used. |
| 98 |
- ih~ and similar have a slightly shorter queue (AM 400 l. 3) |
| 99 |
- small changes for ambitus generally, queues are slightly shorter |
| 100 |
- treat similar figures with consistency (gv and ge for instance) |
| 101 |
|
| 102 |
List of some figures in the AM: |
| 103 |
- ih(ih) : AM 367, 3 (p. 367, l. 3) |
| 104 |
- hg(hg) : AM 367,4 |
| 105 |
- dc(dc) : AM 366 |
| 106 |
- ed(ed) : AM 1185,5 |
| 107 |
- ig(ig) : AM 367,6 |
| 108 |
- fd(fd) : AM 673,1 |
| 109 |
- gd(gd) : AM 531,3 |
| 110 |
- he(he) : AM 420,7 |
| 111 |
- hd(hd) : AM 1183,1 |
| 112 |
- ih~(ih~) : AM 396,1 |
| 113 |
- hg~(hg~) : AM 347,7 |
| 114 |
- dc~(dc~) : AM 397,4, AM 1182,4 |
| 115 |
- ed~(ed~) : AM 402,5 |
| 116 |
- ge~(ge~) : AM 239,4 |
| 117 |
- gd~(gd~) : AM 239,3 |
| 118 |
- gc~(gc~) : AM 397,5 |
| 119 |
""" |
| 120 |
base = font_config['base height'] |
| 121 |
# these are used for both virga and flexus deminutus with ambitus one, for coherence |
| 122 |
virga_long = get_conf(font_config, 'bottom', '', False) - 2*base |
| 123 |
virga_short = get_conf(font_config, 'middle', '', False) - 2*base |
| 124 |
virga_open = get_conf(font_config, 'bottom', '', False) - base |
| 125 |
|
| 126 |
def get_basic(suffix, add_suppl=False, second_suffix=''): |
| 127 |
""" Common function for flexus, pes quadratum, pes quassus, etc. |
| 128 |
""" |
| 129 |
bottom = get_conf(font_config, 'bottom', suffix, add_suppl, second_suffix) |
| 130 |
middle = get_conf(font_config, 'middle', suffix, add_suppl, second_suffix) |
| 131 |
top = get_conf(font_config, 'top', suffix, add_suppl, second_suffix) |
| 132 |
# using lower version for bottom of quilisma when second is on a line |
| 133 |
bottom_lower = get_conf(font_config, 'bottom', suffix, add_suppl, 'lower') |
| 134 |
return { |
| 135 |
"1": { |
| 136 |
# ignoring the suffix for coherence |
| 137 |
"short": virga_short, |
| 138 |
"long": virga_long, |
| 139 |
"open": virga_open |
| 140 |
}, |
| 141 |
"2": { |
| 142 |
"short": virga_short, |
| 143 |
"long": virga_long |
| 144 |
}, |
| 145 |
"3": { |
| 146 |
"short": middle - 3*base, |
| 147 |
"long": bottom_lower - 3*base |
| 148 |
}, |
| 149 |
"4": { |
| 150 |
"short": top - 4*base, |
| 151 |
"long": top - 4*base |
| 152 |
}, |
| 153 |
"5": { |
| 154 |
"short": top - 4*base, |
| 155 |
"long": top - 4*base |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
return { |
| 160 |
"ignore j": True, |
| 161 |
"Virga": { |
| 162 |
"Nothing": { |
| 163 |
"short": virga_short, |
| 164 |
"open": virga_open, |
| 165 |
"long": virga_long |
| 166 |
} |
| 167 |
}, |
| 168 |
"Flexus": { |
| 169 |
"Nothing": get_basic(''), |
| 170 |
"DeminutusFirst": get_basic('deminutus-first'), |
| 171 |
"Deminutus": { |
| 172 |
"1": { |
| 173 |
"short": font_config['middle'] - 2*base, |
| 174 |
"long": font_config['top'] - 3*base, |
| 175 |
"open": font_config['bottom-deminutus'] - base |
| 176 |
}, |
| 177 |
"2": { |
| 178 |
"short": font_config['bottom'] -2*base, |
| 179 |
"long": font_config['bottom'] - 2*base, |
| 180 |
}, |
| 181 |
"3": { |
| 182 |
"long": font_config['top'] - 3*base, |
| 183 |
"short": font_config['top'] - 3*base |
| 184 |
}, |
| 185 |
"4": { |
| 186 |
"long": font_config['top'] - 4*base, |
| 187 |
"short": font_config['top-deminutus'] - 4*base, |
| 188 |
}, |
| 189 |
"5": { |
| 190 |
"long": font_config['top'] - 4*base, |
| 191 |
"short": font_config['top-deminutus'] - 4*base, |
| 192 |
} |
| 193 |
} |
| 194 |
}, |
| 195 |
"PesQuilismaQuadratum": { |
| 196 |
"Nothing": get_basic('quilisma', False, 'upper') |
| 197 |
}, |
| 198 |
"PesQuassus": { |
| 199 |
"Nothing": get_basic('oriscus', False) |
| 200 |
}, |
| 201 |
"Porrectus": get_default_porrectus(font_config, False, virga_long) |
| 202 |
} |
| 203 |
|
| 204 |
def get_stem_schema_solesmes(font_config): |
| 205 |
""" This stem schema has been provided directly by a contact |
| 206 |
at Abbey of Solesmes. |
| 207 |
""" |
| 208 |
base = font_config['base height'] |
| 209 |
|
| 210 |
def get_bottom(suffix, add_suppl=True, second_suffix=''): |
| 211 |
""" Shortcut for get_config with common options |
| 212 |
""" |
| 213 |
return get_conf(font_config, 'bottom', suffix, add_suppl, second_suffix) |
| 214 |
|
| 215 |
def get_basic(suffix, add_suppl=True, second_suffix=''): |
| 216 |
""" Common function for flexus, pes quadratum, pes quassus, etc. |
| 217 |
""" |
| 218 |
bottom = get_bottom(suffix, add_suppl, second_suffix) |
| 219 |
# for ambitus one, it must have the same height as the virga for coherece, so ignoing suffix |
| 220 |
bottom_one = get_bottom('', True, second_suffix) |
| 221 |
return { |
| 222 |
"1": { |
| 223 |
"short": bottom_one - base, |
| 224 |
"long": bottom_one - 2*base, |
| 225 |
"open": bottom_one - base |
| 226 |
}, |
| 227 |
"2": { |
| 228 |
"short": bottom - 2*base, |
| 229 |
"long": bottom - 2*base |
| 230 |
}, |
| 231 |
"3": { |
| 232 |
"short": bottom - 3*base, |
| 233 |
"long": bottom - 3*base |
| 234 |
}, |
| 235 |
"4": { |
| 236 |
"short": bottom - 4*base, |
| 237 |
"long": bottom - 4*base |
| 238 |
}, |
| 239 |
"5": { |
| 240 |
"short": bottom - 5*base, |
| 241 |
"long": bottom - 5*base |
| 242 |
} |
| 243 |
} |
| 244 |
bottom_virga = get_bottom('') |
| 245 |
return { |
| 246 |
"ignore j": True, |
| 247 |
"Virga": { |
| 248 |
"Nothing": { |
| 249 |
"short": bottom_virga - base, |
| 250 |
"open": bottom_virga - base, |
| 251 |
"long": bottom_virga - 2*base |
| 252 |
} |
| 253 |
}, |
| 254 |
"Flexus": { |
| 255 |
"Nothing": get_basic(''), |
| 256 |
"Deminutus": get_basic(''), |
| 257 |
"DeminutusFirst": get_basic('deminutus-first') |
| 258 |
}, |
| 259 |
"PesQuilismaQuadratum": { |
| 260 |
"Nothing": get_basic('quilisma', False, 'lower') |
| 261 |
}, |
| 262 |
"PesQuassus": { |
| 263 |
"Nothing": get_basic('oriscus', False) |
| 264 |
}, |
| 265 |
"Porrectus": get_default_porrectus(font_config, True, bottom_virga - 2*base) |
| 266 |
} |
| 267 |
|
| 268 |
def get_stem_schema(schemaname, font_config): |
| 269 |
""" Function called by squarize.py, returns the stem schema. |
| 270 |
""" |
| 271 |
if schemaname == 'default': |
| 272 |
return get_stem_schema_default(font_config) |
| 273 |
if schemaname == 'solesmes': |
| 274 |
return get_stem_schema_solesmes(font_config) |
| 275 |
print(f'impossible to find schema {schemaname}, quitting') |