Debian Codegraph @

sources/trim_kerning.py

raw symbols SCIP
1 # This script is for deleting kerning pairs that can't or shouldn't occur
2 # together. 1. where runes are kerned with Latin letters. This can occur, but
3 # so rarely that it makes no sense to devote any file space to such pairs.
4 # 2. small caps with lowercase letters. When these occur, there will almost
5 # always be a formatting boundary between them, so kerning won't be done.
6 # This script will remove somewhere between 2000 and 4000 kerning pairs.
7 # Copy this into the Glyphs macro panel and run immediately after running
8 # Kern On. (Don't forget to change the "italic" variable near the bottom of
9 # the script, if necessary)
10
11 lowercase = [
12 "uniA7C1",
13 "gormulum",
14 "uniA7D3",
15 "uniA7D5",
16 "Bsmall",
17 "Gsmall",
18 "Gsmallhook",
19 "Hsmall",
20 "Ismall",
21 "Lsmall",
22 "Nsmall",
23 "OEsmall",
24 "Rsmall",
25 "Rsmallinverted",
26 "Ysmall",
27 "a",
28 "aa",
29 "aacute",
30 "abreve",
31 "abreveacute",
32 "abrevedotbelow",
33 "abrevegrave",
34 "abrevehookabove",
35 "abrevetilde",
36 "acircumflex",
37 "acircumflexacute",
38 "acircumflexdotbelow",
39 "acircumflexgrave",
40 "acircumflexhookabove",
41 "acircumflextilde",
42 "adieresis",
43 "adotbelow",
44 "agrave",
45 "ahookabove",
46 "alpha-latin",
47 "alphaturned-latin",
48 "amacron",
49 "ao",
50 "aogonek",
51 "aring",
52 "aringacute",
53 "atilde",
54 "aturned",
55 "au",
56 "av",
57 "avbar",
58 "ay",
59 "ae",
60 "aeacute",
61 "uni01E3",
62 "b",
63 "bhook",
64 "bidentalpercussive",
65 "bilabialclick",
66 "bilabialpercussive",
67 "bstroke",
68 "c",
69 "cacute",
70 "ccaron",
71 "ccedilla",
72 "ccurl",
73 "cdotaccent",
74 "con",
75 "cstretched",
76 "d",
77 "eth",
78 "dcaron",
79 "dcroat",
80 "dezh",
81 "dhook",
82 "dinsular",
83 "dtail",
84 "dzaltone",
85 "dzcurl",
86 "e",
87 "eacute",
88 "ebreve",
89 "ecaron",
90 "ecircumflex",
91 "ecircumflexacute",
92 "ecircumflexdotbelow",
93 "ecircumflexgrave",
94 "ecircumflexhookabove",
95 "ecircumflextilde",
96 "edieresis",
97 "edotaccent",
98 "edotbelow",
99 "egrave",
100 "ehookabove",
101 "emacron",
102 "eogonek",
103 "eopen",
104 "eopenreversed",
105 "eopenreversedclosed",
106 "eopenreversedhook",
107 "ereversed",
108 "esh",
109 "eshcurl",
110 "eshsquatreversed",
111 "etabbrev",
112 "etilde",
113 "schwa",
114 "schwahook",
115 "ezh",
116 "ezhcurl",
117 "f",
118 "fengdigraph",
119 "finsular",
120 "g",
121 "gamma-latin",
122 "gcommaaccent",
123 "gdotaccent",
124 "ghook",
125 "ginsular",
126 "glottalstop",
127 "glottalstopinverted",
128 "glottalstopreversed",
129 "glottalstopstroke",
130 "glottalstopstrokereversed",
131 "gsingle",
132 "yogh",
133 "h",
134 "hbar",
135 "henghook",
136 "hhook",
137 "hturned",
138 "hturnedfishhook",
139 "hturnedfishhookandtail",
140 "hv",
141 "i",
142 "dotlessi",
143 "iacute",
144 "ibreve",
145 "icircumflex",
146 "idieresis",
147 "idotbelow",
148 "igrave",
149 "ihookabove",
150 "ij",
151 "imacron",
152 "iogonek",
153 "is",
154 "istroke",
155 "itilde",
156 "j",
157 "jdotless",
158 "jcrossedtail",
159 "jdotlessstroke",
160 "jdotlessstrokehook",
161 "k",
162 "kcommaaccent",
163 "kstroke",
164 "l",
165 "lacute",
166 "lbar",
167 "lbelt",
168 "lcaron",
169 "lcommaaccent",
170 "lezh",
171 "lhighstroke",
172 "lhookretroflex",
173 "lmiddletilde",
174 "longsdiagonalstroke",
175 "lsdigraph",
176 "lslash",
177 "lzdigraph",
178 "m",
179 "mhook",
180 "mlonglegturned",
181 "mturned",
182 "n",
183 "nacute",
184 "ncaron",
185 "ncommaaccent",
186 "nhookleft",
187 "nhookretroflex",
188 "ntilde",
189 "eng",
190 "o",
191 "oacute",
192 "obarred",
193 "obreve",
194 "ocircumflex",
195 "ocircumflexacute",
196 "ocircumflexdotbelow",
197 "ocircumflexgrave",
198 "ocircumflexhookabove",
199 "ocircumflextilde",
200 "odieresis",
201 "odotbelow",
202 "ograve",
203 "ohookabove",
204 "ohorn",
205 "ohornacute",
206 "ohorndotbelow",
207 "ohorngrave",
208 "ohornhookabove",
209 "ohorntilde",
210 "ohungarumlaut",
211 "olongstroke",
212 "omacron",
213 "oo",
214 "oogonek",
215 "oopen",
216 "oslash",
217 "oslashacute",
218 "otilde",
219 "oe",
220 "p",
221 "pflourish",
222 "phi-latin",
223 "thorn",
224 "pstrokethroughdescender",
225 "q",
226 "qdiagonalstroke",
227 "qhook",
228 "qstrokethroughdescender",
229 "r",
230 "racute",
231 "ramshorn",
232 "rcaron",
233 "rcommaaccent",
234 "rfishhook",
235 "rfishhookreversed",
236 "rhookturned",
237 "rinsular",
238 "rlonglegturned",
239 "rrotunda",
240 "rtail",
241 "rturned",
242 "rumrotunda",
243 "s",
244 "sacute",
245 "scaron",
246 "scedilla",
247 "germandbls",
248 "shook",
249 "sinsular",
250 "longs",
251 "t",
252 "tbar",
253 "tcaron",
254 "tccurl",
255 "tcedilla",
256 "tesh",
257 "thorncrossed",
258 "tinsular",
259 "tretroflexhook",
260 "ts",
261 "tturned",
262 "u",
263 "uacute",
264 "ubar",
265 "ubreve",
266 "ucircumflex",
267 "udieresis",
268 "udotbelow",
269 "ugrave",
270 "uhookabove",
271 "uhorn",
272 "uhornacute",
273 "uhorndotbelow",
274 "uhorngrave",
275 "uhornhookabove",
276 "uhorntilde",
277 "uhungarumlaut",
278 "umacron",
279 "uogonek",
280 "upsilon-latin",
281 "uring",
282 "utilde",
283 "v",
284 "vhook",
285 "vrighthook",
286 "vturned",
287 "w",
288 "wacute",
289 "wcircumflex",
290 "wdieresis",
291 "wgrave",
292 "wturned",
293 "wy",
294 "wynn",
295 "x",
296 "y",
297 "yacute",
298 "ycircumflex",
299 "ydieresis",
300 "ydotaccent",
301 "ydotbelow",
302 "ygrave",
303 "yhookabove",
304 "ymacron",
305 "ytilde",
306 "yturned",
307 "z",
308 "zacute",
309 "zcaron",
310 "zcurl",
311 "zdotaccent",
312 "zretroflexhook",
313 "zstroke",
314 "d.alt",
315 "dinsular.alt",
316 "f.alt",
317 "g.alt",
318 "i.alt",
319 "p.alt",
320 "r.alt",
321 "rrotunda.alt",
322 "s.alt",
323 "longs.alt",
324 "f.alt2",
325 "longs.alt2",
326 "a.ipa",
327 "b.lf",
328 "f.lf",
329 "h.lf",
330 "k.lf",
331 "l.lf",
332 "thorn.lf",
333 "f.lfrl",
334 "f.lfrtall",
335 "i.llongs",
336 "j.llongs",
337 "longs.llongs",
338 "longs.llongsrij",
339 "longs.llongsrtall",
340 "eth.loclENG",
341 "thorn.loclENG",
342 "f.rf",
343 "longs.rij",
344 "f.rl",
345 "longs.rlongs",
346 "f.rtall",
347 "longs.rtall",
348 "ae.square",
349 "aeacute.square",
350 "uni01E3.square",
351 "k.swash",
352 "z.swash",
353 "zacute.swash",
354 "zcaron.swash",
355 "zdotaccent.swash",
356 "eth.loclENG.alt",
357 "f.alt.lf",
358 "thorn.loclENG.lf",
359 "longs.alt.llongs",
360 "uni027602DE",
361 "uni028F02DE",
362 "uni006102DE",
363 "uni025B02DE",
364 "uni025802DE",
365 "uni026802DE",
366 "uni027502DE",
367 "uni026402DE",
368 "uni028902DE",
369 "uni028A02DE",
370 "uni006102DE.ipa",
371 "a_s",
372 "c_t",
373 "f_eth",
374 "f_f",
375 "f_j",
376 "h_h.hlig",
377 "i_s",
378 "longs_t",
379 "p_p.hlig",
380 "thorn_thorn.hlig",
381 "u_s",
382 "uniFB01",
383 "uniFB02",
384 "uniFB03",
385 "uniFB04",
386 "uniFB06",
387 "wynn_wynn.hlig",
388 "longs_t.llongs",
389 "f_eth.loclENG",
390 "beta",
391 "theta",
392 "pi",
393 "chi",
394 "uni037C"]
395
396 smallcaps = ["avbar.sc",
397 "a.sc",
398 "aa.sc",
399 "aacute.sc",
400 "abreve.sc",
401 "acircumflex.sc",
402 "adieresis.sc",
403 "agrave.sc",
404 "amacron.sc",
405 "ao.sc",
406 "aogonek.sc",
407 "aring.sc",
408 "aringacute.sc",
409 "atilde.sc",
410 "au.sc",
411 "av.sc",
412 "ay.sc",
413 "ae.sc",
414 "aeacute.sc",
415 "uni01E3.sc",
416 "b.sc",
417 "c.sc",
418 "cacute.sc",
419 "ccaron.sc",
420 "ccedilla.sc",
421 "cdotaccent.sc",
422 "d.sc",
423 "eth.sc",
424 "dcaron.sc",
425 "dcroat.sc",
426 "dinsular.sc",
427 "e.sc",
428 "eacute.sc",
429 "ebreve.sc",
430 "ecaron.sc",
431 "ecircumflex.sc",
432 "edieresis.sc",
433 "edotaccent.sc",
434 "egrave.sc",
435 "emacron.sc",
436 "f.sc",
437 "finsular.sc",
438 "g.sc",
439 "gcommaaccent.sc",
440 "gdotaccent.sc",
441 "ginsular.sc",
442 "yogh.sc",
443 "h.sc",
444 "hbar.sc",
445 "hv.sc",
446 "i.sc",
447 "iacute.sc",
448 "ibreve.sc",
449 "icircumflex.sc",
450 "idieresis.sc",
451 "igrave.sc",
452 "ij.sc",
453 "imacron.sc",
454 "iogonek.sc",
455 "j.sc",
456 "k.sc",
457 "kcommaaccent.sc",
458 "uniA741.sc",
459 "l.sc",
460 "lacute.sc",
461 "uni019A.sc",
462 "lcaron.sc",
463 "lcommaaccent.sc",
464 "lhighstroke.sc",
465 "lmiddletilde.sc",
466 "lslash.sc",
467 "m.sc",
468 "n.sc",
469 "nacute.sc",
470 "ncaron.sc",
471 "ncommaaccent.sc",
472 "ntilde.sc",
473 "eng.sc",
474 "o.sc",
475 "oacute.sc",
476 "obreve.sc",
477 "ocircumflex.sc",
478 "odieresis.sc",
479 "ograve.sc",
480 "ohungarumlaut.sc",
481 "omacron.sc",
482 "oo.sc",
483 "oogonek.sc",
484 "oslash.sc",
485 "oslashacute.sc",
486 "otilde.sc",
487 "oe.sc",
488 "p.sc",
489 "thorn.sc",
490 "q.sc",
491 "qdiagonalstroke.sc",
492 "r.sc",
493 "racute.sc",
494 "rcaron.sc",
495 "rcommaaccent.sc",
496 "rinsular.sc",
497 "s.sc",
498 "sacute.sc",
499 "scaron.sc",
500 "scedilla.sc",
501 "germandbls.sc",
502 "sinsular.sc",
503 "t.sc",
504 "tbar.sc",
505 "tcaron.sc",
506 "tcedilla.sc",
507 "tinsular.sc",
508 "u.sc",
509 "uacute.sc",
510 "ubreve.sc",
511 "ucircumflex.sc",
512 "udieresis.sc",
513 "ugrave.sc",
514 "uhungarumlaut.sc",
515 "umacron.sc",
516 "uogonek.sc",
517 "uring.sc",
518 "utilde.sc",
519 "v.sc",
520 "w.sc",
521 "wacute.sc",
522 "wcircumflex.sc",
523 "wdieresis.sc",
524 "wgrave.sc",
525 "wynn.sc",
526 "x.sc",
527 "y.sc",
528 "yacute.sc",
529 "ycircumflex.sc",
530 "ydieresis.sc",
531 "uni1E8F.sc",
532 "ygrave.sc",
533 "ymacron.sc",
534 "z.sc",
535 "zacute.sc",
536 "zcaron.sc",
537 "zdotaccent.sc",
538 "uni01B6.sc",
539 "wy.sc",
540 "q.alt.sc",
541 "thorn.loclENG.sc"]
542
543 rune_names = ["fehu-runic",
544 "v-runic",
545 "uruz-runic",
546 "yr-runic",
547 "y-runic",
548 "w-runic",
549 "thurisazThursThorn-runic",
550 "eth-runic",
551 "ansuzA-runic",
552 "osO-runic",
553 "acA-runic",
554 "aesc-runic",
555 "ossOLongBranch-runic",
556 "ossOShortTwig-runic",
557 "o-runic",
558 "oe-runic",
559 "on-runic",
560 "raidoRadReidR-runic",
561 "kauna-runic",
562 "cen-runic",
563 "kaunK-runic",
564 "g-runic",
565 "eng-runic",
566 "geboGyfuG-runic",
567 "gar-runic",
568 "wunjoWynnW-runic",
569 "haglazH-runic",
570 "haeglH-runic",
571 "hagallHLongBranch-runic",
572 "hagallHShortTwig-runic",
573 "naudNNaudizNyd-runic",
574 "naudNShortTwig-runic",
575 "nDotted-runic",
576 "isazIsIssI-runic",
577 "e-runic",
578 "jeranJ-runic",
579 "ger-runic",
580 "aeLongBranchAr-runic",
581 "aShortTwigAr-runic",
582 "iwazEoh-runic",
583 "perthoPeorthP-runic",
584 "algizEolhx-runic",
585 "sowiloS-runic",
586 "sigelLongBranchSol-runic",
587 "sShortTwigSol-runic",
588 "c-runic",
589 "z-runic",
590 "tiwazTirTyr-runic",
591 "tShortTwigTyr-runic",
592 "d-runic",
593 "berkananBeorcBjarkanB-runic",
594 "bjarkanBshortTwig-runic",
595 "pDotted-runic",
596 "pOpen-runic",
597 "ehwazEhE-runic",
598 "mannazManM-runic",
599 "mLongBranchMadr-runic",
600 "mShortTwigMadr-runic",
601 "laukazLaguLogrL-runic",
602 "lDotted-runic",
603 "ingwaz-runic",
604 "ing-runic",
605 "dagazDaegD-runic",
606 "othalanEthelO-runic",
607 "ear-runic",
608 "ior-runic",
609 "cweorth-runic",
610 "calc-runic",
611 "cealc-runic",
612 "stan-runic",
613 "yrLongBranch-runic",
614 "yrShortTwig-runic",
615 "yrIcelandic-runic",
616 "q-runic",
617 "x-runic",
618 "punctSingle-runic",
619 "punctMultiple-runic",
620 "punctCross-runic",
621 "arlaug-runic",
622 "tvimadur-runic",
623 "belgthor-runic"]
624
625 rune_ids = []
626 smallcap_ids = []
627 lowercase_ids = []
628
629 def is_rune(kern_id):
630 return kern_id in rune_ids or 'runic' in kern_id
631
632 def is_small_cap(kern_id):
633 return kern_id in smallcap_ids or '.sc' in kern_id
634
635 def is_lowercase(kern_id):
636 return (kern_id in lowercase_ids
637 or kern_id.replace("@MMK_L_KO_","") in lowercase
638 or kern_id.replace("@MMK_R_KO_","") in lowercase)
639
640 def del_kerns_in_master(master_index):
641 master_id = Glyphs.font.masters[master_index].id
642 master_kerns = Glyphs.font.kerning[master_id]
643 del_pairs = []
644 left_kern_keys = master_kerns.keys()
645 for l in left_kern_keys:
646 right_kern_keys = master_kerns[l].keys()
647 for r in right_kern_keys:
648 if ((is_rune(l) and not is_rune(r))
649 or (is_rune(r) and not is_rune(l))
650 or (is_small_cap(l) and is_lowercase(r))
651 or (is_small_cap(r) and is_lowercase(l))):
652 del_pairs.append([l, r])
653 for p in del_pairs:
654 del master_kerns[p[0]][p[1]]
655 print(str(len(del_pairs)) + " pairs deleted in master " + str(master_index))
656
657 for n in rune_names:
658 try:
659 rune_ids.append(Glyphs.font.glyphs[n].id)
660 except:
661 print("skipping " + n)
662 for n in smallcaps:
663 try:
664 smallcap_ids.append(Glyphs.font.glyphs[n].id)
665 except:
666 print("skipping " + n)
667 for n in lowercase:
668 try:
669 lowercase_ids.append(Glyphs.font.glyphs[n].id)
670 except:
671 print("skipping " + n)
672
673 italic = False
674
675 del_kerns_in_master(0)
676 del_kerns_in_master(1)
677 del_kerns_in_master(2)
678 del_kerns_in_master(3)
679 del_kerns_in_master(4)
680 if italic:
681 del_kerns_in_master(6)