| 1 |
-- Copyright (C) 2006-2025 The Gregorio Project (see CONTRIBUTORS.md) |
| 2 |
-- |
| 3 |
-- This file is part of Gregorio. |
| 4 |
-- |
| 5 |
-- Gregorio is free software: you can redistribute it and/or modify |
| 6 |
-- it under the terms of the GNU General Public License as published by |
| 7 |
-- the Free Software Foundation, either version 3 of the License, or |
| 8 |
-- (at your option) any later version. |
| 9 |
-- |
| 10 |
-- Gregorio is distributed in the hope that it will be useful, |
| 11 |
-- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
-- GNU General Public License for more details. |
| 14 |
-- |
| 15 |
-- You should have received a copy of the GNU General Public License |
| 16 |
-- along with Gregorio. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
local P = lpeg.P |
| 19 |
local R = lpeg.R |
| 20 |
local C = lpeg.C |
| 21 |
|
| 22 |
local function sort_keys(table_to_sort, compare) |
| 23 |
local sorted = {}, key |
| 24 |
for key in pairs(table_to_sort) do |
| 25 |
table.insert(sorted, key) |
| 26 |
end |
| 27 |
table.sort(sorted, compare) |
| 28 |
return sorted |
| 29 |
end |
| 30 |
|
| 31 |
local function sort_unique_keys(tables, compare) |
| 32 |
local set = {}, ignored, table_to_scan, key |
| 33 |
for ignored, table_to_scan in pairs(tables) do |
| 34 |
if table_to_scan then |
| 35 |
for key in pairs(table_to_scan) do |
| 36 |
set[key] = true |
| 37 |
end |
| 38 |
end |
| 39 |
end |
| 40 |
return sort_keys(set) |
| 41 |
end |
| 42 |
|
| 43 |
local EXCLUDE = { |
| 44 |
['.notdef'] = true, |
| 45 |
['.null'] = true, |
| 46 |
notdef = true, |
| 47 |
nonmarkingreturn = true, |
| 48 |
AscendensOriscusLineBLTR = true, |
| 49 |
AscendensOriscusLineTR = true, |
| 50 |
BracketLeftZero = true, |
| 51 |
BracketLeftSix = true, |
| 52 |
BracketLeftSeven = true, |
| 53 |
BracketLeftEight = true, |
| 54 |
BracketLeftNine = true, |
| 55 |
BracketLeftTen = true, |
| 56 |
BracketLeftEleven = true, |
| 57 |
BracketLeftTwelve = true, |
| 58 |
BracketLeftThirteen = true, |
| 59 |
BracketLeftFourteen = true, |
| 60 |
BracketLeftShortZero = true, |
| 61 |
BracketLeftShortSix = true, |
| 62 |
BracketLeftShortSeven = true, |
| 63 |
BracketLeftShortEight = true, |
| 64 |
BracketLeftShortNine = true, |
| 65 |
BracketLeftShortTen = true, |
| 66 |
BracketLeftShortEleven = true, |
| 67 |
BracketLeftShortTwelve = true, |
| 68 |
BracketLeftShortThirteen = true, |
| 69 |
BracketLeftShortFourteen = true, |
| 70 |
BracketLeftLongZero = true, |
| 71 |
BracketLeftLongSix = true, |
| 72 |
BracketLeftLongSeven = true, |
| 73 |
BracketLeftLongEight = true, |
| 74 |
BracketLeftLongNine = true, |
| 75 |
BracketLeftLongTen = true, |
| 76 |
BracketLeftLongEleven = true, |
| 77 |
BracketLeftLongTwelve = true, |
| 78 |
BracketLeftLongThirteen = true, |
| 79 |
BracketLeftLongFourteen = true, |
| 80 |
BracketRightZero = true, |
| 81 |
BracketRightSix = true, |
| 82 |
BracketRightSeven = true, |
| 83 |
BracketRightEight = true, |
| 84 |
BracketRightNine = true, |
| 85 |
BracketRightTen = true, |
| 86 |
BracketRightEleven = true, |
| 87 |
BracketRightTwelve = true, |
| 88 |
BracketRightThirteen = true, |
| 89 |
BracketRightFourteen = true, |
| 90 |
BracketRightShortZero = true, |
| 91 |
BracketRightShortSix = true, |
| 92 |
BracketRightShortSeven = true, |
| 93 |
BracketRightShortEight = true, |
| 94 |
BracketRightShortNine = true, |
| 95 |
BracketRightShortTen = true, |
| 96 |
BracketRightShortEleven = true, |
| 97 |
BracketRightShortTwelve = true, |
| 98 |
BracketRightShortThirteen = true, |
| 99 |
BracketRightShortFourteen = true, |
| 100 |
BracketRightLongZero = true, |
| 101 |
BracketRightLongSix = true, |
| 102 |
BracketRightLongSeven = true, |
| 103 |
BracketRightLongEight = true, |
| 104 |
BracketRightLongNine = true, |
| 105 |
BracketRightLongTen = true, |
| 106 |
BracketRightLongEleven = true, |
| 107 |
BracketRightLongTwelve = true, |
| 108 |
BracketRightLongThirteen = true, |
| 109 |
BracketRightLongFourteen = true, |
| 110 |
PunctumAuctusLineBL = true, |
| 111 |
PunctumLineBLBR = true, |
| 112 |
PunctumLineBR = true, |
| 113 |
PunctumLineTR = true, |
| 114 |
PunctumSmall = true, |
| 115 |
FlexusLineBL = true, |
| 116 |
FlexusAmOneLineBL = true, |
| 117 |
DescendensOriscusLineTR = true, |
| 118 |
DescendensOriscusLineBLTR = true, |
| 119 |
QuilismaLineTR = true, |
| 120 |
VirgaLineBR = true, |
| 121 |
SalicusOriscus = true, |
| 122 |
VirgaBaseLineBL = true, |
| 123 |
['VirgulaTwo'] = true, |
| 124 |
['VirgulaThree'] = true, |
| 125 |
['VirgulaFive'] = true, |
| 126 |
['VirgulaSix'] = true, |
| 127 |
['VirgulaParenTwo'] = true, |
| 128 |
['VirgulaParenThree'] = true, |
| 129 |
['VirgulaParenFive'] = true, |
| 130 |
['VirgulaParenSix'] = true, |
| 131 |
['DivisioMinimisTwo'] = true, |
| 132 |
['DivisioMinimisThree'] = true, |
| 133 |
['DivisioMinimisFive'] = true, |
| 134 |
['DivisioMinimisSix'] = true, |
| 135 |
['DivisioMinimaTwo'] = true, |
| 136 |
['DivisioMinimaThree'] = true, |
| 137 |
['DivisioMinimaFive'] = true, |
| 138 |
['DivisioMinimaSix'] = true, |
| 139 |
['DivisioMinimaParenTwo'] = true, |
| 140 |
['DivisioMinimaParenThree'] = true, |
| 141 |
['DivisioMinimaParenFive'] = true, |
| 142 |
['DivisioMinimaParenSix'] = true, |
| 143 |
['DivisioMinorTwo'] = true, |
| 144 |
['DivisioMinorThree'] = true, |
| 145 |
['DivisioMinorFive'] = true, |
| 146 |
['DivisioMaiorTwo'] = true, |
| 147 |
['DivisioMaiorThree'] = true, |
| 148 |
['DivisioMaiorFive'] = true, |
| 149 |
['DivisioMaiorDottedTwo'] = true, |
| 150 |
['DivisioMaiorDottedThree'] = true, |
| 151 |
['DivisioMaiorDottedFive'] = true, |
| 152 |
['DivisioMaiorDottedBackingTwo'] = true, |
| 153 |
['DivisioMaiorDottedBackingThree'] = true, |
| 154 |
['DivisioMaiorDottedBackingFive'] = true, |
| 155 |
} |
| 156 |
|
| 157 |
-- &&& in the following two tables is a placeholder for the cavum shape 'r' |
| 158 |
|
| 159 |
local GABC = { |
| 160 |
Accentus = [[\excluded{g}r1]], |
| 161 |
AccentusReversus = [[\excluded{g}r2]], |
| 162 |
Ancus = [[g&&&ec]], |
| 163 |
AncusLongqueue = [[h&&&fd]], |
| 164 |
AscendensOriscus = [[g&&&o1]], |
| 165 |
AscendensOriscusLineBL = [[\excluded{e}@g&&&o1]], |
| 166 |
AscendensOriscusLineTL = [[\excluded{i}@g&&&o1]], |
| 167 |
AscendensOriscusScapus = [[g&&&O1]], |
| 168 |
AscendensOriscusScapusLongqueue = [[h&&&O1]], |
| 169 |
AscendensOriscusScapusOpenqueue = [[a&&&O1]], |
| 170 |
AscendensPunctumInclinatum = [[G1&&&]], |
| 171 |
AuctumMora = [[\excluded{g}.]], |
| 172 |
BarBrace = [[\excluded{,}\_]], |
| 173 |
BracketLeft = [=[[[\excluded{ce]]}]=], |
| 174 |
BracketLeftShort = [=[[[\excluded{fh]]}]=], |
| 175 |
BracketLeftLong = [=[[[\excluded{gi]]}]=], |
| 176 |
BracketRight = [=[\excluded{[[ce}]]]=], |
| 177 |
BracketRightShort = [=[\excluded{[[fh}]]]=], |
| 178 |
BracketRightLong = [=[\excluded{[[gi}]]]=], |
| 179 |
CClef = [[c3]], |
| 180 |
CClefChange = [[c3]], |
| 181 |
Circulus = [[\excluded{g}r3]], |
| 182 |
CurlyBrace = '[ocb:1;6mm]', |
| 183 |
CustosDownLong = [[j+]], |
| 184 |
CustosDownMedium = [[m+]], |
| 185 |
CustosDownShort = [[k+]], |
| 186 |
CustosUpLong = [[f+]], |
| 187 |
CustosUpMedium = [[a+]], |
| 188 |
CustosUpShort = [[g+]], |
| 189 |
DescendensOriscus = [[g&&&o0]], |
| 190 |
DescendensOriscusLineBL = [[\excluded{e}@g&&&o0]], |
| 191 |
DescendensOriscusLineTL = [[\excluded{i}@g&&&o0]], |
| 192 |
DescendensOriscusScapus = [[g&&&O0]], |
| 193 |
DescendensOriscusScapusLongqueue = [[h&&&O0]], |
| 194 |
DescendensOriscusScapusOpenqueue = [[a&&&O0]], |
| 195 |
DescendensPunctumInclinatum = [[G0&&&]], |
| 196 |
DivisioDominican = [[,3]], |
| 197 |
DivisioDominicanAlt = [[,4]], |
| 198 |
DivisioMaiorFour = [[:]], |
| 199 |
DivisioMaiorDottedFour = [[:?]], |
| 200 |
DivisioMaiorDottedBackingFour = [[\excluded{:?}]], |
| 201 |
DivisioMinimaFour = [[,]], |
| 202 |
DivisioMinimaParenFour = [[,?]], |
| 203 |
DivisioMinimisFour = [[\textasciicircum{}]], |
| 204 |
DivisioMinorFour = [[;]], |
| 205 |
FClefChange = [[f3]], |
| 206 |
FClef = [[f3]], |
| 207 |
Flat = [[gx]], |
| 208 |
FlatHole = [[\excluded{gx}]], |
| 209 |
FlatParen = [[gx?]], |
| 210 |
FlatParenHole = [[\excluded{gx?}]], |
| 211 |
Flexus = [[g&&&e]], |
| 212 |
FlexusLongqueue = [[h&&&f]], |
| 213 |
FlexusNobar = [[@h&&&f]], |
| 214 |
FlexusOriscus = [[g&&&oe]], |
| 215 |
FlexusOriscusInusitatus = [[g&&&o1e]], |
| 216 |
FlexusOriscusScapus = [[g&&&Oe]], |
| 217 |
FlexusOriscusScapusInusitatus = [[g&&&O1e]], |
| 218 |
FlexusOriscusScapusInusitatusLongqueue = [[h&&&O1f]], |
| 219 |
FlexusOriscusScapusLongqueue = [[h&&&Of]], |
| 220 |
LeadingOriscus = [[g&&&o\excluded{igig}]], |
| 221 |
LeadingPunctum = [[g&&&\excluded{igig}]], |
| 222 |
LeadingQuilisma = [[g&&&w\excluded{igig}]], |
| 223 |
Linea = [[g&&&=]], |
| 224 |
LineaPunctum = [[g&&&R]], |
| 225 |
Natural = [[gy]], |
| 226 |
NaturalHole = [[\excluded{gy}]], |
| 227 |
NaturalParen = [[gy?]], |
| 228 |
NaturalParenHole = [[\excluded{gy?}]], |
| 229 |
OblatusAscendensOriscus = [[g&&&o1]], |
| 230 |
OblatusDescendensOriscus = [[g&&&o0]], |
| 231 |
OblatusFlexusOriscus = [[g&&&oe]], |
| 232 |
OblatusFlexusOriscusInusitatus = [[g&&&o1e]], |
| 233 |
OblatusPesQuassus = [[g&&&oi]], |
| 234 |
OblatusPesQuassusLongqueue = [[h&&&oj]], |
| 235 |
OblatusPesQuassusInusitatus = [[g&&&o0i]], |
| 236 |
OblatusPesQuassusInusitatusLongqueue = [[h&&&o0j]], |
| 237 |
Oriscus = [[g&&&o]], -- for Deminutus |
| 238 |
Pes = [[g&&&i]], |
| 239 |
PesAscendensOriscus = [[g&&&iO\excluded{/j}]], |
| 240 |
PesDescendensOriscus = [[g&&&iO\excluded{/h}]], |
| 241 |
PesQuadratum = [[g&&&qi]], |
| 242 |
PesQuadratumLongqueue = [[h&&&qj]], |
| 243 |
PesQuassus = [[g&&&oi]], |
| 244 |
PesQuassusInusitatus = [[g&&&o0i]], |
| 245 |
PesQuassusInusitatusLongqueue = [[h&&&o0j]], |
| 246 |
PesQuassusLongqueue = [[h&&&oj]], |
| 247 |
PorrectusFlexus = [[g&&&ege]], |
| 248 |
PorrectusFlexusNobar = [[\excluded{e}g&&&ege]], |
| 249 |
Porrectus = [[g&&&eg]], |
| 250 |
PorrectusLongqueue = [[h&&&fh]], |
| 251 |
PorrectusNobar = [[@g&&&eg]], |
| 252 |
Punctum = [[g&&&]], |
| 253 |
PunctumInclinatum = [[G&&&]], -- for deminutus |
| 254 |
PunctumInclinatumAuctus = [[G&&&>]], |
| 255 |
PunctumLineBL = [[\excluded{e}@g&&&]], |
| 256 |
PunctumLineTL = [[\excluded{i}@g&&&]], |
| 257 |
Quilisma = [[g&&&w]], |
| 258 |
QuilismaPes = [[g&&&wi]], |
| 259 |
QuilismaPesQuadratum = [[g&&&Wi]], |
| 260 |
QuilismaPesQuadratumLongqueue = [[h&&&Wj]], |
| 261 |
RoundBraceDown = '[ub:1;6mm]', |
| 262 |
RoundBrace = '[ob:1;6mm]', |
| 263 |
SalicusFlexus = [[g&&&iOki]], |
| 264 |
Salicus = [[g&&&iOk]], |
| 265 |
SalicusLongqueue = [[h&&&jOl]], |
| 266 |
Scandicus = [[g&&&ik]], |
| 267 |
Semicirculus = [[\excluded{g}r4]], |
| 268 |
SemicirculusReversus = [[\excluded{g}r5]], |
| 269 |
Sharp = [[g\#{}]], |
| 270 |
SharpHole = [[\excluded{g\#{}}]], |
| 271 |
SharpParen = [[g\#{}?]], |
| 272 |
SharpParenHole = [[\excluded{g\#{}?}]], |
| 273 |
StansPunctumInclinatum = [[G2&&&]], |
| 274 |
StrophaAucta = [[g&&&s>]], |
| 275 |
StrophaAuctaLongtail = [[h&&&s>]], |
| 276 |
Stropha = [[g&&&s]], |
| 277 |
Torculus = [[g&&&ig]], |
| 278 |
TorculusLiquescens = [[g&&&ige]], |
| 279 |
TorculusLiquescensQuilisma = [[g&&&wige]], |
| 280 |
TorculusQuilisma = [[g&&&wig]], |
| 281 |
TorculusResupinus = [[g&&&igi]], |
| 282 |
TorculusResupinusQuilisma = [[g&&&wigi]], |
| 283 |
VEpisema = [[\excluded{g}^^^^0027]], |
| 284 |
Virga = [[g&&&v]], |
| 285 |
VirgaLongqueue = [[h&&&v]], |
| 286 |
VirgaOpenqueue = [[a&&&v]], |
| 287 |
VirgaReversa = [[g&&&V]], |
| 288 |
VirgaReversaLongqueue = [[h&&&V]], |
| 289 |
VirgaReversaOpenqueue = [[a&&&V]], |
| 290 |
VirgulaFour = [[^^^^0060]], |
| 291 |
VirgulaParenFour = [[^^^^0060?]], |
| 292 |
} |
| 293 |
|
| 294 |
local GABC_AMBITUS_ONE = { |
| 295 |
PorrectusLongqueue = [[h&&&gh]], |
| 296 |
PorrectusFlexusLongqueue = [[h&&&ghg]], |
| 297 |
FlexusOpenqueue = [[b&&&a]], |
| 298 |
FlexusOriscusScapusOpenqueue = [[b&&&Oa]], |
| 299 |
PesQuadratumOpenqueue = [[a&&&qb]], |
| 300 |
PesQuassusOpenqueue = [[a&&&ob]], |
| 301 |
QuilismaPesQuadratumOpenqueue = [[a&&&Wb]], |
| 302 |
OblatusPesQuassusInusitatusOpenqueue = [[a&&&o0b]], |
| 303 |
OblatusPesQuassusOpenqueue = [[b&&&oc]], |
| 304 |
} |
| 305 |
|
| 306 |
-- if the item is a table, the values will replace fuse_head and gabc |
| 307 |
local GABC_FUSE = { |
| 308 |
Upper = { |
| 309 |
Punctum = [[\excluded{e}@]], |
| 310 |
AscendensOriscus = [[\excluded{e}@]], |
| 311 |
DescendensOriscus = [[\excluded{e}@]], |
| 312 |
OblatusAscendensOriscus = [[\excluded{f}@]], |
| 313 |
OblatusFlexusOriscusInusitatus = [[\excluded{f}@]], |
| 314 |
OblatusPesQuassus = [[\excluded{f}@]], |
| 315 |
OblatusPesQuassusLongqueue = [[\excluded{g}@]], |
| 316 |
OblatusPesQuassusOpenqueue = [[\excluded{a}@]], |
| 317 |
Pes = [[\excluded{e}@]], |
| 318 |
PesQuadratum = [[\excluded{e}@]], |
| 319 |
PesQuadratumLongqueue = [[\excluded{f}@]], |
| 320 |
PesQuadratumOpenqueue = { [[\excluded{a}@]], [[bqc]] }, |
| 321 |
PesQuassus = [[\excluded{e}@]], |
| 322 |
PesQuassusInusitatus = [[\excluded{e}@]], |
| 323 |
PesQuassusInusitatusLongqueue = [[\excluded{f}@]], |
| 324 |
PesQuassusLongqueue = [[\excluded{f}@]], |
| 325 |
PesQuassusOpenqueue = { [[\excluded{a}@]], [[cod]] }, |
| 326 |
Flexus = [[\excluded{e}@]], |
| 327 |
FlexusOriscus = [[\excluded{e}@]], |
| 328 |
FlexusOriscusInusitatus = [[\excluded{e}@]], |
| 329 |
Virga = [[\excluded{e}@]], |
| 330 |
VirgaLongqueue = [[\excluded{f}@]], |
| 331 |
VirgaOpenqueue = { [[\excluded{a}@]], [[cv]] }, |
| 332 |
}, |
| 333 |
Lower = { |
| 334 |
Punctum = [[\excluded{i}@]], |
| 335 |
AscendensOriscus = [[\excluded{i}@]], |
| 336 |
DescendensOriscus = [[\excluded{i}@]], |
| 337 |
OblatusDescendensOriscus = [[\excluded{h}@]], |
| 338 |
OblatusFlexusOriscus = [[\excluded{h}@]], |
| 339 |
OblatusPesQuassusInusitatus = [[\excluded{h}@]], |
| 340 |
OblatusPesQuassusInusitatusLongqueue = [[\excluded{i}@]], |
| 341 |
OblatusPesQuassusInusitatusOpenqueue = [[\excluded{b}@]], |
| 342 |
Pes = [[\excluded{i}@]], |
| 343 |
PesQuadratum = [[\excluded{i}@]], |
| 344 |
PesQuadratumLongqueue = [[\excluded{j}@]], |
| 345 |
PesQuadratumOpenqueue = [[\excluded{b}@]], |
| 346 |
PesQuassus = [[\excluded{i}@]], |
| 347 |
PesQuassusInusitatus = [[\excluded{i}@]], |
| 348 |
PesQuassusInusitatusLongqueue = [[\excluded{j}@]], |
| 349 |
PesQuassusLongqueue = [[\excluded{j}@]], |
| 350 |
PesQuassusOpenqueue = [[\excluded{b}@]], |
| 351 |
Flexus = [[\excluded{i}@]], |
| 352 |
FlexusOriscus = [[\excluded{i}@]], |
| 353 |
FlexusOriscusInusitatus = [[\excluded{i}@]], |
| 354 |
}, |
| 355 |
Up = { |
| 356 |
Punctum = [[\excluded{@ij}]], |
| 357 |
AscendensOriscus = [[\excluded{@ij}]], |
| 358 |
AscendensOriscusScapus = [[\excluded{@ij}]], |
| 359 |
AscendensOriscusScapusLongqueue = [[\excluded{@jk}]], |
| 360 |
DescendensOriscus = [[\excluded{@ij}]], |
| 361 |
DescendensOriscusScapus = [[\excluded{@ij}]], |
| 362 |
DescendensOriscusScapusLongqueue = [[\excluded{@jk}]], |
| 363 |
OblatusAscendensOriscus = [[\excluded{@i}]], |
| 364 |
OblatusDescendensOriscus = [[\excluded{@i}]], |
| 365 |
Quilisma = [[\excluded{@ij}]], |
| 366 |
Flexus = [[\excluded{@gi}]], |
| 367 |
FlexusNobar = [[\excluded{@hj}]], |
| 368 |
}, |
| 369 |
Down = { |
| 370 |
Punctum = [[\excluded{@eg}]], |
| 371 |
AscendensOriscus = [[\excluded{@eg}]], |
| 372 |
AscendensOriscusScapus = [[\excluded{@eg}]], |
| 373 |
AscendensOriscusScapusLongqueue = [[\excluded{@eg}]], |
| 374 |
DescendensOriscus = [[\excluded{@eg}]], |
| 375 |
DescendensOriscusScapus = [[\excluded{@eg}]], |
| 376 |
DescendensOriscusScapusLongqueue = [[\excluded{@eg}]], |
| 377 |
OblatusAscendensOriscus = [[\excluded{@e}]], |
| 378 |
OblatusDescendensOriscus = [[\excluded{@e}]], |
| 379 |
VirgaReversa = [[\excluded{@eg}]], |
| 380 |
VirgaReversaLongqueue = [[\excluded{@fg}]], |
| 381 |
}, |
| 382 |
} |
| 383 |
|
| 384 |
local DEBILIS = { |
| 385 |
InitioDebilis = [[-]], |
| 386 |
[''] = [[]], |
| 387 |
} |
| 388 |
|
| 389 |
local LIQUESCENCE = { |
| 390 |
Ascendens = [[<]], |
| 391 |
Descendens = [[>]], |
| 392 |
Deminutus = [[\~{}]], |
| 393 |
Nothing = [[]], |
| 394 |
[''] = [[]], |
| 395 |
} |
| 396 |
|
| 397 |
GregorioRef = {} |
| 398 |
|
| 399 |
function GregorioRef.emit_score_glyphs(cs_normal, cs_hollow) |
| 400 |
local common_glyphs = {} |
| 401 |
local normal_variants = {} |
| 402 |
local normal_names = {} |
| 403 |
local hollow_variants = {} |
| 404 |
local hollow_names = {} |
| 405 |
|
| 406 |
local function index_font(csname, variants, names, common) |
| 407 |
local glyphs = font.fonts[font.id(csname)].resources.unicodes |
| 408 |
-- force-load the code points of the font -- |
| 409 |
local ignored = glyphs['___magic___'] |
| 410 |
local glyph, cp |
| 411 |
for glyph, cp in pairs(glyphs) do |
| 412 |
names[glyph] = true |
| 413 |
if cp >= 0xe000 and not EXCLUDE[glyph] and not glyph:match('^HEpisema') then |
| 414 |
local name, variant = glyph:match('^([^.]*)(%.%a*)$') |
| 415 |
if name then |
| 416 |
local glyph_variants = variants[name] |
| 417 |
if glyph_variants == nil then |
| 418 |
glyph_variants = {} |
| 419 |
variants[name] = glyph_variants |
| 420 |
end |
| 421 |
glyph_variants[variant] = cp |
| 422 |
elseif common then |
| 423 |
common[glyph] = cp |
| 424 |
end |
| 425 |
end |
| 426 |
end |
| 427 |
end |
| 428 |
|
| 429 |
index_font(cs_normal, normal_variants, normal_names, common_glyphs) |
| 430 |
index_font(cs_hollow, hollow_variants, hollow_names, common_glyphs) |
| 431 |
|
| 432 |
local function maybe_emit_glyph(csname, variants, name, variant) |
| 433 |
local cp = variants[name] |
| 434 |
if cp then |
| 435 |
cp = cp[variant] |
| 436 |
if cp then |
| 437 |
tex.sprint(string.format([[&{\%s\char%d}]], csname, cp)) |
| 438 |
end |
| 439 |
end |
| 440 |
if not cp then |
| 441 |
tex.sprint(string.format([[&{\tiny\itshape N/A}]], csname, cp)) |
| 442 |
end |
| 443 |
end |
| 444 |
|
| 445 |
local function emit_score_glyph(fusion, shape, ambitus, debilis, liquescence) |
| 446 |
local name = fusion..shape..ambitus..debilis..liquescence |
| 447 |
local char = common_glyphs[name] |
| 448 |
local gabc = GABC[shape] or GABC_AMBITUS_ONE[shape] |
| 449 |
if gabc then |
| 450 |
local fuse_head = '' |
| 451 |
local fuse_tail = '' |
| 452 |
if fusion ~= '' then |
| 453 |
fuse_head = GABC_FUSE[fusion][shape] |
| 454 |
if fuse_head == nil then |
| 455 |
tex.error('No head fusion for '..name) |
| 456 |
end |
| 457 |
if type(fuse_head) == 'table' then |
| 458 |
fuse_head, gabc = fuse_head[1], fuse_head[2] |
| 459 |
end |
| 460 |
end |
| 461 |
local liq = liquescence |
| 462 |
if liq == 'Up' or liq == 'Down' then |
| 463 |
fuse_tail = GABC_FUSE[liq][shape] |
| 464 |
if fuse_tail == nil then |
| 465 |
tex.error('No tail fusion for '..name) |
| 466 |
end |
| 467 |
liq = '' |
| 468 |
end |
| 469 |
gabc = '('..fuse_head..DEBILIS[debilis]..gabc..LIQUESCENCE[liq]..fuse_tail..')' |
| 470 |
else |
| 471 |
texio.write_nl('GregorioRef Warning: missing GABC for '..name) |
| 472 |
end |
| 473 |
local sorted_normal = sort_unique_keys{normal_variants[name]} |
| 474 |
local sorted_hollow = sort_unique_keys{hollow_variants[name]} |
| 475 |
local n = math.max(1, #sorted_normal, #sorted_hollow) |
| 476 |
local emitted = false, i, variant |
| 477 |
for i = 1,n do |
| 478 |
if emitted then |
| 479 |
tex.sprint([[\nopagebreak&&&]]) |
| 480 |
else |
| 481 |
tex.sprint(string.format( |
| 482 |
[[{%s\scriptsize %s{\bfseries %s}{\itshape %s}%s%s}&{\ttfamily\small %s}&{\%s\char%d}&]], |
| 483 |
gabc and [[]] or [[\color{red}]], |
| 484 |
fusion, shape, ambitus, debilis, liquescence, |
| 485 |
gabc and gabc:gsub('&&&', '') or '', cs_normal, char |
| 486 |
)) |
| 487 |
end |
| 488 |
variant = sorted_normal[i] |
| 489 |
if variant then |
| 490 |
tex.sprint(string.format([[{\scriptsize %s}]], variant)) |
| 491 |
maybe_emit_glyph(cs_normal, normal_variants, name, variant) |
| 492 |
else |
| 493 |
tex.print([[&]]) |
| 494 |
end |
| 495 |
if emitted or not hollow_names[name] then |
| 496 |
tex.sprint([[&&&]]) |
| 497 |
else |
| 498 |
tex.sprint(string.format( |
| 499 |
[[&{\ttfamily\small %s}&{\%s\char%d}&]], |
| 500 |
gabc and gabc:gsub('&&&', 'r') or '', cs_hollow, char |
| 501 |
)) |
| 502 |
end |
| 503 |
variant = sorted_hollow[i] |
| 504 |
if variant then |
| 505 |
tex.sprint(string.format([[{\scriptsize %s}]], variant)) |
| 506 |
maybe_emit_glyph(cs_hollow, hollow_variants, name, variant) |
| 507 |
else |
| 508 |
tex.print([[&]]) |
| 509 |
end |
| 510 |
tex.print([[\\]]) |
| 511 |
emitted = true |
| 512 |
end |
| 513 |
end |
| 514 |
|
| 515 |
local glyph_names = {} |
| 516 |
local ambitus = P'One' + P'Two' + P'Three' + P'Four' + P'Five' |
| 517 |
local majuscule = R'AZ' |
| 518 |
local minuscule = R'az' |
| 519 |
local fusion = P'Upper' + P'Lower' |
| 520 |
local debilis = P'InitioDebilis' |
| 521 |
local post_word_liquescentia = P'Nothing' + P'Deminutus' + P'Ascendens' + |
| 522 |
P'Descendens' |
| 523 |
local liquescentia = post_word_liquescentia + P'Up' + P'Down' |
| 524 |
local word = ((majuscule * minuscule^0) - fusion - ambitus - debilis - |
| 525 |
post_word_liquescentia) + ((P'Ascendens' + P'Descendens') * P'Oriscus') |
| 526 |
local liquescence = debilis^-1 * liquescentia^-1 |
| 527 |
local pattern = C(fusion^-1) * C(word^1) * C(ambitus^0) * C(debilis^-1) * |
| 528 |
C(liquescentia^-1) * -1 |
| 529 |
local only_twos = P'Two'^1 * -1 |
| 530 |
local ambitus_one = P'One' * P'Two'^0 * -1 |
| 531 |
for name in pairs(common_glyphs) do |
| 532 |
local a, b, c, d, e = pattern:match(name) |
| 533 |
if b then |
| 534 |
table.insert(glyph_names, { a, b, c, d, e }) |
| 535 |
else |
| 536 |
-- if parse fails, just use the name |
| 537 |
table.insert(glyph_names, { '', name, '', '', '' }) |
| 538 |
end |
| 539 |
end |
| 540 |
local function compare(x, y) |
| 541 |
local nx = x[1]..x[2] |
| 542 |
local ny = y[1]..y[2] |
| 543 |
if nx < ny then |
| 544 |
return true |
| 545 |
elseif nx == ny then |
| 546 |
if x[4] < y[4] then |
| 547 |
return true |
| 548 |
elseif x[4] == y[4] then |
| 549 |
if x[5] < y[5] then |
| 550 |
return true |
| 551 |
elseif x[5] == y[5] and x[3] < y[3] then |
| 552 |
return true |
| 553 |
end |
| 554 |
end |
| 555 |
end |
| 556 |
return false |
| 557 |
end |
| 558 |
table.sort(glyph_names, compare) |
| 559 |
local first = true |
| 560 |
local i, name |
| 561 |
for i, name in ipairs(glyph_names) do |
| 562 |
local shape = name[2] |
| 563 |
local ambitus = name[3] |
| 564 |
if shape:match('^Virgula') or shape:match('^Divisio') then |
| 565 |
shape = shape..ambitus |
| 566 |
ambitus = '' |
| 567 |
end |
| 568 |
if not EXCLUDE[shape] then |
| 569 |
if (ambitus == '' and name[5] == '') or ambitus == '' or only_twos:match(ambitus) |
| 570 |
or (GABC_AMBITUS_ONE[shape] and ambitus_one:match(ambitus)) then |
| 571 |
if first then |
| 572 |
first = false |
| 573 |
else |
| 574 |
tex.print([[\hline]]) |
| 575 |
end |
| 576 |
emit_score_glyph(name[1], shape, ambitus, name[4], name[5]) |
| 577 |
end |
| 578 |
end |
| 579 |
end |
| 580 |
end |
| 581 |
|
| 582 |
function GregorioRef.emit_extra_glyphs(csname) |
| 583 |
local glyphs = font.fonts[font.id(csname)].resources.unicodes |
| 584 |
local first = true |
| 585 |
local odd = true |
| 586 |
for i, name in ipairs(sort_keys(glyphs)) do |
| 587 |
local cp = glyphs[name] |
| 588 |
if cp >= 0xe000 and not EXCLUDE[name] then |
| 589 |
if first then |
| 590 |
first = false |
| 591 |
elseif odd then |
| 592 |
tex.print([[\hline]]) |
| 593 |
end |
| 594 |
tex.sprint(string.format([[{\scriptsize %s}&{\%s\char%d}]], name, csname, cp)) |
| 595 |
if odd then |
| 596 |
tex.sprint([[&]]) |
| 597 |
else |
| 598 |
tex.print([[\\]]) |
| 599 |
end |
| 600 |
odd = not odd |
| 601 |
end |
| 602 |
end |
| 603 |
if not odd then |
| 604 |
tex.print([[&\\]]) |
| 605 |
end |
| 606 |
end |
| 607 |
|
| 608 |
function GregorioRef.emit_dimension(value) |
| 609 |
value = string.gsub(value, '(-?%d+%.%d+)%s*(%a+)', [[\unit[%1]{%2}]]) |
| 610 |
value = string.gsub(value, '(-?%d+%.)%s*(%a+)', [[\unit[%1]{%2}]]) |
| 611 |
value = string.gsub(value, '(-?%.?%d+)%s*(%a+)', [[\unit[%1]{%2}]]) |
| 612 |
tex.sprint(value) |
| 613 |
end |