File: normalize.py

package info (click to toggle)
fonts-cantarell 0.303.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,760 kB
  • sloc: python: 859; makefile: 9; sh: 1
file content (49 lines) | stat: -rw-r--r-- 1,499 bytes parent folder | download | duplicates (2)
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
from pathlib import Path

import ufoLib2


source_directory = Path(__file__).parent.parent / "src"
for ufo_path in source_directory.glob("*.ufo"):
    ufo = ufoLib2.Font.open(ufo_path)

    layer_names = [l.name for l in ufo.layers]
    for name in layer_names:
        if name != "public.default":
            del ufo.layers[name]

    ufo.layers.defaultLayer.lib = {
        k: v for k, v in ufo.layers.defaultLayer.lib.items() if k.startswith("public.")
    }

    for glyph in ufo:
        glyph.lib = {
            k: v
            for k, v in glyph.lib.items()
            if (
                k.startswith("public.")
                or k.startswith("com.schriftgestaltung.Glyphs.")
                or k == "com.schriftgestaltung.componentsAlignment"
            )
            and k != "public.markColor"
        }

    ufo.lib = {
        k: v
        for k, v in ufo.lib.items()
        if k.startswith("public.")
        or k.startswith("com.github.googlei18n.ufo2ft.")
        or (
            k
            in {
                "com.schriftgestaltung.appVersion",
                "com.schriftgestaltung.fontMasterID",
                "com.schriftgestaltung.customParameter.GSFont.disablesLastChange",
                "com.schriftgestaltung.customParameter.GSFontMaster.paramArea",
                "com.schriftgestaltung.customParameter.GSFontMaster.paramDepth",
                "com.schriftgestaltung.customParameter.GSFontMaster.paramOver",
            }
        )
    }

    ufo.save()