summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/fonts/source/gregoriotex/stemsschemas.py
blob: eae24cb9c4111ba215a636d769dd3e3263cc7f4c (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# This is a companion to squarize.py
# coding=utf-8

"""
    Companion to squarize.py, building the stem length config
    according to various schemas.

    Copyright (C) 2016-2021 The Gregorio Project (see CONTRIBUTORS.md)

    This file is part of Gregorio.

    Gregorio is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation, either version 3 of the License,
    or (at your option) any later version.

    Gregorio is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Gregorio.  If not, see <http://www.gnu.org/licenses/>.

    This script takes a very simple .sfd file with a few symbols and
    builds a complete square notation font. See gregorio-base.sfd for
    naming conventions of these symbols.

    To build your own font, look at gregorio-base.sfd, and build your
    own glyphs from it.

    The idea here is to return a "stem schema" describing the lengths
    of all possible stems.

    Common names of variables:
      - font_config(dict): the font configuration (ex: content of
            greciliae.json)
      - add_suppl(boolean): if we must make queues slightly longer
            than their reference height. The height difference is
            font_config[font_config['bottom-add']]
      - bmu(str): "bottom" or "middle" or "top"
      - base (int): font_config['base height']
"""

def get_default_porrectus(font_config, add_suppl, one_bottom):
    """ Common subfunction, gets porrectus length.
    """
    suppl = font_config['bottom-add'] if add_suppl else 0
    return {
        "Nothing": {
            "1": {
                "short": font_config['bottom-porrectus-1'] + suppl,
                "long": one_bottom
            },
            "2": {
                "short": font_config['bottom-porrectus-2'] + suppl,
                "long": font_config['bottom-porrectus-2'] + suppl
            },
            "3": {
                "short": font_config['bottom-porrectus-3'] + suppl,
                "long": font_config['bottom-porrectus-3'] + suppl
            },
            "4": {
                "short": font_config['bottom-porrectus-4'] + suppl,
                "long": font_config['bottom-porrectus-4'] + suppl
            },
            "5": {
                "short": font_config['bottom-porrectus-5'] + suppl,
                "long": font_config['bottom-porrectus-5'] + suppl
            }
        }
    }

def get_conf(font_config, bmu, suffix, add_suppl, second_suffix=''):
    """ Gets a value from font_config, with fallbacks if not present.
        - suffix can be 'deminutus', 'oriscus', etc.
        - second_suffix can be 'lower' or 'upper', currently handling
            quilisma only.
    """
    suffixed = bmu+'-'+suffix
    second_suffixed = bmu+'-'+suffix+'-'+second_suffix
    base = font_config[bmu]
    if second_suffixed in font_config:
        base = font_config[second_suffixed]
    elif suffixed in font_config:
        base = font_config[suffixed]
    if add_suppl and bmu == 'bottom':
        base += font_config['bottom-add']
    return base

def get_stem_schema_default(font_config):
    """ This returns Gregorio's default schema. This is adapted from
        1934 Antiphonale Monasticum (AM), with a few changes:
          - values for ancus and salicus (not present in AM)
          - more consistent short virga stems. AM has a short and
              longer form. See line 6 page 400 for both figures side
              to side. The longer form is used.
          - ih~ and similar have a slightly shorter queue (AM 400 l. 3)
          - small changes for ambitus generally, queues are slightly shorter
          - treat similar figures with consistency (gv and ge for instance)

        List of some figures in the AM:
          - ih(ih) : AM 367, 3 (p. 367, l. 3)
          - hg(hg) : AM 367,4
          - dc(dc) : AM 366
          - ed(ed) : AM 1185,5
          - ig(ig) : AM 367,6
          - fd(fd) : AM 673,1
          - gd(gd) : AM 531,3
          - he(he) : AM 420,7
          - hd(hd) : AM 1183,1
          - ih~(ih~) : AM 396,1
          - hg~(hg~) : AM 347,7
          - dc~(dc~) : AM 397,4, AM 1182,4
          - ed~(ed~) : AM 402,5
          - ge~(ge~) : AM 239,4
          - gd~(gd~) : AM 239,3
          - gc~(gc~) : AM 397,5
    """
    base = font_config['base height']
    # these are used for both virga and flexus deminutus with ambitus one, for coherence
    virga_long = get_conf(font_config, 'bottom', '', False) - 2*base
    virga_short = get_conf(font_config, 'middle', '', False) - 2*base
    virga_open = get_conf(font_config, 'bottom', '', False) - base

    def get_basic(suffix, add_suppl=False, second_suffix=''):
        """ Common function for flexus, pes quadratum, pes quassus, etc.
        """
        bottom = get_conf(font_config, 'bottom', suffix, add_suppl, second_suffix)
        middle = get_conf(font_config, 'middle', suffix, add_suppl, second_suffix)
        top = get_conf(font_config, 'top', suffix, add_suppl, second_suffix)
        # using lower version for bottom of quilisma when second is on a line
        bottom_lower = get_conf(font_config, 'bottom', suffix, add_suppl, 'lower')
        return {
            "1": {
                # ignoring the suffix for coherence
                "short": virga_short,
                "long": virga_long,
                "open": virga_open
            },
            "2": {
                "short": virga_short,
                "long": virga_long
            },
            "3": {
                "short": middle - 3*base,
                "long": bottom_lower - 3*base
            },
            "4": {
                "short": top - 4*base,
                "long": top - 4*base
            },
            "5": {
                "short": top - 4*base,
                "long": top - 4*base
            }
        }

    return {
        "ignore j": True,
        "Virga": {
            "Nothing": {
                "short": virga_short,
                "open": virga_open,
                "long": virga_long
            }
        },
        "Flexus": {
            "Nothing": get_basic(''),
            "DeminutusFirst": get_basic('deminutus-first'),
            "Deminutus": {
                "1": {
                    "short": font_config['middle'] - 2*base,
                    "long": font_config['top'] - 3*base,
                    "open": font_config['bottom-deminutus'] - base
                },
                "2": {
                    "short": font_config['bottom'] -2*base,
                    "long": font_config['bottom'] - 2*base,
                },
                "3": {
                    "long": font_config['top'] - 3*base,
                    "short": font_config['top'] - 3*base
                },
                "4": {
                    "long": font_config['top'] - 4*base,
                    "short": font_config['top-deminutus'] - 4*base,
                },
                "5": {
                    "long": font_config['top'] - 4*base,
                    "short": font_config['top-deminutus'] - 4*base,
                }
            }
        },
        "PesQuilismaQuadratum": {
            "Nothing": get_basic('quilisma', False, 'upper')
        },
        "PesQuassus": {
            "Nothing": get_basic('oriscus', False)
        },
        "Porrectus": get_default_porrectus(font_config, False, virga_long)
    }

def get_stem_schema_solesmes(font_config):
    """ This stem schema has been provided directly by a contact
        at Abbey of Solesmes.
    """
    base = font_config['base height']

    def get_bottom(suffix, add_suppl=True, second_suffix=''):
        """ Shortcut for get_config with common options
        """
        return get_conf(font_config, 'bottom', suffix, add_suppl, second_suffix)

    def get_basic(suffix, add_suppl=True, second_suffix=''):
        """ Common function for flexus, pes quadratum, pes quassus, etc.
        """
        bottom = get_bottom(suffix, add_suppl, second_suffix)
        # for ambitus one, it must have the same height as the virga for coherece, so ignoing suffix
        bottom_one = get_bottom('', True, second_suffix)
        return {
            "1": {
                "short": bottom_one - base,
                "long": bottom_one - 2*base,
                "open": bottom_one - base
            },
            "2": {
                "short": bottom - 2*base,
                "long": bottom - 2*base
            },
            "3": {
                "short": bottom - 3*base,
                "long": bottom - 3*base
            },
            "4": {
                "short": bottom - 4*base,
                "long": bottom - 4*base
            },
            "5": {
                "short": bottom - 5*base,
                "long": bottom - 5*base
            }
        }
    bottom_virga = get_bottom('')
    return {
        "ignore j": True,
        "Virga": {
            "Nothing": {
                "short": bottom_virga - base,
                "open": bottom_virga - base,
                "long": bottom_virga - 2*base
            }
        },
        "Flexus": {
            "Nothing": get_basic(''),
            "Deminutus": get_basic(''),
            "DeminutusFirst": get_basic('deminutus-first')
        },
        "PesQuilismaQuadratum": {
            "Nothing": get_basic('quilisma', False, 'lower')
        },
        "PesQuassus": {
            "Nothing": get_basic('oriscus', False)
        },
        "Porrectus": get_default_porrectus(font_config, True, bottom_virga - 2*base)
    }

def get_stem_schema(schemaname, font_config):
    """ Function called by squarize.py, returns the stem schema.
    """
    if schemaname == 'default':
        return get_stem_schema_default(font_config)
    elif schemaname == 'solesmes':
        return get_stem_schema_solesmes(font_config)
    print('impossible to find schema %s, quitting' % schemaname)